github.com/vmware/govmomi@v0.43.0/govc/vm/dataset/entry/rm.go (about) 1 /* 2 Copyright (c) 2023-2023 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 entry 18 19 import ( 20 "context" 21 "flag" 22 23 "github.com/vmware/govmomi/govc/cli" 24 "github.com/vmware/govmomi/govc/flags" 25 govc "github.com/vmware/govmomi/govc/vm/dataset" 26 "github.com/vmware/govmomi/vapi/vm/dataset" 27 ) 28 29 type rm struct { 30 *flags.VirtualMachineFlag 31 dataSet string 32 } 33 34 func init() { 35 cli.Register("vm.dataset.entry.rm", &rm{}) 36 } 37 38 func (cmd *rm) Register(ctx context.Context, f *flag.FlagSet) { 39 cmd.VirtualMachineFlag, ctx = flags.NewVirtualMachineFlag(ctx) 40 cmd.VirtualMachineFlag.Register(ctx, f) 41 f.StringVar(&cmd.dataSet, "dataset", "", "Data set name or ID") 42 } 43 44 func (cmd *rm) Process(ctx context.Context) error { 45 return cmd.VirtualMachineFlag.Process(ctx) 46 } 47 48 func (cmd *rm) Usage() string { 49 return "KEY" 50 } 51 52 func (cmd *rm) Description() string { 53 return `Delete data set entry. 54 55 Examples: 56 govc vm.dataset.entry.rm -vm $vm -dataset com.example.project2 somekey` 57 } 58 59 func (cmd *rm) Run(ctx context.Context, f *flag.FlagSet) error { 60 if f.NArg() != 1 { 61 return flag.ErrHelp 62 } 63 entryKey := f.Arg(0) 64 65 vm, err := cmd.VirtualMachineFlag.VirtualMachine() 66 if err != nil { 67 return err 68 } 69 if vm == nil { 70 return flag.ErrHelp 71 } 72 vmId := vm.Reference().Value 73 74 if cmd.dataSet == "" { 75 return flag.ErrHelp 76 } 77 78 c, err := cmd.RestClient() 79 if err != nil { 80 return err 81 } 82 mgr := dataset.NewManager(c) 83 dataSetId, err := govc.FindDataSetId(ctx, mgr, vmId, cmd.dataSet) 84 if err != nil { 85 return err 86 } 87 return mgr.DeleteEntry(ctx, vmId, dataSetId, entryKey) 88 }