github.com/vmware/govmomi@v0.37.1/govc/namespace/vmclass/update.go (about) 1 /* 2 Copyright (c) 2024-2024 VMware, Inc. All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package vmclass 18 19 import ( 20 "context" 21 "flag" 22 23 "github.com/vmware/govmomi/govc/cli" 24 "github.com/vmware/govmomi/govc/flags" 25 "github.com/vmware/govmomi/vapi/namespace" 26 ) 27 28 type update struct { 29 *flags.ClientFlag 30 31 spec namespace.VirtualMachineClassUpdateSpec 32 } 33 34 func init() { 35 cli.Register("namespace.vmclass.update", &update{}) 36 } 37 38 func (cmd *update) Register(ctx context.Context, f *flag.FlagSet) { 39 cmd.ClientFlag, ctx = flags.NewClientFlag(ctx) 40 cmd.ClientFlag.Register(ctx, f) 41 42 f.Int64Var(&cmd.spec.CpuCount, "cpus", 0, "The number of CPUs.") 43 f.Int64Var(&cmd.spec.MemoryMb, "memory", 0, "The amount of memory (in MB).") 44 } 45 46 func (cmd *update) Process(ctx context.Context) error { 47 return cmd.ClientFlag.Process(ctx) 48 } 49 50 func (cmd *update) Usage() string { 51 return "NAME" 52 } 53 54 func (cmd *update) Description() string { 55 return `Modifies an existing virtual machine class. 56 57 Examples: 58 govc namespace.vmclass.update -cpus=8 -memory=8192 test-class` 59 } 60 61 func (cmd *update) Run(ctx context.Context, f *flag.FlagSet) error { 62 rc, err := cmd.RestClient() 63 64 if err != nil { 65 return err 66 } 67 68 cmd.spec.Id = f.Arg(0) 69 70 nm := namespace.NewManager(rc) 71 72 return nm.UpdateVmClass(ctx, cmd.spec.Id, cmd.spec) 73 }