client

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Copyright 2023 Fred78290. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const VMREST_CONTENT_TYPE = "application/vnd.vmware.vmw.rest-v1+json"

Variables

View Source
var (
	// ContextOAuth2 takes a oauth2.TokenSource as authentication for the request.
	ContextOAuth2 = contextKey("token")

	// ContextBasicAuth takes BasicAuth as authentication for the request.
	ContextBasicAuth = contextKey("basic")

	// ContextAccessToken takes a string oauth2 access token as authentication for the request.
	ContextAccessToken = contextKey("accesstoken")

	// ContextAPIKey takes an APIKey as authentication for the request
	ContextAPIKey = contextKey("apikey")
)

Functions

func NewHttpClient

func NewHttpClient(endpoint, userAgent, userName, password string, timeout time.Duration, unsecureTLS bool) (api.Client, error)

NewHttpClient Changes the VM power state

  • @param endpoint the endpoint to joint vmrest
  • @param userAgent
  • @param userName
  • @param password
  • @param timeout operation timeout in seconds
  • @param unsecureTLS unsecure tls

@return api.Client

Types

type APIClient

type APIClient struct {
	Client api.Client
	// contains filtered or unexported fields
}

APIClient manages communication with the VMware Workstation REST API API v1.3.0 In most cases there should be only one, shared, APIClient.

func NewAPIClient

func NewAPIClient(cfg *Configuration) (*APIClient, error)

NewAPIClient creates a new API client. Requires a userAgent string describing your application. optionally a custom http.Client to allow for advanced features such as caching.

func (*APIClient) ChangePowerState

func (c *APIClient) ChangePowerState(id string, operation model.VmPowerOperation) (*model.VmPowerState, error)

ChangePowerState Changes the VM power state

  • @param id ID of VM
  • @param operation VM power operation: on, off, shutdown, suspend, pause, unpause

@return VmPowerState

func (*APIClient) ConfigVMParams

func (c *APIClient) ConfigVMParams(id string, parameters *model.ConfigVmParamsParameter) (*model.ErrorModel, error)

ConfigVMParams update the vm config params

  • @param id ID of VM
  • @param parameters Parameters set to the VM

@return ErrorModel

func (*APIClient) CreateNICDevice

func (c *APIClient) CreateNICDevice(id string, parameters *model.NicDeviceParameter) (*model.NicDevice, error)

CreateNICDevice Creates a network adapter in the VM

  • @param id ID of VM
  • @param parameters Parameters of network adapter to create

@return NicDevice

func (*APIClient) CreateNetwork

func (c *APIClient) CreateNetwork(parameters *model.CreateVmnetParameter) (*model.Network, error)

CreateNetwork Creates a virtual network

  • @param parameters Host network to be created

@return Network

func (*APIClient) CreateSharedFolder

func (c *APIClient) CreateSharedFolder(id string, parameters *model.SharedFolder) (model.SharedFolders, error)

CreateSharedFolder Mounts a new shared folder in the VM

  • @param id ID of VM
  • @param parameters Parameters of the shared folder to mount

@return SharedFolders

func (*APIClient) CreateVM

func (c *APIClient) CreateVM(parameters *model.VmCloneParameter) (*model.VmInformation, error)

CreateVM Creates a copy of the VM

  • @param params Parameters of VM to create

@return VmInformation

func (*APIClient) DeleteNICDevice

func (c *APIClient) DeleteNICDevice(id string, index int) error

DeleteNICDevice Deletes a VM network adapter

  • @param id ID of VM
  • @param index Index of VM network adapter

func (*APIClient) DeletePortforward

func (c *APIClient) DeletePortforward(vmnet string, protocol string, port int) error

DeletePortforward Deletes port forwarding

  • @param vmnet NAT type of virtual network
  • @param protocol Protocol type: tcp, udp
  • @param port Host port number

func (*APIClient) DeleteSharedFolder

func (c *APIClient) DeleteSharedFolder(id string, folderId string) error

DeleteSharedFolder Deletes a shared folder

  • @param id ID of VM
  • @param folderId ID of shared folder

func (*APIClient) DeleteVM

func (c *APIClient) DeleteVM(id string) error

DeleteVM Deletes a VM

  • @param id ID of VM

func (*APIClient) GetAllNICDevices

func (c *APIClient) GetAllNICDevices(id string) (*model.NicDevices, error)

GetAllNICDevices Returns all network adapters in the VM

  • @param id ID of VM

@return NicDevices

func (*APIClient) GetAllNetworks

func (c *APIClient) GetAllNetworks() (*model.Networks, error)

GetAllNetworks Returns all virtual networks

@return Networks

func (*APIClient) GetAllSharedFolders

func (c *APIClient) GetAllSharedFolders(id string) (model.SharedFolders, error)

GetAllSharedFolders Returns all shared folders mounted in the VM

  • @param id ID of VM

@return SharedFolders

func (*APIClient) GetAllVMs

func (c *APIClient) GetAllVMs() ([]model.Vmid, error)

GetAllVMs Returns a list of VM IDs and paths for all VMs @return []Vmid

func (*APIClient) GetIPAddress

func (c *APIClient) GetIPAddress(id string) (*model.InlineResponse200, error)

GetIPAddress Returns the IP address of a VM

  • @param id ID of VM

@return InlineResponse200

func (*APIClient) GetMACToIPs

func (c *APIClient) GetMACToIPs(vmnet string) (*model.MactoIps, error)
	GetMACToIPs Returns all MAC-to-IP settings for DHCP service

 - @param vmnet Virtual network that has DHCP enabled

@return MactoIps

func (*APIClient) GetNicInfo

func (c *APIClient) GetNicInfo(id string) (*model.NicIpStackAll, error)

GetNicInfo Returns the IP stack configuration of all NICs of a VM

  • @param id ID of VM

@return NicIpStackAll

func (*APIClient) GetPortforwards

func (c *APIClient) GetPortforwards(vmnet string) (*model.Portforwards, error)

GetPortforwards Returns all port forwardings

  • @param vmnet NAT type of virtual network

@return Portforwards

func (*APIClient) GetPowerState

func (c *APIClient) GetPowerState(id string) (*model.VmPowerState, error)

GetPowerState Returns the power state of the VM

  • @param id ID of VM

@return VmPowerState

func (*APIClient) GetVM

func (c *APIClient) GetVM(id string) (*model.VmInformation, error)

GetVM Returns the VM setting information of a VM

  • @param id ID of VM

@return VmInformation

func (*APIClient) GetVMParams

func (c *APIClient) GetVMParams(id string, name string) (*model.ConfigVmParamsParameter, error)

GetVMParams Get the VM config params

  • @param id ID of VM
  • @param name Name of the param

@return ConfigVmParamsParameter

func (*APIClient) GetVMRestrictions

func (c *APIClient) GetVMRestrictions(id string) (*model.VmRestrictionsInformation, error)

GetVMRestrictions Returns the restrictions information of the VM

  • @param id ID of VM

@return VmRestrictionsInformation

func (*APIClient) RegisterVM

RegisterVM Register VM to VM Library

  • @param parameters Parameters of the VM to register

@return VmRegistrationInformation

func (*APIClient) UpdateMacToIP

func (c *APIClient) UpdateMacToIP(vmnet string, mac string, parameters *model.MacToIpParameter) (*model.ErrorModel, error)

UpdateMacToIP Updates the MAC-to-IP binding

  • @param vmnet Virtual network that enabled DHCP
  • @param mac Mac address that want to be mapped with a given IP
  • @param parameters IP that will be assigned to given Mac address. If empty IP, the original Mac to IP binding will be deleted

@return ErrorModel

func (*APIClient) UpdateNICDevice

func (c *APIClient) UpdateNICDevice(id string, index int, parameters *model.NicDeviceParameter) (*model.NicDevice, error)

UpdateNICDevice Updates a network adapter in the VM

  • @param id ID of VM
  • @param index Index of VM network adapter
  • @param parameters Parameters of network adapter to update to

@return NicDevice

func (*APIClient) UpdatePortforward

func (c *APIClient) UpdatePortforward(vmnet string, protocol string, port int, parameters *model.PortforwardParameter) (*model.ErrorModel, error)

UpdatePortforward Updates port forwarding

  • @param vmnet NAT type of virtual network
  • @param protocol Protocol type: tcp, udp
  • @param port Host port number
  • @param parameters Guest to forward to

@return ErrorModel

func (*APIClient) UpdateSharedFolder

func (c *APIClient) UpdateSharedFolder(id string, folderId string, parameters *model.SharedFolderParameter) (model.SharedFolders, error)

UpdateSharedFolder Updates a shared folder mounted in the VM

  • @param id ID of VM
  • @param folderId ID of VM shared folder
  • @param parameters Parameters of the shared folder to update to

@return SharedFolders

func (*APIClient) UpdateVM

func (c *APIClient) UpdateVM(id string, parameters *model.VmParameter) (*model.VmInformation, error)

UpdateVM Updates the VM settings

  • @param id ID of VM
  • @param parameters VM definition

@return VmInformation

type APIKey

type APIKey struct {
	Key    string
	Prefix string
}

APIKey provides API key based authentication to a request passed via context using ContextAPIKey

type APIResponse

type APIResponse struct {
	*http.Response `json:"-"`
	Message        string `json:"message,omitempty"`
	// Operation is the name of the swagger operation.
	Operation string `json:"operation,omitempty"`
	// RequestURL is the request URL. This value is always available, even if the
	// embedded *http.Response is nil.
	RequestURL string `json:"url,omitempty"`
	// Method is the HTTP method used for the request.  This value is always
	// available, even if the embedded *http.Response is nil.
	Method string `json:"method,omitempty"`
	// Payload holds the contents of the response body (which may be nil or empty).
	// This is provided here as the raw response.Body() reader will have already
	// been drained.
	Payload []byte `json:"-"`
}

func NewAPIResponse

func NewAPIResponse(r *http.Response) *APIResponse

func NewAPIResponseWithError

func NewAPIResponseWithError(errorMessage string) *APIResponse

type BasicAuth

type BasicAuth struct {
	UserName string `json:"userName,omitempty"`
	Password string `json:"password,omitempty"`
}

BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth

type Configuration

type Configuration struct {
	Endpoint    string        `json:"endpoint,omitempty"`
	UserAgent   string        `json:"userAgent,omitempty"`
	UserName    string        `json:"userName,omitempty"`
	Password    string        `json:"password,omitempty"`
	Timeout     time.Duration `json:"timeout,omitempty"`
	UnsecureTLS bool          `json:"unsecure-tls,omitempty"`
}

func NewConfiguration

func NewConfiguration(username, password string, port int) *Configuration

type GenericSwaggerError

type GenericSwaggerError struct {
	// contains filtered or unexported fields
}

GenericSwaggerError Provides access to the body, error and model on returned errors.

func (GenericSwaggerError) Body

func (e GenericSwaggerError) Body() []byte

Body returns the raw bytes of the response

func (GenericSwaggerError) Error

func (e GenericSwaggerError) Error() string

Error returns non-empty string if there was an error.

func (GenericSwaggerError) Model

func (e GenericSwaggerError) Model() interface{}

Model returns the unpacked model of the error

type Logger

type Logger interface {
	// LogRequest logs an HTTP request.
	LogRequest(*http.Request)

	// LogResponse logs an HTTP response.
	LogResponse(*http.Response)
}

Logger is the interface that should be implemented for loggers that wish to log HTTP requests and HTTP responses.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL