mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix: sync new project for azure resource group
This commit is contained in:
@@ -465,15 +465,20 @@ func (self *SAzureClient) _apiVersion(resource string, params url.Values) string
|
||||
return AZURE_API_VERSION
|
||||
}
|
||||
|
||||
func (self *SAzureClient) _list(resource string, params url.Values) (jsonutils.JSONObject, error) {
|
||||
subId := self.subscriptionId
|
||||
if len(subId) == 0 {
|
||||
for _, sub := range self.subscriptions {
|
||||
if sub.State == "Enabled" {
|
||||
subId = sub.SubscriptionId
|
||||
}
|
||||
func (self *SAzureClient) _subscriptionId() string {
|
||||
if len(self.subscriptionId) > 0 {
|
||||
return self.subscriptionId
|
||||
}
|
||||
for _, sub := range self.subscriptions {
|
||||
if sub.State == "Enabled" {
|
||||
return sub.SubscriptionId
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (self *SAzureClient) _list(resource string, params url.Values) (jsonutils.JSONObject, error) {
|
||||
subId := self._subscriptionId()
|
||||
path := "subscriptions"
|
||||
switch resource {
|
||||
case "subscriptions", "providers/Microsoft.Billing/enrollmentAccounts":
|
||||
|
||||
@@ -540,12 +540,16 @@ func (self *SRegion) checkResourceGroup(resourceGroup string) (string, error) {
|
||||
if len(resourceGroup) == 0 {
|
||||
resourceGroup = "Default"
|
||||
}
|
||||
for i := range self.client.ressourceGroups {
|
||||
if strings.ToLower(self.client.ressourceGroups[i].Name) == strings.ToLower(resourceGroup) {
|
||||
projs, err := self.client.GetIProjects()
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "GetIProjects")
|
||||
}
|
||||
for _, proj := range projs {
|
||||
if strings.ToLower(proj.GetGlobalId()) == strings.ToLower(resourceGroup) {
|
||||
return resourceGroup, nil
|
||||
}
|
||||
}
|
||||
_, err := self.CreateResourceGroup(resourceGroup)
|
||||
_, err = self.CreateResourceGroup(resourceGroup)
|
||||
return resourceGroup, err
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ type SResourceGroup struct {
|
||||
|
||||
func (self *SRegion) GetResourceGroupDetail(groupName string) (*SResourceGroup, error) {
|
||||
resourceGroup := SResourceGroup{}
|
||||
idStr := fmt.Sprintf("subscriptions/%s/resourcegroups/%s", self.client.subscriptionId, groupName)
|
||||
idStr := fmt.Sprintf("subscriptions/%s/resourcegroups/%s", self.client._subscriptionId(), groupName)
|
||||
return &resourceGroup, self.get(idStr, url.Values{}, &resourceGroup)
|
||||
}
|
||||
|
||||
@@ -56,12 +56,12 @@ func (self *SRegion) UpdateResourceGroup(groupName string, newName string) error
|
||||
|
||||
func (self *SRegion) CreateResourceGroup(groupName string) (jsonutils.JSONObject, error) {
|
||||
resourceGroup := SResourceGroup{Location: self.Name}
|
||||
idStr := fmt.Sprintf("subscriptions/%s/resourcegroups/%s", self.client.subscriptionId, groupName)
|
||||
idStr := fmt.Sprintf("subscriptions/%s/resourcegroups/%s", self.client._subscriptionId(), groupName)
|
||||
return self.client.put(idStr, jsonutils.Marshal(resourceGroup))
|
||||
}
|
||||
|
||||
func (self *SRegion) DeleteResourceGroup(groupName string) error {
|
||||
idStr := fmt.Sprintf("subscriptions/%s/resourcegroups/%s", self.client.subscriptionId, groupName)
|
||||
idStr := fmt.Sprintf("subscriptions/%s/resourcegroups/%s", self.client._subscriptionId(), groupName)
|
||||
return self.del(idStr)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user