mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #9771 from ioito/hotfix/qx-azure-register-service
fix(region): avoid panic when register service not work
This commit is contained in:
@@ -200,16 +200,20 @@ func (self *SAzureClient) jsonRequest(method, path string, body jsonutils.JSONOb
|
||||
if ae, ok := err.(*AzureResponseError); ok {
|
||||
switch ae.AzureError.Code {
|
||||
case "SubscriptionNotRegistered":
|
||||
err = self.ServiceRegister("Microsoft.Network")
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "self.registerService(Microsoft.Network)")
|
||||
service := self.getService(path)
|
||||
if len(service) == 0 {
|
||||
return nil, err
|
||||
}
|
||||
re := self.ServiceRegister("Microsoft.Network")
|
||||
if re != nil {
|
||||
return nil, errors.Wrapf(re, "self.registerService(Microsoft.Network)")
|
||||
}
|
||||
continue
|
||||
case "MissingSubscriptionRegistration":
|
||||
for _, serviceType := range ae.AzureError.Details {
|
||||
err = self.ServiceRegister(serviceType.Target)
|
||||
re := self.ServiceRegister(serviceType.Target)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "self.registerService(%s)", serviceType.Target)
|
||||
return nil, errors.Wrapf(re, "self.registerService(%s)", serviceType.Target)
|
||||
}
|
||||
}
|
||||
continue
|
||||
@@ -367,6 +371,25 @@ func (self *SAzureClient) list(resource string, params url.Values, retVal interf
|
||||
return jsonutils.Update(retVal, result)
|
||||
}
|
||||
|
||||
func (self *SAzureClient) getService(path string) string {
|
||||
for _, service := range []string{
|
||||
"microsoft.compute",
|
||||
"microsoft.classiccompute",
|
||||
"microsoft.network",
|
||||
"microsoft.classicnetwork",
|
||||
"microsoft.storage",
|
||||
"microsoft.classicstorage",
|
||||
"microsoft.billing",
|
||||
"microsoft.insights",
|
||||
"microsoft.authorization",
|
||||
} {
|
||||
if strings.Contains(strings.ToLower(path), service) {
|
||||
return service
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SAzureClient) _apiVersion(resource string, params url.Values) string {
|
||||
version := params.Get("api-version")
|
||||
if len(version) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user