fix(region): sync auzre subscription health status

This commit is contained in:
Qu Xuan
2021-07-16 10:53:16 +08:00
parent a351d9bcaf
commit 75f7188bc6
5 changed files with 13 additions and 6 deletions

View File

@@ -16,7 +16,6 @@ package cloudprovider
type SSubAccount struct {
Name string
State string
Account string
HealthStatus string // 云端服务健康状态。例如欠费、项目冻结都属于不健康状态。
}

View File

@@ -793,9 +793,8 @@ func (self *SAzureClient) GetSubAccounts() (subAccounts []cloudprovider.SSubAcco
subAccounts = make([]cloudprovider.SSubAccount, len(self.subscriptions))
for i, subscription := range self.subscriptions {
subAccounts[i].Account = fmt.Sprintf("%s/%s", self.tenantId, subscription.SubscriptionId)
subAccounts[i].State = subscription.State
subAccounts[i].Name = subscription.DisplayName
subAccounts[i].HealthStatus = api.CLOUD_PROVIDER_HEALTH_NORMAL
subAccounts[i].HealthStatus = subscription.GetHealthStatus()
}
return subAccounts, nil
}

View File

@@ -14,7 +14,11 @@
package azure
import "net/url"
import (
"net/url"
api "yunion.io/x/onecloud/pkg/apis/compute"
)
type SSubscription struct {
SubscriptionId string `json:"subscriptionId"`
@@ -22,6 +26,13 @@ type SSubscription struct {
DisplayName string `json:"displayName"`
}
func (self *SSubscription) GetHealthStatus() string {
if self.State == "Enabled" {
return api.CLOUD_PROVIDER_HEALTH_NORMAL
}
return api.CLOUD_PROVIDER_HEALTH_SUSPENDED
}
func (self *SAzureClient) ListSubscriptions() ([]SSubscription, error) {
result := []SSubscription{}
err := self.list("subscriptions", url.Values{}, &result)

View File

@@ -277,7 +277,6 @@ func (self *SCtyunClient) GetSubAccounts() ([]cloudprovider.SSubAccount, error)
s := cloudprovider.SSubAccount{
Name: fmt.Sprintf("%s-%s", self.cpcfg.Name, iregion.GetId()),
State: api.CLOUD_PROVIDER_CONNECTED,
Account: fmt.Sprintf("%s/%s", self.accessKey, iregion.GetId()),
HealthStatus: api.CLOUD_PROVIDER_HEALTH_NORMAL,
}

View File

@@ -333,7 +333,6 @@ func (self *SHuaweiClient) GetSubAccounts() ([]cloudprovider.SSubAccount, error)
}
s := cloudprovider.SSubAccount{
Name: fmt.Sprintf("%s-%s", self.cpcfg.Name, project.Name),
State: api.CLOUD_PROVIDER_CONNECTED,
Account: fmt.Sprintf("%s/%s", self.accessKey, project.ID),
HealthStatus: project.GetHealthStatus(),
}