yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/azure/resourcegroup.go (about) 1 // Copyright 2019 Yunion 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package azure 16 17 import ( 18 "fmt" 19 "net/url" 20 "strings" 21 22 "yunion.io/x/jsonutils" 23 24 api "yunion.io/x/cloudmux/pkg/apis/compute" 25 "yunion.io/x/cloudmux/pkg/multicloud" 26 ) 27 28 type GroupProperties struct { 29 ProvisioningState string 30 } 31 32 type SResourceGroup struct { 33 multicloud.SProjectBase 34 AzureTags 35 client *SAzureClient 36 37 ID string 38 Name string 39 Location string 40 Properties GroupProperties 41 ManagedBy string 42 subId string 43 } 44 45 func (self *SRegion) GetResourceGroupDetail(groupName string) (*SResourceGroup, error) { 46 resourceGroup := SResourceGroup{client: self.client, subId: self.client._subscriptionId()} 47 idStr := fmt.Sprintf("subscriptions/%s/resourcegroups/%s", self.client._subscriptionId(), groupName) 48 return &resourceGroup, self.get(idStr, url.Values{}, &resourceGroup) 49 } 50 51 // not support update, resource group name is immutable??? 52 func (self *SRegion) UpdateResourceGroup(groupName string, newName string) error { 53 resourceGroup := SResourceGroup{Name: newName, client: self.client, subId: self.client._subscriptionId()} 54 resource := fmt.Sprintf("subscriptions/%s/resourcegroups/%s", self.client.subscriptionId, groupName) 55 _, err := self.client.patch(resource, jsonutils.Marshal(&resourceGroup)) 56 return err 57 } 58 59 func (self *SRegion) CreateResourceGroup(groupName string) (jsonutils.JSONObject, error) { 60 resourceGroup := SResourceGroup{Location: self.Name, client: self.client, subId: self.client._subscriptionId()} 61 idStr := fmt.Sprintf("subscriptions/%s/resourcegroups/%s", self.client._subscriptionId(), groupName) 62 return self.client.put(idStr, jsonutils.Marshal(resourceGroup)) 63 } 64 65 func (self *SRegion) DeleteResourceGroup(groupName string) error { 66 idStr := fmt.Sprintf("subscriptions/%s/resourcegroups/%s", self.client._subscriptionId(), groupName) 67 return self.del(idStr) 68 } 69 70 func (r *SResourceGroup) GetName() string { 71 return r.Name 72 } 73 74 func (r *SResourceGroup) GetId() string { 75 return r.ID 76 } 77 78 func (self *SResourceGroup) GetAccountId() string { 79 return fmt.Sprintf("%s/%s", self.client.tenantId, self.subId) 80 } 81 82 func (r *SResourceGroup) GetGlobalId() string { 83 return strings.ToLower(fmt.Sprintf("%s/%s", r.subId, r.Name)) 84 } 85 86 func (r *SResourceGroup) GetStatus() string { 87 return api.EXTERNAL_PROJECT_STATUS_AVAILABLE 88 }