github.com/vmware/govmomi@v0.43.0/govc/vcsa/shutdown/get.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 "fmt" 23 "io" 24 "text/tabwriter" 25 26 "github.com/vmware/govmomi/govc/cli" 27 "github.com/vmware/govmomi/govc/flags" 28 "github.com/vmware/govmomi/vapi/appliance/shutdown" 29 ) 30 31 type get struct { 32 *flags.ClientFlag 33 *flags.OutputFlag 34 } 35 36 func init() { 37 cli.Register("vcsa.shutdown.get", &get{}) 38 } 39 40 func (cmd *get) Register(ctx context.Context, f *flag.FlagSet) { 41 cmd.ClientFlag, ctx = flags.NewClientFlag(ctx) 42 cmd.ClientFlag.Register(ctx, f) 43 44 cmd.OutputFlag, ctx = flags.NewOutputFlag(ctx) 45 cmd.OutputFlag.Register(ctx, f) 46 } 47 48 func (cmd *get) Process(ctx context.Context) error { 49 if err := cmd.ClientFlag.Process(ctx); err != nil { 50 return err 51 } 52 if err := cmd.OutputFlag.Process(ctx); err != nil { 53 return err 54 } 55 return nil 56 } 57 58 func (cmd *get) Description() string { 59 return `Get details about the pending shutdown action. 60 61 Note: This command requires vCenter 7.0.2 or higher. 62 63 Examples: 64 govc vcsa.shutdown.get` 65 } 66 67 type config struct { 68 shutdown.Config 69 } 70 71 func (cmd *get) Run(ctx context.Context, f *flag.FlagSet) error { 72 c, err := cmd.RestClient() 73 if err != nil { 74 return err 75 } 76 77 m := shutdown.NewManager(c) 78 79 s, err := m.Get(ctx) 80 if err != nil { 81 return err 82 } 83 84 return cmd.WriteResult(config{ 85 s, 86 }) 87 } 88 89 func (c config) Write(w io.Writer) error { 90 tw := tabwriter.NewWriter(w, 2, 0, 2, ' ', 0) 91 fmt.Fprintf(tw, "Action:%s\n", c.Action) 92 fmt.Fprintf(tw, "Reason:%s\n", c.Reason) 93 fmt.Fprintf(tw, "ShutDown Time:%s\n", c.ShutdownTime) 94 95 return tw.Flush() 96 }