Skip to content

Commit

Permalink
Update FindTag() method to support ALL option
Browse files Browse the repository at this point in the history
  • Loading branch information
innodreamer committed Aug 20, 2024
1 parent f5e6a11 commit 65d15b1
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func handleTag() {

// rsType := irs.RSType(irs.VM)
// rsType := irs.RSType(irs.MYIMAGE)
rsType := irs.RSType(irs.DISK)
// rsType := irs.RSType(irs.DISK)
rsType := irs.RSType(irs.ALL)

rsIId := irs.IID{
NameId: "MyVM-1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,35 +198,73 @@ func (tagHandler *KtCloudTagHandler) FindTag(resType irs.RSType, keyword string)
return nil, newErr
}

tagList, err := tagHandler.getTagList(resType)
if err != nil {
newErr := fmt.Errorf("Failed to Get Tag List : [%v]", err)
cblogger.Error(newErr.Error())
return nil, newErr
}

var tagList []ktsdk.Tag
var tagInfoList []*irs.TagInfo
for _, curTag := range tagList {
if strings.Contains(curTag.Key, keyword) || strings.Contains(curTag.Value, keyword) {
var tagKVList []irs.KeyValue
tagKV := irs.KeyValue {
Key: curTag.Key,
Value: curTag.Value,

if resType == irs.RSType(irs.ALL) {
resTypes := []irs.RSType{irs.RSType(irs.VM), irs.RSType(irs.MYIMAGE), irs.RSType(irs.DISK)}
for _, curType := range resTypes {
var err error
tagList, err = tagHandler.getTagList(curType)
if err != nil {
newErr := fmt.Errorf("Failed to Get Tag List : [%v]", err)
cblogger.Error(newErr.Error())
return nil, newErr
}
tagKVList = append(tagKVList, tagKV)

tagInfo := &irs.TagInfo {
ResType : resType,
ResIId : irs.IID {
NameId : "",
SystemId: curTag.ResourceId,
},
TagList : tagKVList,
// KeyValueList: , // reserved for optinal usage
for _, curTag := range tagList {
if strings.Contains(curTag.Key, keyword) || strings.Contains(curTag.Value, keyword) {
var tagKVList []irs.KeyValue
tagKV := irs.KeyValue {
Key: curTag.Key,
Value: curTag.Value,
}
tagKVList = append(tagKVList, tagKV)

tagInfo := &irs.TagInfo {
ResType : curType,
ResIId : irs.IID {
NameId : "",
SystemId: curTag.ResourceId,
},
TagList : tagKVList,
// KeyValueList: , // reserved for optinal usage
}
tagInfoList = append(tagInfoList, tagInfo)
}
}
}
} else {
var err error
tagList, err = tagHandler.getTagList(resType)
if err != nil {
newErr := fmt.Errorf("Failed to Get Tag List : [%v]", err)
cblogger.Error(newErr.Error())
return nil, newErr
}

for _, curTag := range tagList {
if strings.Contains(curTag.Key, keyword) || strings.Contains(curTag.Value, keyword) {
var tagKVList []irs.KeyValue
tagKV := irs.KeyValue {
Key: curTag.Key,
Value: curTag.Value,
}
tagKVList = append(tagKVList, tagKV)

tagInfo := &irs.TagInfo {
ResType : resType,
ResIId : irs.IID {
NameId : "",
SystemId: curTag.ResourceId,
},
TagList : tagKVList,
// KeyValueList: , // reserved for optinal usage
}
tagInfoList = append(tagInfoList, tagInfo)
}
tagInfoList = append(tagInfoList, tagInfo)
}
}

return tagInfoList, nil
}

Expand Down

0 comments on commit 65d15b1

Please sign in to comment.