mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #558 in YUNIONIO/onecloud from ~QUXUAN/onecloud:hotfix/qx-cloudprovider-compatible to release/2.3.0
* commit 'e1284e60cd24ac73b7961d0549fefd261f44fa5f': 兼容从2.3.0降级到2.2.0
This commit is contained in:
@@ -230,6 +230,9 @@ func (self *SCloudaccount) PerformUpdateCredential(ctx context.Context, userCred
|
||||
changed := false
|
||||
secret, _ := data.GetString("secret")
|
||||
account, _ := data.GetString("account")
|
||||
if len(account) > 0 && self.Provider == CLOUD_PROVIDER_AZURE {
|
||||
return nil, httperrors.NewInputParameterError("not allow update azure tenant info")
|
||||
}
|
||||
accessUrl, _ := data.GetString("access_url")
|
||||
if len(secret) > 0 || len(account) > 0 || len(accessUrl) > 0 {
|
||||
// check duplication
|
||||
@@ -276,6 +279,11 @@ func (self *SCloudaccount) PerformUpdateCredential(ctx context.Context, userCred
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, provider := range self.GetCloudproviders() {
|
||||
provider.savePassword(secret)
|
||||
}
|
||||
|
||||
changed = true
|
||||
}
|
||||
|
||||
@@ -385,6 +393,7 @@ func (self *SCloudaccount) ImportSubAccount(ctx context.Context, userCred mcclie
|
||||
newCloudprovider.Account = subAccount.Account
|
||||
newCloudprovider.CloudaccountId = self.Id
|
||||
newCloudprovider.Provider = self.Provider
|
||||
newCloudprovider.AccessUrl = self.AccessUrl
|
||||
newCloudprovider.Enabled = true
|
||||
newCloudprovider.Status = CLOUD_PROVIDER_CONNECTED
|
||||
newCloudprovider.Name = subAccount.Name
|
||||
@@ -400,6 +409,13 @@ func (self *SCloudaccount) ImportSubAccount(ctx context.Context, userCred mcclie
|
||||
return nil, isNew, err
|
||||
}
|
||||
|
||||
passwd, err := self.getPassword()
|
||||
if err != nil {
|
||||
return nil, isNew, err
|
||||
}
|
||||
|
||||
newCloudprovider.savePassword(passwd)
|
||||
|
||||
if autoCreateProject {
|
||||
err = newCloudprovider.syncProject(ctx)
|
||||
if err != nil {
|
||||
@@ -492,12 +508,12 @@ func (self *SCloudaccount) GetExtraDetails(ctx context.Context, userCred mcclien
|
||||
}
|
||||
|
||||
func migrateCloudprovider(cloudprovider *SCloudprovider) error {
|
||||
mainAccount, providerAccount, providerName := cloudprovider.Account, cloudprovider.Account, cloudprovider.Name
|
||||
mainAccount, providerName := cloudprovider.Account, cloudprovider.Name
|
||||
|
||||
if cloudprovider.Provider == CLOUD_PROVIDER_AZURE {
|
||||
accountInfo := strings.Split(cloudprovider.Account, "/")
|
||||
if len(accountInfo) == 2 {
|
||||
mainAccount, providerAccount = accountInfo[0], accountInfo[1]
|
||||
mainAccount = accountInfo[0]
|
||||
if len(cloudprovider.Description) > 0 {
|
||||
providerName = cloudprovider.Description
|
||||
}
|
||||
@@ -549,9 +565,6 @@ func migrateCloudprovider(cloudprovider *SCloudprovider) error {
|
||||
|
||||
_, err = CloudproviderManager.TableSpec().Update(cloudprovider, func() error {
|
||||
cloudprovider.CloudaccountId = account.Id
|
||||
cloudprovider.Account = providerAccount
|
||||
cloudprovider.Secret = ""
|
||||
cloudprovider.Name = providerName
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -378,55 +378,30 @@ func (self *SCloudprovider) GetDriver() (cloudprovider.ICloudProvider, error) {
|
||||
return nil, fmt.Errorf("Cloud provider is not enabled")
|
||||
}
|
||||
|
||||
account, err := self.getAccount()
|
||||
passwd, err := self.getPassword()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cloudprovider.GetProvider(self.Id, self.Name, account.AccessUrl, account.Account, account.Secret, self.Provider)
|
||||
return cloudprovider.GetProvider(self.Id, self.Name, self.AccessUrl, self.Account, passwd, self.Provider)
|
||||
}
|
||||
|
||||
type SAccount struct {
|
||||
AccessUrl string
|
||||
Account string
|
||||
Secret string
|
||||
func (self *SCloudprovider) savePassword(secret string) error {
|
||||
sec, err := utils.EncryptAESBase64(self.Id, secret)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = self.GetModelManager().TableSpec().Update(self, func() error {
|
||||
self.Secret = sec
|
||||
return nil
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) GetCloudaccount() *SCloudaccount {
|
||||
return CloudaccountManager.FetchCloudaccountById(self.CloudaccountId)
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) getAccount() (SAccount, error) {
|
||||
account := SAccount{}
|
||||
|
||||
cloudaccount := self.GetCloudaccount()
|
||||
if cloudaccount == nil {
|
||||
// legacy mode
|
||||
passwd, err := self.getPassword()
|
||||
if err != nil {
|
||||
return account, err
|
||||
}
|
||||
account.Account = self.Account
|
||||
account.AccessUrl = self.AccessUrl
|
||||
account.Secret = passwd
|
||||
return account, nil // fmt.Errorf("fail to find cloudaccount???")
|
||||
}
|
||||
|
||||
passwd, err := cloudaccount.getPassword()
|
||||
if err != nil {
|
||||
return account, err
|
||||
}
|
||||
|
||||
account.Account = cloudaccount.Account
|
||||
account.AccessUrl = cloudaccount.AccessUrl
|
||||
account.Secret = passwd
|
||||
|
||||
if len(self.Account) > 0 && self.Account != account.Account {
|
||||
account.Account = fmt.Sprintf("%s/%s", account.Account, self.Account)
|
||||
}
|
||||
|
||||
return account, nil
|
||||
}
|
||||
|
||||
func (self *SCloudprovider) SaveSysInfo(info jsonutils.JSONObject) {
|
||||
self.GetModelManager().TableSpec().Update(self, func() error {
|
||||
self.Sysinfo = info
|
||||
|
||||
@@ -626,10 +626,11 @@ func (self *SAzureClient) GetSubAccounts() (subAccounts []cloudprovider.SSubAcco
|
||||
}
|
||||
subAccounts = make([]cloudprovider.SSubAccount, len(subscriptions))
|
||||
for i, subscription := range subscriptions {
|
||||
subAccounts[i].Account, err = subscription.GetString("subscriptionId")
|
||||
subscriptionId, err := subscription.GetString("subscriptionId")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
subAccounts[i].Account = fmt.Sprintf("%s/%s", self.tenantId, subscriptionId)
|
||||
subAccounts[i].State, err = subscription.GetString("state")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user