mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #10109 from ioito/hotfix/qx-huawei-subaccount
fix(region): avoid sync huawei unusable account
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/util/timeutils"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
@@ -96,8 +97,9 @@ type SHuaweiClient struct {
|
||||
|
||||
isMainProject bool // whether the project is the main project in the region
|
||||
|
||||
ownerId string
|
||||
ownerName string
|
||||
ownerId string
|
||||
ownerName string
|
||||
ownerCreateTime time.Time
|
||||
|
||||
iregions []cloudprovider.ICloudRegion
|
||||
iBuckets []cloudprovider.ICloudBucket
|
||||
@@ -324,6 +326,11 @@ func (self *SHuaweiClient) GetSubAccounts() ([]cloudprovider.SSubAccount, error)
|
||||
if strings.ToLower(project.Name) == "mos" {
|
||||
continue
|
||||
}
|
||||
// https://www.huaweicloud.com/notice/2018/20190618171312411.html
|
||||
expiredAt, _ := timeutils.ParseTimeStr("2020-09-16 00:00:00")
|
||||
if !self.ownerCreateTime.IsZero() && self.ownerCreateTime.After(expiredAt) && strings.ToLower(project.Name) == "cn-north-1" {
|
||||
continue
|
||||
}
|
||||
s := cloudprovider.SSubAccount{
|
||||
Name: fmt.Sprintf("%s-%s", self.cpcfg.Name, project.Name),
|
||||
State: api.CLOUD_PROVIDER_CONNECTED,
|
||||
@@ -540,8 +547,9 @@ func (self *SHuaweiClient) GetOwnerId() (string, error) {
|
||||
}
|
||||
|
||||
type user struct {
|
||||
DomainId string `json:"domain_id"`
|
||||
Name string `json:"name"`
|
||||
DomainId string `json:"domain_id"`
|
||||
Name string `json:"name"`
|
||||
CreateTime string
|
||||
}
|
||||
|
||||
ret := &user{}
|
||||
@@ -550,6 +558,8 @@ func (self *SHuaweiClient) GetOwnerId() (string, error) {
|
||||
return "", errors.Wrap(err, "SHuaweiClient.GetOwnerId.DoGet")
|
||||
}
|
||||
self.ownerName = ret.Name
|
||||
// 2021-02-02 02:43:28.0
|
||||
self.ownerCreateTime, _ = timeutils.ParseTimeStr(strings.TrimSuffix(ret.CreateTime, ".0"))
|
||||
return ret.DomainId, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -53,4 +53,14 @@ func init() {
|
||||
fmt.Println(capabilities)
|
||||
return nil
|
||||
})
|
||||
|
||||
shellutils.R(&RegionListOptions{}, "subaccount-list", "List account", func(cli *huawei.SRegion, args *RegionListOptions) error {
|
||||
accounts, err := cli.GetClient().GetSubAccounts()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printList(accounts, 0, 0, 0, nil)
|
||||
return nil
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user