github.com/vmware/govmomi@v0.37.1/govc/datastore/remove.go (about) 1 /* 2 Copyright (c) 2015 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 datastore 18 19 import ( 20 "context" 21 "flag" 22 23 "github.com/vmware/govmomi/govc/cli" 24 "github.com/vmware/govmomi/govc/flags" 25 ) 26 27 type remove struct { 28 *flags.HostSystemFlag 29 *flags.DatastoreFlag 30 } 31 32 func init() { 33 cli.Register("datastore.remove", &remove{}) 34 } 35 36 func (cmd *remove) Register(ctx context.Context, f *flag.FlagSet) { 37 cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx) 38 cmd.HostSystemFlag.Register(ctx, f) 39 40 cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx) 41 cmd.DatastoreFlag.Register(ctx, f) 42 } 43 44 func (cmd *remove) Process(ctx context.Context) error { 45 if err := cmd.HostSystemFlag.Process(ctx); err != nil { 46 return err 47 } 48 if err := cmd.DatastoreFlag.Process(ctx); err != nil { 49 return err 50 } 51 return nil 52 } 53 54 func (cmd *remove) Usage() string { 55 return "HOST..." 56 } 57 58 func (cmd *remove) Description() string { 59 return `Remove datastore from HOST. 60 61 Examples: 62 govc datastore.remove -ds nfsDatastore cluster1 63 govc datastore.remove -ds nasDatastore host1 host2 host3` 64 } 65 66 func (cmd *remove) Run(ctx context.Context, f *flag.FlagSet) error { 67 ds, err := cmd.Datastore() 68 if err != nil { 69 return err 70 } 71 72 hosts, err := cmd.HostSystems(f.Args()) 73 if err != nil { 74 return err 75 } 76 77 for _, host := range hosts { 78 hds, err := host.ConfigManager().DatastoreSystem(ctx) 79 if err != nil { 80 return err 81 } 82 83 err = hds.Remove(ctx, ds) 84 if err != nil { 85 return err 86 } 87 } 88 89 return nil 90 }