yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/google/shell/dbinstance.go (about) 1 // Copyright 2019 Yunion 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package shell 16 17 import ( 18 "yunion.io/x/cloudmux/pkg/multicloud/google" 19 "yunion.io/x/onecloud/pkg/util/shellutils" 20 ) 21 22 func init() { 23 type DBInstanceListOptions struct { 24 MaxResults int 25 PageToken string 26 } 27 shellutils.R(&DBInstanceListOptions{}, "dbinstance-list", "List dbinstances", func(cli *google.SRegion, args *DBInstanceListOptions) error { 28 instances, err := cli.GetDBInstances(args.MaxResults, args.PageToken) 29 if err != nil { 30 return err 31 } 32 printList(instances, 0, 0, 0, nil) 33 return nil 34 }) 35 36 type DBInstanceIdOptions struct { 37 INSTANCE string 38 } 39 40 shellutils.R(&DBInstanceIdOptions{}, "dbinstance-show", "Show dbinstance", func(cli *google.SRegion, args *DBInstanceIdOptions) error { 41 instance, err := cli.GetDBInstance(args.INSTANCE) 42 if err != nil { 43 return err 44 } 45 printObject(instance) 46 return nil 47 }) 48 49 shellutils.R(&DBInstanceIdOptions{}, "dbinstance-close-public-connection", "Close dbinstance public connection", func(cli *google.SRegion, args *DBInstanceIdOptions) error { 50 return cli.DBInstancePublicConnectionOperation(args.INSTANCE, false) 51 }) 52 53 shellutils.R(&DBInstanceIdOptions{}, "dbinstance-open-public-connection", "Open dbinstance public connection", func(cli *google.SRegion, args *DBInstanceIdOptions) error { 54 return cli.DBInstancePublicConnectionOperation(args.INSTANCE, true) 55 }) 56 57 shellutils.R(&DBInstanceIdOptions{}, "dbinstance-delete", "Delete dbinstance", func(cli *google.SRegion, args *DBInstanceIdOptions) error { 58 return cli.DeleteDBInstance(args.INSTANCE) 59 }) 60 61 type DBInstanceCreateOptions struct { 62 NAME string 63 ENGINE string 64 DATABASEVERSION string 65 Category string `default:"Zonal" choices:"Zonal|Regional"` 66 INSTANCE_TYPE string 67 STORAGE_TYPE string 68 DISK_SIZE_GB int 69 VpcId string 70 ZoneId string 71 Password string 72 } 73 74 shellutils.R(&DBInstanceCreateOptions{}, "dbinstance-create", "Create dbinstance", func(cli *google.SRegion, args *DBInstanceCreateOptions) error { 75 instance, err := cli.CreateRds(args.NAME, args.ENGINE, args.DATABASEVERSION, args.Category, args.INSTANCE_TYPE, args.STORAGE_TYPE, args.DISK_SIZE_GB, args.VpcId, args.ZoneId, args.Password) 76 if err != nil { 77 return err 78 } 79 printObject(instance) 80 return nil 81 }) 82 83 type DBInstanceChangeConfigOptions struct { 84 INSTANCE string 85 DiskSizeGb int 86 InstnaceType string 87 } 88 89 shellutils.R(&DBInstanceChangeConfigOptions{}, "dbinstance-change-config", "Change dbinstance config", func(cli *google.SRegion, args *DBInstanceChangeConfigOptions) error { 90 return cli.ChangeDBInstanceConfig(args.INSTANCE, args.DiskSizeGb, args.InstnaceType) 91 }) 92 93 type DBInstanceRecoveryOptions struct { 94 NAME string 95 TARGET string 96 BACKUP string 97 } 98 99 shellutils.R(&DBInstanceRecoveryOptions{}, "dbinstance-restore", "restore dbinstance from backup", func(cli *google.SRegion, args *DBInstanceRecoveryOptions) error { 100 return cli.RecoverFromBackup(args.NAME, args.TARGET, args.BACKUP) 101 }) 102 103 }