github.com/vmware/govmomi@v0.43.0/govc/vcsa/access/shell/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 shell 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/shell" 26 ) 27 28 type set struct { 29 *flags.ClientFlag 30 enabled bool 31 timeout int 32 } 33 34 func init() { 35 cli.Register("vcsa.access.shell.set", &set{}) 36 } 37 38 func (cmd *set) Register(ctx context.Context, f *flag.FlagSet) { 39 cmd.ClientFlag, ctx = flags.NewClientFlag(ctx) 40 cmd.ClientFlag.Register(ctx, f) 41 42 f.BoolVar(&cmd.enabled, 43 "enabled", 44 false, 45 "Enable BASH, that is, access to BASH from within the controlled CLI.") 46 f.IntVar(&cmd.timeout, 47 "timeout", 48 0, 49 "The timeout (in seconds) specifies how long you enable the Shell access. The maximum timeout is 86400 seconds(1 day).") 50 } 51 52 func (cmd *set) Process(ctx context.Context) error { 53 if err := cmd.ClientFlag.Process(ctx); err != nil { 54 return err 55 } 56 57 return nil 58 } 59 60 func (cmd *set) Description() string { 61 return `Set enabled state of BASH, that is, access to BASH from within the controlled CLI. 62 63 Note: This command requires vCenter 7.0.2 or higher. 64 65 Examples: 66 # Enable Shell 67 govc vcsa.access.shell.set -enabled=true -timeout=240 68 69 # Disable Shell 70 govc vcsa.access.shell.set -enabled=false` 71 } 72 73 func (cmd *set) Run(ctx context.Context, f *flag.FlagSet) error { 74 c, err := cmd.RestClient() 75 if err != nil { 76 return err 77 } 78 79 m := shell.NewManager(c) 80 81 input := shell.Access{ 82 Enabled: cmd.enabled, 83 Timeout: cmd.timeout, 84 } 85 if err = m.Set(ctx, input); err != nil { 86 return err 87 } 88 89 return nil 90 }