Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions pkg/multicloud/ksyun/shell/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package shell

import (
"strings"

"yunion.io/x/cloudmux/pkg/multicloud/ksyun"

"yunion.io/x/pkg/errors"
Expand All @@ -34,4 +36,38 @@ func init() {
printObject(ret)
return nil
})

type TagCreateOptions struct {
ResourceType string `choices:"kec-image|kec-instance|rds-instance|security-group|vpc|subnet|eip|slb|bucket|kcs-instance|volume|nat|tunnel|bws|peering" default:"kec-instance"`
ID string
Tags string `help:"tags, key:value"`
}
shellutils.R(&TagCreateOptions{}, "tag-create", "create tag", func(cli *ksyun.SRegion, args *TagCreateOptions) error {
tags := map[string]string{}
for _, t := range strings.Split(args.Tags, ",") {
parts := strings.Split(t, ":")
if len(parts) != 2 {
return errors.Errorf("invalid tag %s", t)
}
tags[parts[0]] = parts[1]
}
return cli.CreateTags(args.ResourceType, args.ID, tags)
})

type TagDeleteOptions struct {
ResourceType string `choices:"kec-image|kec-instance|rds-instance|security-group|vpc|subnet|eip|slb|bucket|kcs-instance|volume|nat|tunnel|bws|peering" default:"kec-instance"`
ID string
Tags string `help:"tags, key:value"`
}
shellutils.R(&TagDeleteOptions{}, "tag-delete", "delete tag", func(cli *ksyun.SRegion, args *TagDeleteOptions) error {
tags := map[string]string{}
for _, t := range strings.Split(args.Tags, ",") {
parts := strings.Split(t, ":")
if len(parts) != 2 {
return errors.Errorf("invalid tag %s", t)
}
tags[parts[0]] = parts[1]
}
return cli.DeleteTags(args.ResourceType, args.ID, tags)
})
}
Loading