github.com/vmware/govmomi@v0.37.1/govc/namespace/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 namespace 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 libraries flags.StringList 32 vmClasses flags.StringList 33 spec namespace.NamespacesInstanceUpdateSpec 34 } 35 36 func init() { 37 cli.Register("namespace.update", &update{}) 38 } 39 40 func (cmd *update) Register(ctx context.Context, f *flag.FlagSet) { 41 cmd.ClientFlag, ctx = flags.NewClientFlag(ctx) 42 cmd.ClientFlag.Register(ctx, f) 43 44 f.Var(&cmd.libraries, "library", "Content library IDs to associate with the vSphere Namespace.") 45 f.Var(&cmd.vmClasses, "vm-class", "Virtual machine class IDs to associate with the vSphere Namespace.") 46 } 47 48 func (cmd *update) Process(ctx context.Context) error { 49 cmd.spec.VmServiceSpec.ContentLibraries = cmd.libraries 50 cmd.spec.VmServiceSpec.VmClasses = cmd.vmClasses 51 52 return cmd.ClientFlag.Process(ctx) 53 } 54 55 func (cmd *update) Usage() string { 56 return "NAME" 57 } 58 59 func (cmd *update) Description() string { 60 return `Modifies an existing vSphere Namespace on a Supervisor. 61 62 Examples: 63 govc namespace.update -library=dca9cc16-9460-4da0-802c-4aa148ac6cf7 test-namespace 64 govc namespace.update -library=dca9cc16-9460-4da0-802c-4aa148ac6cf7 -library=617a3ee3-a2ff-4311-9a7c-0016ccf958bd test-namespace 65 govc namespace.update -vm-class=best-effort-2xlarge test-namespace 66 govc namespace.update -vm-class=best-effort-2xlarge -vm-class=best-effort-4xlarge test-namespace 67 govc namespace.update -library=dca9cc16-9460-4da0-802c-4aa148ac6cf7 -library=617a3ee3-a2ff-4311-9a7c-0016ccf958bd -vm-class=best-effort-2xlarge -vm-class=best-effort-4xlarge test-namespace` 68 } 69 70 func (cmd *update) Run(ctx context.Context, f *flag.FlagSet) error { 71 if f.NArg() != 1 { 72 return flag.ErrHelp 73 } 74 75 rc, err := cmd.RestClient() 76 if err != nil { 77 return err 78 } 79 80 nm := namespace.NewManager(rc) 81 82 return nm.UpdateNamespace(ctx, f.Arg(0), cmd.spec) 83 }