From 53746609ab1febf58c9f9b4d8b7987fccc49d561 Mon Sep 17 00:00:00 2001 From: Qu Xuan Date: Tue, 6 Jul 2021 19:51:06 +0800 Subject: [PATCH] fix(region): update jdcloud rds port --- pkg/apis/compute/dbinstance_const.go | 1 + pkg/multicloud/jdcloud/rds.go | 29 ++++++++++++++++++++++++++++ pkg/multicloud/jdcloud/shell/rds.go | 8 ++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/pkg/apis/compute/dbinstance_const.go b/pkg/apis/compute/dbinstance_const.go index 7a4d04f5ab..0ed7b0f237 100644 --- a/pkg/apis/compute/dbinstance_const.go +++ b/pkg/apis/compute/dbinstance_const.go @@ -102,6 +102,7 @@ const ( DBINSTANCE_TYPE_MARIADB = "MariaDB" DBINSTANCE_TYPE_ORACLE = "Oracle" DBINSTANCE_TYPE_PPAS = "PPAS" + DBINSTANCE_TYPE_PERCONA = "Percona" //阿里云实例类型 ALIYUN_DBINSTANCE_CATEGORY_BASIC = "basic" //基础版 diff --git a/pkg/multicloud/jdcloud/rds.go b/pkg/multicloud/jdcloud/rds.go index 8687fd1b52..a8c218cc43 100644 --- a/pkg/multicloud/jdcloud/rds.go +++ b/pkg/multicloud/jdcloud/rds.go @@ -76,6 +76,14 @@ func (self *SDBInstance) GetIVpcId() string { return self.VpcId } +func (self *SDBInstance) Refresh() error { + rds, err := self.region.GetDBInstance(self.InstanceId) + if err != nil { + return err + } + return jsonutils.Update(self, rds) +} + func (self *SDBInstance) GetMaintainTime() string { return "" } @@ -85,6 +93,9 @@ func (self *SDBInstance) GetMasterInstanceId() string { } func (self *SDBInstance) GetPort() int { + if len(self.InstancePort) == 0 { + self.Refresh() + } port, _ := strconv.Atoi(self.InstancePort) return int(port) } @@ -163,6 +174,10 @@ func (self *SDBInstance) GetInternalConnectionStr() string { return self.InternalDomainName } +func (self *SDBInstance) Delete() error { + return self.region.DeleteDBInstance(self.InstanceId) +} + func (self *SRegion) GetIDBInstances() ([]cloudprovider.ICloudDBInstance, error) { rds := []SDBInstance{} n := 1 @@ -210,6 +225,20 @@ func (self *SRegion) GetDBInstance(id string) (*SDBInstance, error) { return &ret, nil } +func (self *SRegion) DeleteDBInstance(id string) error { + req := apis.NewDeleteInstanceRequest(self.ID, id) + client := client.NewRdsClient(self.Credential) + client.Logger = Logger{} + resp, err := client.DeleteInstance(req) + if err != nil { + return err + } + if resp.Error.Code == 404 { + return nil + } + return nil +} + func (self *SRegion) GetDBInstances(pageNumber int, pageSize int) ([]SDBInstance, int, error) { req := apis.NewDescribeInstancesRequestWithAllParams(self.ID, &pageNumber, &pageSize, []commodels.Filter{}, []commodels.TagFilter{}) client := client.NewRdsClient(self.Credential) diff --git a/pkg/multicloud/jdcloud/shell/rds.go b/pkg/multicloud/jdcloud/shell/rds.go index 4324e6f1eb..e838786015 100644 --- a/pkg/multicloud/jdcloud/shell/rds.go +++ b/pkg/multicloud/jdcloud/shell/rds.go @@ -34,11 +34,11 @@ func init() { return nil }) - type DBInstanceShowOptions struct { + type DBInstanceIdOptions struct { ID string } - shellutils.R(&DBInstanceShowOptions{}, "dbinstance-show", "Show rds", func(cli *jdcloud.SRegion, args *DBInstanceShowOptions) error { + shellutils.R(&DBInstanceIdOptions{}, "dbinstance-show", "Show rds", func(cli *jdcloud.SRegion, args *DBInstanceIdOptions) error { rds, err := cli.GetDBInstance(args.ID) if err != nil { return err @@ -47,6 +47,10 @@ func init() { return nil }) + shellutils.R(&DBInstanceIdOptions{}, "dbinstance-delete", "Delete rds", func(cli *jdcloud.SRegion, args *DBInstanceIdOptions) error { + return cli.DeleteDBInstance(args.ID) + }) + type DBInstanceAccountListOptions struct { PageNumber int `default:"1"` PageSize int `default:"100"`