github.com/vmware/govmomi@v0.37.1/govc/datastore/maintenance/exit.go (about) 1 /* 2 Copyright (c) 2019 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 maintenance 18 19 import ( 20 "context" 21 "flag" 22 "fmt" 23 24 "github.com/vmware/govmomi/govc/cli" 25 "github.com/vmware/govmomi/govc/flags" 26 "github.com/vmware/govmomi/object" 27 "github.com/vmware/govmomi/vim25/methods" 28 "github.com/vmware/govmomi/vim25/types" 29 ) 30 31 type exit struct { 32 *flags.DatastoreFlag 33 } 34 35 func init() { 36 cli.Register("datastore.maintenance.exit", &exit{}) 37 } 38 39 func (cmd *exit) Register(ctx context.Context, f *flag.FlagSet) { 40 cmd.DatastoreFlag, ctx = flags.NewDatastoreFlag(ctx) 41 cmd.DatastoreFlag.Register(ctx, f) 42 } 43 44 func (cmd *exit) Usage() string { 45 return "DATASTORE" 46 } 47 48 func (cmd *exit) Description() string { 49 return `Take DATASTORE out of maintenance mode.` 50 } 51 52 func (cmd *exit) ExitMaintenanceMode(ctx context.Context, ds *object.Datastore) error { 53 req := &types.DatastoreExitMaintenanceMode_Task{ 54 This: ds.Reference(), 55 } 56 res, err := methods.DatastoreExitMaintenanceMode_Task(ctx, ds.Client(), req) 57 if err != nil { 58 return err 59 } 60 61 task := object.NewTask(ds.Client(), res.Returnval) 62 63 logger := cmd.ProgressLogger(fmt.Sprintf("%s exiting maintenance mode... ", ds.InventoryPath)) 64 defer logger.Wait() 65 66 _, err = task.WaitForResult(ctx, logger) 67 return err 68 } 69 70 func (cmd *exit) Run(ctx context.Context, f *flag.FlagSet) error { 71 ds, err := cmd.Datastore() 72 if err != nil { 73 return err 74 } 75 76 return cmd.ExitMaintenanceMode(ctx, ds) 77 }