fix: 优化azure订阅创建

This commit is contained in:
Qu Xuan
2020-07-10 19:47:59 +08:00
parent 20f517bef4
commit 3d9e8b8727
4 changed files with 38 additions and 22 deletions
+4 -4
View File
@@ -387,14 +387,14 @@ type CANetConf struct {
type SubscriptonCreateInput struct {
// EA 账号id, 可通过 cloud-account-enrollment-accounts接口获取里面的name字段
EnrollmentAccountId string
// EA 账号id, 可通过 cloud-account-enrollment-accounts接口获取里面的id字段
EnrollmentAccountId string `json:"enrollment_account_id"`
// 订阅名称
Name string
Name string `json:"name"`
// 可选值: MS-AZR-0017P(生产用途), MS-AZR-0148P(开发测试)
OfferType string
OfferType string `json:"offer_type"`
}
type EnrollmentAccountQuery struct {
+4 -15
View File
@@ -20,24 +20,13 @@ type SubscriptionCreateInput struct {
OfferType string
}
type SEnrollmentAccountProperties struct {
// Enrollment Account 主体名称
PrincipalName string
// Enrollment Account 支持创建订阅类别
OfferTypes []string
}
type SEnrollmentAccount struct {
// Enrollment Account 标识Id
Id string
// Enrollment Account Id
Id string `json:"id"`
// Enrollment Account name
Name string
Name string `json:"name"`
// Enrollment Account 类型
Type string
// Enrollment Account 属性
Properties SEnrollmentAccountProperties
Type string `json:"type"`
}
+7 -1
View File
@@ -3009,5 +3009,11 @@ func (self *SCloudaccount) PerformCreateSubscription(ctx context.Context, userCr
OfferType: input.OfferType,
}
return nil, provider.CreateSubscription(conf)
err = provider.CreateSubscription(conf)
if err != nil {
return nil, errors.Wrap(err, "CreateSubscription")
}
syncRange := SSyncRange{}
return nil, self.StartSyncCloudProviderInfoTask(ctx, userCred, &syncRange, "")
}
+23 -2
View File
@@ -25,15 +25,36 @@ import (
"yunion.io/x/onecloud/pkg/cloudprovider"
)
type SEnrollmentAccountProperties struct {
PrincipalName string
OfferTypes []string
}
type SEnrollmentAccount struct {
Id string
Name string
Type string
Properties SEnrollmentAccountProperties
}
func (cli *SAzureClient) GetEnrollmentAccounts() ([]cloudprovider.SEnrollmentAccount, error) {
accounts := struct {
Value []cloudprovider.SEnrollmentAccount
Value []SEnrollmentAccount
}{}
err := cli.Get("providers/Microsoft.Billing/enrollmentAccounts", nil, &accounts)
if err != nil {
return nil, err
}
return accounts.Value, nil
eas := []cloudprovider.SEnrollmentAccount{}
for i := range accounts.Value {
ea := cloudprovider.SEnrollmentAccount{
Id: accounts.Value[i].Name,
Name: accounts.Value[i].Properties.PrincipalName,
Type: accounts.Value[i].Type,
}
eas = append(eas, ea)
}
return eas, nil
}
func (cli *SAzureClient) CreateSubscription(name string, eaId string, offerType string) error {