diff --git a/pkg/mcclient/options/compute/servers.go b/pkg/mcclient/options/compute/servers.go index e1f1f1a81d..3827d61fc3 100644 --- a/pkg/mcclient/options/compute/servers.go +++ b/pkg/mcclient/options/compute/servers.go @@ -25,6 +25,7 @@ import ( "yunion.io/x/pkg/util/fileutils" "yunion.io/x/pkg/util/regutils" + "yunion.io/x/onecloud/pkg/apis/cloudcommon/db" computeapi "yunion.io/x/onecloud/pkg/apis/compute" schedapi "yunion.io/x/onecloud/pkg/apis/scheduler" "yunion.io/x/onecloud/pkg/cloudcommon/cmdline" @@ -468,7 +469,8 @@ type ServerCreateOptionalOptions struct { GuestImageID string `help:"create from guest image, need to specify the guest image id"` - EncryptKey string `help:"encryption key"` + EncryptKey string `help:"encryption key"` + Tags []string `help:"tags in the form of key=value"` } func (o *ServerCreateOptions) ToScheduleInput() (*schedapi.ScheduleInput, error) { @@ -633,6 +635,17 @@ func (opts *ServerCreateOptions) Params() (*computeapi.ServerCreateInput, error) if err != nil { return nil, err } + meta := map[string]string{} + for _, v := range opts.Tags { + tag := strings.Split(v, "=") + if len(tag) != 2 { + return nil, fmt.Errorf("invalid tag %s", v) + } + prefix := db.USER_TAG_PREFIX + k, v := prefix+strings.TrimPrefix(tag[0], prefix), tag[1] + meta[k] = v + } + params.Metadata = meta if opts.GenerateName { params.GenerateName = opts.NAME