github.com/vmware/govmomi@v0.37.2/vapi/appliance/access/consolecli/consolecli.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 consolecli
    18  
    19  import (
    20  	"context"
    21  	"net/http"
    22  
    23  	"github.com/vmware/govmomi/vapi/rest"
    24  )
    25  
    26  const Path = "/api/appliance/access/consolecli"
    27  
    28  // Manager provides convenience methods to get/set enabled state of CLI.
    29  type Manager struct {
    30  	*rest.Client
    31  }
    32  
    33  // NewManager creates a new Manager with the given client
    34  func NewManager(client *rest.Client) *Manager {
    35  	return &Manager{
    36  		Client: client,
    37  	}
    38  }
    39  
    40  // Get returns enabled state of the console-based controlled CLI (TTY1).
    41  func (m *Manager) Get(ctx context.Context) (bool, error) {
    42  	r := m.Resource(Path)
    43  
    44  	var status bool
    45  	return status, m.Do(ctx, r.Request(http.MethodGet), &status)
    46  }
    47  
    48  // Access represents the value to be set for ConsoleCLI
    49  type Access struct {
    50  	Enabled bool `json:"enabled"`
    51  }
    52  
    53  // Set enables state of the console-based controlled CLI (TTY1).
    54  func (m *Manager) Set(ctx context.Context, inp Access) error {
    55  	r := m.Resource(Path)
    56  
    57  	return m.Do(ctx, r.Request(http.MethodPut, inp), nil)
    58  }