github.com/vmware/govmomi@v0.43.0/govc/vcsa/access/ssh/set.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 ssh 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/access/ssh" 26 ) 27 28 type set struct { 29 *flags.ClientFlag 30 enabled bool 31 } 32 33 func init() { 34 cli.Register("vcsa.access.ssh.set", &set{}) 35 } 36 37 func (cmd *set) Register(ctx context.Context, f *flag.FlagSet) { 38 cmd.ClientFlag, ctx = flags.NewClientFlag(ctx) 39 cmd.ClientFlag.Register(ctx, f) 40 41 f.BoolVar(&cmd.enabled, 42 "enabled", 43 false, 44 "Enable SSH-based controlled CLI.") 45 } 46 47 func (cmd *set) Process(ctx context.Context) error { 48 if err := cmd.ClientFlag.Process(ctx); err != nil { 49 return err 50 } 51 52 return nil 53 } 54 55 func (cmd *set) Description() string { 56 return `Set enabled state of the SSH-based controlled CLI. 57 58 Note: This command requires vCenter 7.0.2 or higher. 59 60 Examples: 61 # Enable SSH 62 govc vcsa.access.ssh.set -enabled=true 63 64 # Disable SSH 65 govc vcsa.access.ssh.set -enabled=false` 66 } 67 68 func (cmd *set) Run(ctx context.Context, f *flag.FlagSet) error { 69 c, err := cmd.RestClient() 70 if err != nil { 71 return err 72 } 73 74 m := ssh.NewManager(c) 75 76 input := ssh.Access{Enabled: cmd.enabled} 77 if err = m.Set(ctx, input); err != nil { 78 return err 79 } 80 81 return nil 82 }