yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/qcloud/shell/rds_mysql.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 "fmt" 19 20 "yunion.io/x/pkg/errors" 21 22 "yunion.io/x/cloudmux/pkg/multicloud/qcloud" 23 "yunion.io/x/onecloud/pkg/util/shellutils" 24 ) 25 26 func init() { 27 type MysqlSkuListOptions struct { 28 } 29 shellutils.R(&MysqlSkuListOptions{}, "mysql-sku-list", "List mysql instance types", func(cli *qcloud.SRegion, args *MysqlSkuListOptions) error { 30 skus, err := cli.ListMysqlSkus() 31 if err != nil { 32 return errors.Wrapf(err, "ListMysqlSkus") 33 } 34 printList(skus, 0, 0, 0, nil) 35 return nil 36 }) 37 38 type MysqlInstanceListOptions struct { 39 Ids []string 40 Offset int 41 Limit int 42 } 43 44 shellutils.R(&MysqlInstanceListOptions{}, "mysql-instance-list", "List mysql instance", func(cli *qcloud.SRegion, args *MysqlInstanceListOptions) error { 45 result, _, err := cli.ListMySQLInstances(args.Ids, args.Offset, args.Limit) 46 if err != nil { 47 return errors.Wrapf(err, "ListMySQLInstances") 48 } 49 printList(result, 0, 0, 0, nil) 50 return nil 51 }) 52 53 type MySQLInstanceIdOptions struct { 54 ID string 55 } 56 57 shellutils.R(&MySQLInstanceIdOptions{}, "mysql-instance-reboot", "Reboot mysql instance", func(cli *qcloud.SRegion, args *MySQLInstanceIdOptions) error { 58 return cli.RebootMySQLInstance(args.ID) 59 }) 60 61 shellutils.R(&MySQLInstanceIdOptions{}, "mysql-instance-isolate", "Isolate mysql instance", func(cli *qcloud.SRegion, args *MySQLInstanceIdOptions) error { 62 return cli.IsolateMySQLDBInstance(args.ID) 63 }) 64 65 shellutils.R(&MySQLInstanceIdOptions{}, "mysql-instance-offline-isolate", "Offline Isolate mysql instance", func(cli *qcloud.SRegion, args *MySQLInstanceIdOptions) error { 66 return cli.OfflineIsolatedMySQLInstances([]string{args.ID}) 67 }) 68 69 shellutils.R(&MySQLInstanceIdOptions{}, "mysql-instance-release-isolate", "Release Isolate mysql instance", func(cli *qcloud.SRegion, args *MySQLInstanceIdOptions) error { 70 return cli.ReleaseIsolatedMySQLDBInstances([]string{args.ID}) 71 }) 72 73 shellutils.R(&MySQLInstanceIdOptions{}, "mysql-instance-secgroup-list", "List mysql instance secgroups", func(cli *qcloud.SRegion, args *MySQLInstanceIdOptions) error { 74 secgroups, err := cli.DescribeMySQLDBSecurityGroups(args.ID) 75 if err != nil { 76 return err 77 } 78 printList(secgroups, 0, 0, 0, nil) 79 return nil 80 }) 81 82 type MySQLInstanceDBListOptions struct { 83 MySQLInstanceIdOptions 84 Offset int 85 Limit int 86 } 87 88 shellutils.R(&MySQLInstanceDBListOptions{}, "mysql-instance-database-list", "List mysql instance database", func(cli *qcloud.SRegion, args *MySQLInstanceDBListOptions) error { 89 databases, totalCount, err := cli.DescribeMySQLDatabases(args.ID, args.Offset, args.Limit) 90 if err != nil { 91 return err 92 } 93 printList(databases, 0, 0, 0, nil) 94 fmt.Println("TotalCount: ", totalCount) 95 return nil 96 }) 97 98 shellutils.R(&MySQLInstanceDBListOptions{}, "mysql-instance-account-list", "List mysql instance accounts", func(cli *qcloud.SRegion, args *MySQLInstanceDBListOptions) error { 99 accounts, totalCount, err := cli.DescribeMySQLAccounts(args.ID, args.Offset, args.Limit) 100 if err != nil { 101 return err 102 } 103 printList(accounts, 0, 0, 0, nil) 104 fmt.Println("TotalCount: ", totalCount) 105 return nil 106 }) 107 108 shellutils.R(&MySQLInstanceDBListOptions{}, "mysql-instance-backup-list", "List mysql instance backups", func(cli *qcloud.SRegion, args *MySQLInstanceDBListOptions) error { 109 backups, totalCount, err := cli.DescribeMySQLBackups(args.ID, args.Offset, args.Limit) 110 if err != nil { 111 return err 112 } 113 printList(backups, 0, 0, 0, nil) 114 fmt.Println("TotalCount: ", totalCount) 115 return nil 116 }) 117 118 shellutils.R(&MySQLInstanceIdOptions{}, "mysql-instance-show", "Show mysql instance", func(cli *qcloud.SRegion, args *MySQLInstanceIdOptions) error { 119 result, err := cli.DescribeMySQLDBInstanceInfo(args.ID) 120 if err != nil { 121 return err 122 } 123 printObject(result) 124 return nil 125 }) 126 127 type MySQLRenewOptions struct { 128 MySQLInstanceIdOptions 129 MONTH int `choices:"1|2|3|4|5|6|7|8|9|10|11|12|24|36"` 130 } 131 132 type MySQLAutoRenewOptions struct { 133 MySQLInstanceIdOptions 134 AutoRenew bool 135 } 136 137 shellutils.R(&MySQLAutoRenewOptions{}, "mysql-instance-set-auto-renew", "Set Auto Renew for mysql instance", func(cli *qcloud.SRegion, args *MySQLAutoRenewOptions) error { 138 return cli.ModifyMySQLAutoRenewFlag([]string{args.ID}, args.AutoRenew) 139 }) 140 141 shellutils.R(&MySQLRenewOptions{}, "mysql-instance-renew", "Renew mysql instance", func(cli *qcloud.SRegion, args *MySQLRenewOptions) error { 142 return cli.RenewMySQLDBInstance(args.ID, args.MONTH) 143 }) 144 145 shellutils.R(&MySQLInstanceIdOptions{}, "mysql-instance-backup-create", "Create mysql instance backup", func(cli *qcloud.SRegion, args *MySQLInstanceIdOptions) error { 146 backup, err := cli.CreateMySQLBackup(args.ID, nil) 147 if err != nil { 148 return err 149 } 150 printObject(backup) 151 return nil 152 }) 153 154 type RestAccountPasswordOptions struct { 155 INSTANCE_ID string 156 PASSWORD string 157 USER string 158 Host string `default:"%"` 159 } 160 161 shellutils.R(&RestAccountPasswordOptions{}, "mysql-account-reset-password", "Reset mysql account password", func(cli *qcloud.SRegion, args *RestAccountPasswordOptions) error { 162 return cli.ModifyMySQLAccountPassword(args.INSTANCE_ID, args.PASSWORD, map[string]string{args.USER: args.Host}) 163 }) 164 165 type MySQLAccountPrivilegeShowOptions struct { 166 INSTANCE_ID string 167 USER string 168 Host string `default:"%"` 169 } 170 171 shellutils.R(&MySQLAccountPrivilegeShowOptions{}, "mysql-account-privilege-show", "Show account privileges", func(cli *qcloud.SRegion, args *MySQLAccountPrivilegeShowOptions) error { 172 result, err := cli.DescribeAccountPrivileges(args.INSTANCE_ID, args.USER, args.Host) 173 if err != nil { 174 return err 175 } 176 printObject(result) 177 return nil 178 }) 179 180 }