github.com/vmware/govmomi@v0.51.0/cli/namespace/vmclass/create.go (about) 1 // © Broadcom. All Rights Reserved. 2 // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. 3 // SPDX-License-Identifier: Apache-2.0 4 5 package vmclass 6 7 import ( 8 "context" 9 "flag" 10 11 "github.com/vmware/govmomi/cli" 12 "github.com/vmware/govmomi/cli/flags" 13 "github.com/vmware/govmomi/vapi/namespace" 14 ) 15 16 type create struct { 17 *flags.ClientFlag 18 19 spec namespace.VirtualMachineClassCreateSpec 20 } 21 22 func init() { 23 cli.Register("namespace.vmclass.create", &create{}) 24 } 25 26 func (cmd *create) Register(ctx context.Context, f *flag.FlagSet) { 27 cmd.ClientFlag, ctx = flags.NewClientFlag(ctx) 28 cmd.ClientFlag.Register(ctx, f) 29 30 f.Int64Var(&cmd.spec.CpuCount, "cpus", 0, "The number of CPUs.") 31 f.Int64Var(&cmd.spec.MemoryMb, "memory", 0, "The amount of memory (in MB).") 32 } 33 34 func (*create) Usage() string { 35 return "NAME" 36 } 37 38 func (cmd *create) Description() string { 39 return `Creates a new virtual machine class. 40 41 The name of the virtual machine class has DNS_LABEL restrictions 42 as specified in "https://tools.ietf.org/html/rfc1123". It 43 must be an alphanumeric (a-z and 0-9) string and with maximum length 44 of 63 characters and with the '-' character allowed anywhere except 45 the first or last character. This name is unique in this vCenter server. 46 47 Examples: 48 govc namespace.vmclass.create -cpus=8 -memory=8192 test-class-01` 49 } 50 51 func (cmd *create) Run(ctx context.Context, f *flag.FlagSet) error { 52 cmd.spec.Id = f.Arg(0) 53 if f.NArg() != 1 { 54 return flag.ErrHelp 55 } 56 57 rc, err := cmd.RestClient() 58 if err != nil { 59 return err 60 } 61 62 nm := namespace.NewManager(rc) 63 64 return nm.CreateVmClass(ctx, cmd.spec) 65 }