github.com/vmware/govmomi@v0.43.0/govc/vcsa/access/dcui/get.go (about) 1 /* 2 Copyright (c) 2022 VMware, Inc. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0. 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 dcui 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/access/dcui" 29 ) 30 31 type get struct { 32 *flags.ClientFlag 33 *flags.OutputFlag 34 } 35 36 func init() { 37 cli.Register("vcsa.access.dcui.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 enabled state of Direct Console User Interface (DCUI TTY2). 60 61 Note: This command requires vCenter 7.0.2 or higher. 62 63 Examples: 64 govc vcsa.access.dcui.get` 65 } 66 67 type access struct { 68 Enabled bool `json:"enabled"` 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 := dcui.NewManager(c) 78 79 status, err := m.Get(ctx) 80 if err != nil { 81 return err 82 } 83 84 return cmd.WriteResult(access{Enabled: status}) 85 } 86 87 func (res access) Write(w io.Writer) error { 88 tw := tabwriter.NewWriter(w, 10, 4, 0, ' ', 0) 89 90 fmt.Fprintf(tw, "%t\n", res.Enabled) 91 92 return tw.Flush() 93 }