github.com/vmware/govmomi@v0.43.0/govc/vcsa/shutdown/reboot.go (about) 1 /* 2 Copyright (c) 2022 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 shutdown 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/appliance/shutdown" 26 ) 27 28 type reboot struct { 29 *flags.ClientFlag 30 31 reason string 32 delay int // in minutes 33 } 34 35 func init() { 36 cli.Register("vcsa.shutdown.reboot", &reboot{}) 37 } 38 39 func (cmd *reboot) Register(ctx context.Context, f *flag.FlagSet) { 40 cmd.ClientFlag, ctx = flags.NewClientFlag(ctx) 41 cmd.ClientFlag.Register(ctx, f) 42 43 var now int 44 f.IntVar(&cmd.delay, 45 "delay", 46 now, 47 "Minutes after which reboot should start.") 48 } 49 50 func (cmd *reboot) Process(ctx context.Context) error { 51 if err := cmd.ClientFlag.Process(ctx); err != nil { 52 return err 53 } 54 return nil 55 } 56 57 func (cmd *reboot) Usage() string { 58 return "REASON" 59 } 60 61 func (cmd *reboot) Description() string { 62 return `Reboot the appliance. 63 64 Note: This command requires vCenter 7.0.2 or higher. 65 66 Examples: 67 govc vcsa.shutdown.reboot -delay 10 "rebooting for maintenance"` 68 } 69 70 func (cmd *reboot) Run(ctx context.Context, f *flag.FlagSet) error { 71 if f.NArg() != 1 { 72 return flag.ErrHelp 73 } 74 75 c, err := cmd.RestClient() 76 if err != nil { 77 return err 78 } 79 80 m := shutdown.NewManager(c) 81 82 if err = m.Reboot(ctx, f.Arg(0), cmd.delay); err != nil { 83 return err 84 } 85 86 return nil 87 }