yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/apsara/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 apsara 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 ApsaraTags struct { 27 Tags struct { 28 Tag []multicloud.STag 29 } 30 } 31 32 func (self *ApsaraTags) GetTags() (map[string]string, error) { 33 ret := map[string]string{} 34 for _, tag := range self.Tags.Tag { 35 if strings.HasPrefix(tag.TagKey, "aliyun") || strings.HasPrefix(tag.TagKey, "acs:") || 36 strings.HasSuffix(tag.Key, "aliyun") || strings.HasPrefix(tag.Key, "acs:") { 37 continue 38 } 39 if len(tag.TagKey) > 0 { 40 ret[tag.TagKey] = tag.TagValue 41 } else if len(tag.Key) > 0 { 42 ret[tag.Key] = tag.Value 43 } 44 } 45 return ret, nil 46 } 47 48 func (self *ApsaraTags) GetSysTags() map[string]string { 49 ret := map[string]string{} 50 for _, tag := range self.Tags.Tag { 51 if strings.HasPrefix(tag.TagKey, "aliyun") || strings.HasPrefix(tag.TagKey, "acs:") || 52 strings.HasPrefix(tag.Key, "aliyun") || strings.HasPrefix(tag.Key, "acs:") { 53 if len(tag.TagKey) > 0 { 54 ret[tag.TagKey] = tag.TagValue 55 } else if len(tag.Key) > 0 { 56 ret[tag.Key] = tag.Value 57 } 58 } 59 } 60 return ret 61 } 62 63 func (self *ApsaraTags) SetTags(tags map[string]string, replace bool) error { 64 return errors.Wrap(cloudprovider.ErrNotImplemented, "SetTags") 65 }