github.com/vmware/govmomi@v0.51.0/cli/vcsa/shutdown/get.go (about) 1 // © Broadcom. All Rights Reserved. 2 // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. 3 // SPDX-License-Identifier: Apache-2.0 4 5 package shutdown 6 7 import ( 8 "context" 9 "flag" 10 "fmt" 11 "io" 12 "text/tabwriter" 13 14 "github.com/vmware/govmomi/cli" 15 "github.com/vmware/govmomi/cli/flags" 16 "github.com/vmware/govmomi/vapi/appliance/shutdown" 17 ) 18 19 type get struct { 20 *flags.ClientFlag 21 *flags.OutputFlag 22 } 23 24 func init() { 25 cli.Register("vcsa.shutdown.get", &get{}) 26 } 27 28 func (cmd *get) Register(ctx context.Context, f *flag.FlagSet) { 29 cmd.ClientFlag, ctx = flags.NewClientFlag(ctx) 30 cmd.ClientFlag.Register(ctx, f) 31 32 cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx) 33 cmd.OutputFlag.Register(ctx, f) 34 } 35 36 func (cmd *get) Process(ctx context.Context) error { 37 if err := cmd.ClientFlag.Process(ctx); err != nil { 38 return err 39 } 40 if err := cmd.OutputFlag.Process(ctx); err != nil { 41 return err 42 } 43 return nil 44 } 45 46 func (cmd *get) Description() string { 47 return `Get details about the pending shutdown action. 48 49 Note: This command requires vCenter 7.0.2 or higher. 50 51 Examples: 52 govc vcsa.shutdown.get` 53 } 54 55 type config struct { 56 shutdown.Config 57 } 58 59 func (cmd *get) Run(ctx context.Context, f *flag.FlagSet) error { 60 c, err := cmd.RestClient() 61 if err != nil { 62 return err 63 } 64 65 m := shutdown.NewManager(c) 66 67 s, err := m.Get(ctx) 68 if err != nil { 69 return err 70 } 71 72 return cmd.WriteResult(config{ 73 s, 74 }) 75 } 76 77 func (c config) Write(w io.Writer) error { 78 tw := tabwriter.NewWriter(w, 2, 0, 2, ' ', 0) 79 fmt.Fprintf(tw, "Action:%s\n", c.Action) 80 fmt.Fprintf(tw, "Reason:%s\n", c.Reason) 81 fmt.Fprintf(tw, "ShutDown Time:%s\n", c.ShutdownTime) 82 83 return tw.Flush() 84 }