diff --git a/pkg/apis/compute/cloudaccount.go b/pkg/apis/compute/cloudaccount.go index 0c6677041a..c68642731b 100644 --- a/pkg/apis/compute/cloudaccount.go +++ b/pkg/apis/compute/cloudaccount.go @@ -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 { diff --git a/pkg/cloudprovider/subscription.go b/pkg/cloudprovider/subscription.go index a849ccb165..f2b0df700c 100644 --- a/pkg/cloudprovider/subscription.go +++ b/pkg/cloudprovider/subscription.go @@ -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"` } diff --git a/pkg/compute/models/cloudaccounts.go b/pkg/compute/models/cloudaccounts.go index 60ed92a683..4a8e82f817 100644 --- a/pkg/compute/models/cloudaccounts.go +++ b/pkg/compute/models/cloudaccounts.go @@ -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, "") } diff --git a/pkg/multicloud/azure/enrollment_account.go b/pkg/multicloud/azure/enrollment_account.go index 786ea24ddb..bd07abe7ec 100644 --- a/pkg/multicloud/azure/enrollment_account.go +++ b/pkg/multicloud/azure/enrollment_account.go @@ -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 {