yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/qcloud/tag_base.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 qcloud 16 17 import ( 18 "strings" 19 20 "yunion.io/x/pkg/errors" 21 22 "yunion.io/x/cloudmux/pkg/cloudprovider" 23 "yunion.io/x/cloudmux/pkg/multicloud" 24 ) 25 26 type QcloudTags struct { 27 TagSet []multicloud.STag 28 29 // Redis 30 InstanceTags []multicloud.STag 31 // Elasticsearch 32 TagList []multicloud.STag 33 // Kafka 34 Tags []multicloud.STag 35 // Cdn 36 Tag []multicloud.STag 37 // TDSQL 38 ResourceTags []multicloud.STag 39 } 40 41 func (self *QcloudTags) getTags() (map[string]string, error) { 42 ret := map[string]string{} 43 for _, tag := range self.TagSet { 44 if tag.Value == "null" { 45 tag.Value = "" 46 } 47 ret[tag.Key] = tag.Value 48 } 49 for _, tag := range self.InstanceTags { 50 if tag.TagValue == "null" { 51 tag.TagValue = "" 52 } 53 ret[tag.TagKey] = tag.TagValue 54 } 55 for _, tag := range self.TagList { 56 if tag.TagValue == "null" { 57 tag.TagValue = "" 58 } 59 ret[tag.TagKey] = tag.TagValue 60 } 61 for _, tag := range self.Tags { 62 if tag.TagValue == "null" { 63 tag.TagValue = "" 64 } 65 ret[tag.TagKey] = tag.TagValue 66 } 67 for _, tag := range self.Tag { 68 if tag.TagValue == "null" { 69 tag.TagValue = "" 70 } 71 ret[tag.TagKey] = tag.TagValue 72 } 73 for _, tag := range self.ResourceTags { 74 if tag.TagValue == "null" { 75 tag.TagValue = "" 76 } 77 ret[tag.TagKey] = tag.TagValue 78 } 79 return ret, nil 80 } 81 82 func (self *QcloudTags) GetTags() (map[string]string, error) { 83 tags, _ := self.getTags() 84 for k := range tags { 85 if strings.HasPrefix(k, "tencentcloud:") { 86 delete(tags, k) 87 } 88 } 89 return tags, nil 90 } 91 92 func (self *QcloudTags) GetSysTags() map[string]string { 93 tags, _ := self.getTags() 94 ret := map[string]string{} 95 for k, v := range tags { 96 if strings.HasPrefix(k, "tencentcloud:") { 97 ret[k] = v 98 } 99 } 100 return ret 101 } 102 103 func (self *QcloudTags) SetTags(tags map[string]string, replace bool) error { 104 return errors.Wrap(cloudprovider.ErrNotImplemented, "SetTags") 105 }