mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): optimized azure aliyun qcloud tags sync
This commit is contained in:
@@ -851,18 +851,6 @@ func (region *SRegion) RenewDBInstance(instanceId string, bc billing.SBillingCyc
|
||||
return err
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) GetTags() (map[string]string, error) {
|
||||
tags, err := rds.region.ListTags(ALIYUN_SERVICE_RDS, "INSTANCE", rds.GetId())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, `rds.region.ListTags`)
|
||||
}
|
||||
ret := map[string]string{}
|
||||
for _, tag := range tags {
|
||||
ret[tag.TagKey] = tag.TagValue
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (rds *SDBInstance) SetTags(tags map[string]string, replace bool) error {
|
||||
return rds.region.SetResourceTags(ALIYUN_SERVICE_RDS, "INSTANCE", rds.GetId(), tags, replace)
|
||||
}
|
||||
|
||||
@@ -33,10 +33,6 @@ type SMountInstances struct {
|
||||
MountInstance []string
|
||||
}
|
||||
|
||||
type STags struct {
|
||||
Tag []string
|
||||
}
|
||||
|
||||
type SDisk struct {
|
||||
storage *SStorage
|
||||
multicloud.SDisk
|
||||
@@ -69,7 +65,6 @@ type SDisk struct {
|
||||
Size int
|
||||
SourceSnapshotId string
|
||||
Status string
|
||||
Tags STags
|
||||
Type string
|
||||
ZoneId string
|
||||
}
|
||||
@@ -317,18 +312,19 @@ func (self *SRegion) resetDisk(diskId, snapshotId string) error {
|
||||
}
|
||||
|
||||
func (self *SDisk) CreateISnapshot(ctx context.Context, name, desc string) (cloudprovider.ICloudSnapshot, error) {
|
||||
if snapshotId, err := self.storage.zone.region.CreateSnapshot(self.DiskId, name, desc); err != nil {
|
||||
log.Errorf("createSnapshot fail %s", err)
|
||||
return nil, err
|
||||
} else if snapshot, err := self.getSnapshot(snapshotId); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
snapshot.region = self.storage.zone.region
|
||||
if err := cloudprovider.WaitStatus(snapshot, api.SNAPSHOT_READY, 15*time.Second, 3600*time.Second); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return snapshot, nil
|
||||
snapshotId, err := self.storage.zone.region.CreateSnapshot(self.DiskId, name, desc)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "CreateSnapshot")
|
||||
}
|
||||
snapshot, err := self.storage.zone.region.GetISnapshotById(snapshotId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "getSnapshot(%s)", snapshotId)
|
||||
}
|
||||
err = cloudprovider.WaitStatus(snapshot, api.SNAPSHOT_READY, 15*time.Second, 3600*time.Second)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "cloudprovider.WaitStatus")
|
||||
}
|
||||
return snapshot, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) CreateSnapshot(diskId, name, desc string) (string, error) {
|
||||
@@ -347,41 +343,25 @@ func (self *SRegion) CreateSnapshot(diskId, name, desc string) (string, error) {
|
||||
}
|
||||
|
||||
func (self *SDisk) GetISnapshot(snapshotId string) (cloudprovider.ICloudSnapshot, error) {
|
||||
if snapshot, err := self.getSnapshot(snapshotId); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
snapshot.region = self.storage.zone.region
|
||||
return snapshot, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (self *SDisk) getSnapshot(snapshotId string) (*SSnapshot, error) {
|
||||
if snapshots, total, err := self.storage.zone.region.GetSnapshots("", "", "", []string{snapshotId}, 0, 1); err != nil {
|
||||
return nil, err
|
||||
} else if total != 1 {
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
} else {
|
||||
return &snapshots[0], nil
|
||||
}
|
||||
return self.storage.zone.region.GetISnapshotById(snapshotId)
|
||||
}
|
||||
|
||||
func (self *SDisk) GetISnapshots() ([]cloudprovider.ICloudSnapshot, error) {
|
||||
snapshots := make([]SSnapshot, 0)
|
||||
for {
|
||||
if parts, total, err := self.storage.zone.region.GetSnapshots("", self.DiskId, "", []string{}, 0, 20); err != nil {
|
||||
log.Errorf("GetDisks fail %s", err)
|
||||
return nil, err
|
||||
} else {
|
||||
snapshots = append(snapshots, parts...)
|
||||
if len(snapshots) >= total {
|
||||
break
|
||||
}
|
||||
parts, total, err := self.storage.zone.region.GetSnapshots("", self.DiskId, "", []string{}, 0, 20)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetSnapshots(%s)", self.DiskId)
|
||||
}
|
||||
snapshots = append(snapshots, parts...)
|
||||
if len(snapshots) >= total {
|
||||
break
|
||||
}
|
||||
}
|
||||
isnapshots := make([]cloudprovider.ICloudSnapshot, len(snapshots))
|
||||
isnapshots := []cloudprovider.ICloudSnapshot{}
|
||||
for i := 0; i < len(snapshots); i++ {
|
||||
snapshots[i].region = self.storage.zone.region
|
||||
isnapshots[i] = &snapshots[i]
|
||||
isnapshots = append(isnapshots, &snapshots[i])
|
||||
}
|
||||
return isnapshots, nil
|
||||
}
|
||||
|
||||
@@ -61,7 +61,6 @@ type SElasticcache struct {
|
||||
Bandwidth int64 `json:"Bandwidth"`
|
||||
ChargeType TChargeType `json:"ChargeType"`
|
||||
InstanceType string `json:"InstanceType"`
|
||||
Tags Tags `json:"Tags"`
|
||||
InstanceStatus string `json:"InstanceStatus"`
|
||||
Port int `json:"Port"`
|
||||
InstanceClass string `json:"InstanceClass"`
|
||||
@@ -101,7 +100,6 @@ type SElasticcacheAttribute struct {
|
||||
ReplicationMode string `json:"ReplicationMode"`
|
||||
InstanceType string `json:"InstanceType"`
|
||||
InstanceStatus string `json:"InstanceStatus"`
|
||||
Tags Tags `json:"Tags"`
|
||||
Port int64 `json:"Port"`
|
||||
InstanceClass string `json:"InstanceClass"`
|
||||
CreateTime time.Time `json:"CreateTime"`
|
||||
@@ -925,18 +923,6 @@ func (self *SElasticcache) GetICloudElasticcacheBackup(backupId string) (cloudpr
|
||||
return nil, cloudprovider.ErrNotFound
|
||||
}
|
||||
|
||||
func (instance *SElasticcache) GetTags() (map[string]string, error) {
|
||||
tags, err := instance.region.ListTags(ALIYUN_SERVICE_KVS, "INSTANCE", instance.GetId())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "instance.region.ListTags")
|
||||
}
|
||||
ret := map[string]string{}
|
||||
for _, tag := range tags {
|
||||
ret[tag.TagKey] = tag.TagValue
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (instance *SElasticcache) SetTags(tags map[string]string, replace bool) error {
|
||||
return instance.region.SetResourceTags(ALIYUN_SERVICE_KVS, "INSTANCE", instance.GetId(), tags, replace)
|
||||
}
|
||||
|
||||
@@ -70,8 +70,6 @@ type SFileSystem struct {
|
||||
FileSystemType string
|
||||
FileSystemId string
|
||||
RegionId string
|
||||
|
||||
Tags Tags
|
||||
}
|
||||
|
||||
func (self *SFileSystem) GetId() string {
|
||||
@@ -167,10 +165,6 @@ func (self *SFileSystem) Refresh() error {
|
||||
return jsonutils.Update(self, fs)
|
||||
}
|
||||
|
||||
func (self *SFileSystem) GetTags() (map[string]string, error) {
|
||||
return self.Tags.GetTags()
|
||||
}
|
||||
|
||||
func (self *SRegion) GetFileSystems(id string, pageSize, pageNum int) ([]SFileSystem, int, error) {
|
||||
if pageSize < 1 || pageSize > 100 {
|
||||
pageSize = 50
|
||||
|
||||
@@ -130,9 +130,6 @@ type SInstance struct {
|
||||
VlanId string
|
||||
VpcAttributes SVpcAttributes
|
||||
ZoneId string
|
||||
|
||||
sys map[string]string
|
||||
user map[string]string
|
||||
}
|
||||
|
||||
// {"AutoReleaseTime":"","ClusterId":"","Cpu":1,"CreationTime":"2018-05-23T07:58Z","DedicatedHostAttribute":{"DedicatedHostId":"","DedicatedHostName":""},"Description":"","DeviceAvailable":true,"EipAddress":{"AllocationId":"","InternetChargeType":"","IpAddress":""},"ExpiredTime":"2018-05-30T16:00Z","GPUAmount":0,"GPUSpec":"","HostName":"iZ2ze57isp1ali72tzkjowZ","ImageId":"centos_7_04_64_20G_alibase_201701015.vhd","InnerIpAddress":{"IpAddress":[]},"InstanceChargeType":"PrePaid","InstanceId":"i-2ze57isp1ali72tzkjow","InstanceName":"gaoxianqi-test-7days","InstanceNetworkType":"vpc","InstanceType":"ecs.t5-lc2m1.nano","InstanceTypeFamily":"ecs.t5","InternetChargeType":"PayByBandwidth","InternetMaxBandwidthIn":-1,"InternetMaxBandwidthOut":0,"IoOptimized":true,"Memory":512,"NetworkInterfaces":{"NetworkInterface":[{"MacAddress":"00:16:3e:10:f0:c9","NetworkInterfaceId":"eni-2zecqsagtpztl6x5hu2r","PrimaryIpAddress":"192.168.220.214"}]},"OSName":"CentOS 7.4 64位","OSType":"linux","OperationLocks":{"LockReason":[]},"PublicIpAddress":{"IpAddress":[]},"Recyclable":false,"RegionId":"cn-beijing","ResourceGroupId":"","SaleCycle":"Week","SecurityGroupIds":{"SecurityGroupId":["sg-2zecqsagtpztl6x9zynl"]},"SerialNumber":"df05d9b4-df3d-4400-88d1-5f843f0dd088","SpotPriceLimit":0.000000,"SpotStrategy":"NoSpot","StartTime":"2018-05-23T07:58Z","Status":"Running","StoppedMode":"Not-applicable","VlanId":"","VpcAttributes":{"NatIpAddress":"","PrivateIpAddress":{"IpAddress":["192.168.220.214"]},"VSwitchId":"vsw-2ze9cqwza4upoyujq1thd","VpcId":"vpc-2zer4jy8ix3i8f0coc5uw"},"ZoneId":"cn-beijing-f"}
|
||||
@@ -183,14 +180,6 @@ func (self *SInstance) GetSecurityGroupIds() ([]string, error) {
|
||||
|
||||
func (self *SInstance) GetSysTags() map[string]string {
|
||||
data := map[string]string{}
|
||||
// The pricingInfo key structure is 'RegionId::InstanceType::NetworkType::OSType::IoOptimized'
|
||||
optimized := "optimized"
|
||||
if !self.IoOptimized {
|
||||
optimized = "none"
|
||||
}
|
||||
priceKey := fmt.Sprintf("%s::%s::%s::%s::%s", self.RegionId, self.InstanceType, self.InstanceNetworkType, self.OSType, optimized)
|
||||
data["price_key"] = priceKey
|
||||
data["zone_ext_id"] = self.host.zone.GetGlobalId()
|
||||
if len(self.ImageId) > 0 {
|
||||
if image, err := self.host.zone.region.GetImage(self.ImageId); err != nil {
|
||||
log.Errorf("Failed to find image %s for instance %s", self.ImageId, self.GetName())
|
||||
@@ -201,33 +190,13 @@ func (self *SInstance) GetSysTags() map[string]string {
|
||||
}
|
||||
}
|
||||
}
|
||||
sys, _, _ := self.fetchTags()
|
||||
sys := self.STags.GetSysTags()
|
||||
for k, v := range sys {
|
||||
data[k] = v
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
func (self *SInstance) GetTags() (map[string]string, error) {
|
||||
_, tags, err := self.fetchTags()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "self.fetchTags")
|
||||
}
|
||||
return tags, nil
|
||||
}
|
||||
|
||||
func (self *SInstance) fetchTags() (map[string]string, map[string]string, error) {
|
||||
if self.sys != nil || self.user != nil {
|
||||
return self.sys, self.user, nil
|
||||
}
|
||||
var err error
|
||||
self.sys, self.user, err = self.host.zone.region.ListSysAndUserTags(ALIYUN_SERVICE_ECS, "instance", self.InstanceId)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrapf(err, "ListSysAndUserTags")
|
||||
}
|
||||
return self.sys, self.user, nil
|
||||
}
|
||||
|
||||
func (self *SInstance) GetIHost() cloudprovider.ICloudHost {
|
||||
return self.host
|
||||
}
|
||||
@@ -384,12 +353,11 @@ func (self *SInstance) GetStatus() string {
|
||||
}
|
||||
|
||||
func (self *SInstance) Refresh() error {
|
||||
self.sys, self.user = nil, nil
|
||||
new, err := self.host.zone.region.GetInstance(self.InstanceId)
|
||||
ins, err := self.host.zone.region.GetInstance(self.InstanceId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return jsonutils.Update(self, new)
|
||||
return jsonutils.Update(self, ins)
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -105,18 +105,6 @@ func (lb *SLoadbalancer) GetStatus() string {
|
||||
return api.LB_STATUS_DISABLED
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetTags() (map[string]string, error) {
|
||||
tags, err := lb.region.ListTags(ALIYUN_SERVICE_SLB, "instance", lb.GetId())
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "lb.region.ListTags")
|
||||
}
|
||||
ret := map[string]string{}
|
||||
for _, tag := range tags {
|
||||
ret[tag.TagKey] = tag.TagValue
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (lb *SLoadbalancer) GetAddress() string {
|
||||
return lb.Address
|
||||
}
|
||||
|
||||
@@ -44,7 +44,6 @@ type SMountTarget struct {
|
||||
MountTargetDomain string
|
||||
AccessGroup string
|
||||
ClientMasterNodes ClientMasterNodes
|
||||
Tags Tags
|
||||
}
|
||||
|
||||
func (self *SMountTarget) GetGlobalId() string {
|
||||
|
||||
@@ -451,7 +451,7 @@ func (self *SRegion) GetVpcs(vpcId []string, offset int, limit int) ([]SVpc, int
|
||||
params["VpcId"] = strings.Join(vpcId, ",")
|
||||
}
|
||||
|
||||
body, err := self.ecsRequest("DescribeVpcs", params)
|
||||
body, err := self.vpcRequest("DescribeVpcs", params)
|
||||
if err != nil {
|
||||
log.Errorf("GetVpcs fail %s", err)
|
||||
return nil, 0, err
|
||||
|
||||
@@ -62,23 +62,6 @@ type SPermissions struct {
|
||||
Permission []SPermission
|
||||
}
|
||||
|
||||
type Tags struct {
|
||||
Tag []Tag
|
||||
}
|
||||
|
||||
func (t Tags) GetTags() (map[string]string, error) {
|
||||
ret := map[string]string{}
|
||||
for _, tag := range t.Tag {
|
||||
ret[tag.TagKey] = tag.TagValue
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
type Tag struct {
|
||||
TagKey string
|
||||
TagValue string
|
||||
}
|
||||
|
||||
type SSecurityGroup struct {
|
||||
multicloud.SSecurityGroup
|
||||
|
||||
@@ -91,21 +74,12 @@ type SSecurityGroup struct {
|
||||
InnerAccessPolicy string
|
||||
Permissions SPermissions
|
||||
RegionId string
|
||||
Tags Tags
|
||||
}
|
||||
|
||||
func (self *SSecurityGroup) GetVpcId() string {
|
||||
return self.VpcId
|
||||
}
|
||||
|
||||
func (self *SSecurityGroup) GetTags() (map[string]string, error) {
|
||||
tags := map[string]string{}
|
||||
for _, value := range self.Tags.Tag {
|
||||
tags[value.TagKey] = value.TagValue
|
||||
}
|
||||
return tags, nil
|
||||
}
|
||||
|
||||
func (self *SSecurityGroup) GetId() string {
|
||||
return self.SecurityGroupId
|
||||
}
|
||||
|
||||
@@ -168,6 +168,10 @@ func (self *SRegion) GetDisks() ([]SDisk, error) {
|
||||
return disks, nil
|
||||
}
|
||||
|
||||
func (self *SDisk) GetTags() (map[string]string, error) {
|
||||
return self.Tags, nil
|
||||
}
|
||||
|
||||
func (self *SDisk) GetStatus() string {
|
||||
status := self.Properties.ProvisioningState
|
||||
switch status {
|
||||
|
||||
@@ -64,6 +64,10 @@ type SEipAddress struct {
|
||||
Sku *PublicIPAddressSku
|
||||
}
|
||||
|
||||
func (self *SEipAddress) GetTags() (map[string]string, error) {
|
||||
return self.Tags.GetTags()
|
||||
}
|
||||
|
||||
func (self *SRegion) AllocateEIP(name, projectId string) (*SEipAddress, error) {
|
||||
params := map[string]interface{}{
|
||||
"Location": self.Name,
|
||||
|
||||
@@ -35,6 +35,11 @@ type SNetwork struct {
|
||||
Name string
|
||||
Properties SubnetPropertiesFormat
|
||||
AddressPrefix string `json:"addressPrefix,omitempty"`
|
||||
Tags TAzureTags
|
||||
}
|
||||
|
||||
func (self *SNetwork) GetTags() (map[string]string, error) {
|
||||
return self.Tags, nil
|
||||
}
|
||||
|
||||
func (self *SNetwork) GetId() string {
|
||||
|
||||
@@ -94,9 +94,9 @@ type SStorageAccount struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Tags TAzureTags
|
||||
|
||||
Properties AccountProperties `json:"properties"`
|
||||
Tags TAzureTags
|
||||
}
|
||||
|
||||
func (self *SRegion) listStorageAccounts() ([]SStorageAccount, error) {
|
||||
|
||||
@@ -55,6 +55,10 @@ type SVpc struct {
|
||||
Properties VirtualNetworkPropertiesFormat `json:"properties,omitempty"`
|
||||
}
|
||||
|
||||
func (self *SVpc) GetTags() (map[string]string, error) {
|
||||
return self.Tags, nil
|
||||
}
|
||||
|
||||
func (self *SVpc) GetId() string {
|
||||
return self.ID
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ type SElasticcache struct {
|
||||
InstanceID string `json:"InstanceId"`
|
||||
InstanceName string `json:"InstanceName"`
|
||||
InstanceNode []interface{} `json:"InstanceNode"`
|
||||
InstanceTags []InstanceTag `json:"InstanceTags"`
|
||||
InstanceTitle string `json:"InstanceTitle"`
|
||||
OfflineTime string `json:"OfflineTime"`
|
||||
Port int `json:"Port"`
|
||||
@@ -53,7 +52,6 @@ type SElasticcache struct {
|
||||
Status int `json:"Status"`
|
||||
SubStatus int64 `json:"SubStatus"`
|
||||
SubnetID int64 `json:"SubnetId"`
|
||||
Tags []interface{} `json:"Tags"`
|
||||
Type int `json:"Type"`
|
||||
UniqSubnetID string `json:"UniqSubnetId"`
|
||||
UniqVpcID string `json:"UniqVpcId"`
|
||||
@@ -66,11 +64,6 @@ func (self *SElasticcache) SetTags(tags map[string]string, replace bool) error {
|
||||
return self.region.SetResourceTags("redis", "instance", []string{self.InstanceID}, tags, replace)
|
||||
}
|
||||
|
||||
type InstanceTag struct {
|
||||
TagKey string `json:"TagKey"`
|
||||
TagValue string `json:"TagValue"`
|
||||
}
|
||||
|
||||
type MaintenanceTime struct {
|
||||
StartTime string `json:"start_time"`
|
||||
EndTime string `json:"end_time"`
|
||||
@@ -241,17 +234,6 @@ func (self *SElasticcache) IsEmulated() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SElasticcache) GetTags() (map[string]string, error) {
|
||||
tags, err := self.region.FetchResourceTags("redis", "instance", []string{self.GetId()})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "self.region.FetchResourceTags")
|
||||
}
|
||||
if _, ok := tags[self.GetId()]; !ok {
|
||||
return map[string]string{}, nil
|
||||
}
|
||||
return *tags[self.GetId()], nil
|
||||
}
|
||||
|
||||
func (self *SElasticcache) GetProjectId() string {
|
||||
return strconv.Itoa(self.ProjectID)
|
||||
}
|
||||
|
||||
@@ -15,12 +15,80 @@
|
||||
package multicloud
|
||||
|
||||
import (
|
||||
"yunion.io/x/pkg/errors"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
)
|
||||
|
||||
type SResourceBase struct{}
|
||||
type STagSet struct {
|
||||
TagSet []STag
|
||||
//Redis
|
||||
InstanceTags []STag
|
||||
}
|
||||
|
||||
func (self STagSet) GetTags() (map[string]string, error) {
|
||||
ret := map[string]string{}
|
||||
for _, tag := range self.TagSet {
|
||||
ret[tag.Key] = tag.Value
|
||||
}
|
||||
for _, tag := range self.InstanceTags {
|
||||
ret[tag.TagKey] = tag.TagValue
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
type STag struct {
|
||||
TagKey string
|
||||
TagValue string
|
||||
|
||||
Key string
|
||||
Value string
|
||||
}
|
||||
|
||||
type STags struct {
|
||||
Tags struct {
|
||||
Tag []STag
|
||||
}
|
||||
}
|
||||
|
||||
func (self *STags) GetTags() (map[string]string, error) {
|
||||
ret := map[string]string{}
|
||||
for _, tag := range self.Tags.Tag {
|
||||
if strings.HasPrefix(tag.TagKey, "aliyun") || strings.HasPrefix(tag.TagKey, "acs:") ||
|
||||
strings.HasSuffix(tag.Key, "aliyun") || strings.HasPrefix(tag.Key, "acs:") {
|
||||
continue
|
||||
}
|
||||
if len(tag.TagKey) > 0 {
|
||||
ret[tag.TagKey] = tag.TagValue
|
||||
} else if len(tag.Key) > 0 {
|
||||
ret[tag.Key] = tag.Value
|
||||
}
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (self *STags) GetSysTags() map[string]string {
|
||||
ret := map[string]string{}
|
||||
for _, tag := range self.Tags.Tag {
|
||||
if strings.HasPrefix(tag.TagKey, "aliyun") || strings.HasPrefix(tag.TagKey, "acs:") ||
|
||||
strings.HasPrefix(tag.Key, "aliyun") || strings.HasPrefix(tag.Key, "acs:") {
|
||||
if len(tag.TagKey) > 0 {
|
||||
ret[tag.TagKey] = tag.TagValue
|
||||
} else if len(tag.Key) > 0 {
|
||||
ret[tag.Key] = tag.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
type SResourceBase struct {
|
||||
// Qcloud
|
||||
STagSet
|
||||
|
||||
// Aliyun
|
||||
STags
|
||||
}
|
||||
|
||||
func (self *SResourceBase) IsEmulated() bool {
|
||||
return false
|
||||
@@ -35,7 +103,15 @@ func (self *SResourceBase) GetSysTags() map[string]string {
|
||||
}
|
||||
|
||||
func (self *SResourceBase) GetTags() (map[string]string, error) {
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotImplemented, "GetTags")
|
||||
tags, _ := self.STagSet.GetTags()
|
||||
if len(tags) > 0 {
|
||||
return tags, nil
|
||||
}
|
||||
tags, _ = self.STags.GetTags()
|
||||
if len(tags) > 0 {
|
||||
return tags, nil
|
||||
}
|
||||
return map[string]string{}, nil
|
||||
}
|
||||
|
||||
func (self *SResourceBase) SetTags(tags map[string]string, replace bool) error {
|
||||
|
||||
Reference in New Issue
Block a user