api

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RunStateStart = "running"
	RunStateStop  = "stopped"
	RunStatePause = "suspended"
	RunStateKill  = "halted"
	RunStateBusy  = "busy"
	RunStateReset = "reset"
)
View Source
const (
	NetworkPath          = "networks"
	InterfacePath        = "interfaces"
	VpnPath              = "vpns"
	PublishedServicePath = "services"
)
View Source
const (
	AcceptHeaderV2 = "application/vnd.skytap.api.v2+json"
	AcceptHeaderV1 = "application/json"
	BaseUriV1      = "https://cloud.skytap.com"
	BaseUriV2      = "https://cloud.skytap.com/v2"
	MetadataUri    = "http://gw/skytap"
	UserAgent      = "skytap-sdk-go"
)
View Source
const (
	EnvironmentPath = "configurations"
)
View Source
const (
	TemplatePath = "templates"
)
View Source
const (
	VmPath = "vms"
)

Variables

This section is empty.

Functions

func DeleteEnvironment

func DeleteEnvironment(client SkytapClient, envId string) error

Delete an environment by id.

func DeleteNetwork added in v1.0.0

func DeleteNetwork(client SkytapClient, envId string, netId string) error

DeleteNetwork - delete a network from an environment

func DeleteVirtualMachine

func DeleteVirtualMachine(client SkytapClient, vmId string) error

Delete a VM.

func GetSkytapResource

func GetSkytapResource(client SkytapClient, url string, respObj interface{}) (*http.Response, error)

Return a skytap resource specified as complete GET based URL.

func IsRunningInSkytap added in v0.2.0

func IsRunningInSkytap() bool

func RunSkytapRequest

func RunSkytapRequest(client SkytapClient, useV2 bool, respJson interface{}, slingDecorator SlingDecorator) (*http.Response, error)

Runs an initial skytap API request attempt, with retries.

Returns the resulting response, or error. If no error occurs, the response json will be present in respJson.

useV2 - If true the request should use V2 API path. respJson - Interface to fill with response JSON. slingDecorator - Decorate request with specifics, set request path relative to root, add body, etc.

Types

type AttachVpnBody

type AttachVpnBody struct {
	VpnId string `json:"vpn_id"`
}

Request body for VPN attach commands.

type AttachVpnResult

type AttachVpnResult struct {
	Id        string           `json:"id"`
	Connected bool             `json:"connected"`
	Network   NetworkInterface `json:"network"`
	Vpn       interface{}      `json:"vpn"`
}

Response body for VPN attach commands.

type ConnectVpnBody

type ConnectVpnBody struct {
	Connected bool `json:"connected"`
}

Request body for VPN connect commands.

type ContainerHostQuery added in v0.3.0

type ContainerHostQuery struct {
	ContainerHost bool `url:"container_host"`
}

type CopyEnvironmentBody

type CopyEnvironmentBody struct {
	EnvironmentId string   `json:"configuration_id"`
	VmIds         []string `json:"vm_ids"`
}

Request body for copy environment commands.

type CreateEnvironmentBody

type CreateEnvironmentBody struct {
	TemplateId string `json:"template_id"`
}

Request body for create commands.

type Disk added in v1.0.0

type Disk struct {
	Id         string `json:"id"`
	Size       *int   `json:"size"`
	Type       string `json:"type"`
	Controller string `json:"controller"`
	Lun        string `json:"lun"`
}

type Environment

type Environment struct {
	Id          string            `json:"id,omitempty"`
	Url         string            `json:"url,omitempty"`
	Name        string            `json:"name,omitempty"`
	Description string            `json:"description,omitempty"`
	Error       []string          `json:"errors,omitempty"`
	Runstate    string            `json:"runstate,omitempty"`
	Vms         []*VirtualMachine `json:"vms,omitempty"`
	Networks    []Network         `json:"networks,omitempty"`
}

* Skytap Environment resource.

func CopyEnvironmentWithVms

func CopyEnvironmentWithVms(client SkytapClient, sourceEnvId string, vmIds []string) (*Environment, error)

Create a new environment from a source environment, including only specific VMs, which must be a part of the template.

func CreateNewEnvironment

func CreateNewEnvironment(client SkytapClient, templateId string) (*Environment, error)

Create a new environment from a template.

func CreateNewEnvironmentWithVms

func CreateNewEnvironmentWithVms(client SkytapClient, templateId string, vmIds []string) (*Environment, error)

Create a new environment from a source template, including only specific VMs, which must be a part of the template.

func GetEnvironment

func GetEnvironment(client SkytapClient, envId string) (*Environment, error)

Return an existing environment by id.

func RenameEnvironment added in v1.0.0

func RenameEnvironment(client SkytapClient, envId string, name string, restartEnv bool) (*Environment, error)

func (*Environment) AddVirtualMachine

func (e *Environment) AddVirtualMachine(client SkytapClient, vmId string) (*Environment, error)

Adds a VM to an existing environment.

func (*Environment) ChangeRunstate

func (e *Environment) ChangeRunstate(client SkytapClient, runstate string, desiredRunstate string) (*Environment, error)

Changes the runstate of the Environment to the specified state and waits until the Environment is in the desired state.

func (*Environment) MergeEnvironmentVirtualMachine

func (e *Environment) MergeEnvironmentVirtualMachine(client SkytapClient, envId string, vmId string) (*Environment, error)

Merge an environment based VM into this environment (the VM must be in an existing environment).

func (*Environment) MergeTemplateVirtualMachine

func (e *Environment) MergeTemplateVirtualMachine(client SkytapClient, templateId string, vmId string) (*Environment, error)

Merge a template based VM into this environment (the VM must be in an existing template).

func (*Environment) MergeVirtualMachine

func (e *Environment) MergeVirtualMachine(client SkytapClient, mergeBody interface{}) (*Environment, error)

Merge arbitrary VM into this environment.

mergeBody - The correct representation of the request body, see the MergeEnvironmentVirtualMachine and MergeTemplateVirtualMachine methods.

func (*Environment) Refresh

func (e *Environment) Refresh(client SkytapClient) (RunstateAwareResource, error)

func (*Environment) RunstateStr

func (e *Environment) RunstateStr() string

func (*Environment) Start

func (e *Environment) Start(client SkytapClient) (*Environment, error)

Starts an environment.

func (*Environment) Suspend

func (e *Environment) Suspend(client SkytapClient) (*Environment, error)

Suspends an environment.

func (*Environment) WaitUntilInState

func (e *Environment) WaitUntilInState(client SkytapClient, desiredStates []string, requireStateChange bool) (*Environment, error)

func (*Environment) WaitUntilReady

func (e *Environment) WaitUntilReady(client SkytapClient) (*Environment, error)

type Hardware

type Hardware struct {
	Cpus          *int   `json:"cpus,omitempty"`
	CpusPerSocket *int   `json:"cpus_per_socket,omitempty"`
	Ram           *int   `json:"ram,omitempty"`
	Disks         []Disk `json:"disks,omitempty"`
}

type HardwareUpdate

type HardwareUpdate struct {
	Hardware Hardware `json:"hardware"`
}

type MergeEnvironmentBody

type MergeEnvironmentBody struct {
	EnvironmentId string   `json:"merge_configuration"`
	VmIds         []string `json:"vm_ids"`
}

Request body for merge commands.

type MergeTemplateBody

type MergeTemplateBody struct {
	TemplateId string   `json:"template_id"`
	VmIds      []string `json:"vm_ids"`
}

Request body for merge commands.

type NameQuery

type NameQuery struct {
	Name string `url:"name"`
}

type NameUpdate

type NameUpdate struct {
	Hostname string `json:"hostname"`
}

type NatAddresses

type NatAddresses struct {
	VpnNatAddresses     []VpnNatAddress     `json:"vpn_nat_addresses,omitempty"`
	NetworkNatAddresses []NetworkNatAddress `json:"network_nat_addresses,omitempty	"`
}

Nat addresses stored inside network interface.

type Network

type Network struct {
	Id                  string          `json:"id"`
	Url                 string          `json:"url"`
	Name                string          `json:"name"`
	Subnet              string          `json:"subnet"`
	Domain              string          `json:"domain"`
	Gateway             string          `json:"gateway"`
	NetworkType         string          `json:"network_type"`
	Tunnelable          bool            `json:"tunnelable"`
	Tunnels             interface{}     `json:"tunnels"`
	PrimaryNameserver   string          `json:"primary_nameserver"`
	SecondaryNameserver string          `json:"secondary_nameserver"`
	Region              string          `json:"region"`
	NatSubnet           string          `json:"nat_subnet"`
	NatPoolSize         int             `json:"nat_pool_size"`
	NatPoolRemaining    int             `json:"nat_pool_remaining"`
	VpnAttachments      []VpnAttachment `json:"vpn_attachments"`
}

Network resource.

func CreateAutomaticNetwork added in v1.0.0

func CreateAutomaticNetwork(
	client SkytapClient,
	envId string,
	name string,
	subnet string,
	domain string) (*Network, error)

CreateAutomaticNetwork - create a new network in an Environment

func CreateManualNetwork added in v1.0.0

func CreateManualNetwork(
	client SkytapClient,
	envId string,
	name string,
	subnet string,
	gateway string) (*Network, error)

func (*Network) AttachToVpn

func (n *Network) AttachToVpn(client SkytapClient, envId string, vpnId string) (*AttachVpnResult, error)

Attach a network to a VPN, in the context of the given environment.

func (*Network) ChangeConnectionToVpn

func (n *Network) ChangeConnectionToVpn(client SkytapClient, envId string, vpnId string, connected bool) error

General method for manipulating VPN connection state.

func (*Network) ConnectToVpn

func (n *Network) ConnectToVpn(client SkytapClient, envId string, vpnId string) error

Connect to a given VPN in the context of a given environment.

func (*Network) DetachFromVpn

func (n *Network) DetachFromVpn(client SkytapClient, envId string, vpnId string) error

Detach a network from a VPN in the context of the given environment.

func (*Network) DisconnectFromVpn

func (n *Network) DisconnectFromVpn(client SkytapClient, envId string, vpnId string) error

Disconnect an environment's network from a VPN.

type NetworkInterface

type NetworkInterface struct {
	Id                string             `json:"id,omitempty"`
	Ip                string             `json:"ip,omitempty"`
	PublicIpsCount    int                `json:"public_ips_count,omitempty"`
	Hostname          string             `json:"hostname,omitempty"`
	PublicIps         []PublicIp         `json:"public_ips,omitempty"`
	NatAddresses      *NatAddresses      `json:"nat_addresses,omitempty"`
	Status            string             `json:"status,omitempty"`
	ExternalAddress   string             `json:"external_address,omitempty"`
	NicType           string             `json:"nic_type,omitempty"`
	NetworkId         string             `json:"network_id,omitempty"`
	PublishedServices []PublishedService `json:"services,omitempty"`
}

Network interface inside a VM.

func (*NetworkInterface) AddPublishedService added in v1.0.0

func (nic *NetworkInterface) AddPublishedService(client SkytapClient, port int, envId, vmId string) (*NetworkInterface, error)

type NetworkNatAddress

type NetworkNatAddress struct {
	IpAddress        string `json:"ip_address"`
	NetworkId        string `json:"network_id"`
	NetworkName      string `json:"network_name"`
	NetworkUrl       string `json:"network_url"`
	ConfigurationId  string `json:"configuration_id"`
	ConfigurationUrl string `json:"configuration_url"`
}

Network based NAT address.

type PublicIp

type PublicIp struct {
	Id      string      `json:"id"`
	Address string      `json:"address"`
	Region  string      `json:"region"`
	Nics    interface{} `json:"nics"`
	VpnId   string      `json:"vpn_id"`
}

IP type.

type PublishedService added in v1.0.0

type PublishedService struct {
	Id           string `json:"id,omitempty"`
	InternalPort int    `json:"internal_port,omitempty"`
	ExternalIp   string `json:"external_ip,omitempty"`
	ExternalPort int    `json:"external_port,omitempty"`
}

type RunstateAwareResource

type RunstateAwareResource interface {
	//
	RunstateStr() string
	// Should fetch a fresh representation of the resource and return the current runstate, or error
	Refresh(client SkytapClient) (RunstateAwareResource, error)
}

A runstate aware resource has a runstate in its representation, which can be used when waiting for a specific state.

func WaitUntilInState

func WaitUntilInState(client SkytapClient, desiredStates []string, r RunstateAwareResource, requireStateChange bool) (RunstateAwareResource, error)

Wait until the given resource is in one of the desired states.

If the resource reaches the desired state, a recently fetched representation is returned. Otherwise an error is returned, along with the result of the last attempt.

If requireStateChange is set, a transition must occur. The function will wait until the state changes or timeout.

type RunstateBody

type RunstateBody struct {
	Runstate string `json:"runstate"`
}

Some skytap resources have a runstate in response, use this for monitoring.

type SkytapApiError

type SkytapApiError struct {
	Error string `json:error`
}

General skytap json error response.

type SkytapClient

type SkytapClient struct {
	HttpClient  *http.Client
	Credentials SkytapCredentials
}

Skytap client object, needed for all REST calls.

func NewSkytapClient

func NewSkytapClient(username string, apiKey string) *SkytapClient

Create a new client from username and key.

func NewSkytapClientFromCredentials

func NewSkytapClientFromCredentials(credentials SkytapCredentials) *SkytapClient

Create a new client from credentials

type SkytapCredentials

type SkytapCredentials struct {
	Username string
	ApiKey   string
}

Credentials for accessing skytap REST API.

type SkytapMetadata added in v0.2.0

type SkytapMetadata struct {
	Id string `json:"id"`
}

Skytap metadata service response.

type SlingDecorator

type SlingDecorator func(*sling.Sling) *sling.Sling

Request methods use this to create/customize the requests.

type Template

type Template struct {
	Id     string `json:"id"`
	Url    string `json:"url"`
	Name   string `json:"name"`
	Region string `json:"region"`
}

Skytap template resource.

type VirtualMachine

type VirtualMachine struct {
	Id             string              `json:"id,omitempty"`
	Name           string              `json:"name,omitempty" url:"name"`
	Runstate       string              `json:"runstate,omitempty"`
	Error          interface{}         `json:"error,omitempty"`
	TemplateUrl    string              `json:"template_url,omitempty"`
	EnvironmentUrl string              `json:"configuration_url,omitempty"`
	Interfaces     []*NetworkInterface `json:"interfaces,omitempty"`
	Hardware       Hardware            `json:"hardware,omitempty"`
	CreatedAt      string              `json:"created_at,omitempty"`
}

Skytap VM resource.

func GetVirtualMachine

func GetVirtualMachine(client SkytapClient, vmId string) (*VirtualMachine, error)

Get a VM without reference to environment or template. The result object should contain information on its source.

func GetVirtualMachineInEnvironment

func GetVirtualMachineInEnvironment(client SkytapClient, envId string, vmId string) (*VirtualMachine, error)
Get a VM from an existing environment.

TODO see if we can trap the JSON unmarshall error

func GetVirtualMachineInTemplate

func GetVirtualMachineInTemplate(client SkytapClient, templateId string, vmId string) (*VirtualMachine, error)

Get a VM from an existing template.

func (*VirtualMachine) AddDisk added in v1.0.0

func (vm *VirtualMachine) AddDisk(client SkytapClient, envId string, diskSize int, restartVm bool) (*VirtualMachine, error)

Add a Disk of a specified size to VM

func (*VirtualMachine) AddNetworkInterface added in v1.0.0

func (vm *VirtualMachine) AddNetworkInterface(client SkytapClient, envId, ip, host, nic_type string, restartVm bool) (*NetworkInterface, error)

Add a network interface to VM

func (*VirtualMachine) ChangeAttribute

func (vm *VirtualMachine) ChangeAttribute(client SkytapClient, queryStruct interface{}) (*VirtualMachine, error)

func (*VirtualMachine) ChangeRunstate

func (vm *VirtualMachine) ChangeRunstate(client SkytapClient, runstate string, desiredRunstates ...string) (*VirtualMachine, error)

Changes the runstate of the VM to the specified state and waits until the VM is in the desired state.

func (*VirtualMachine) GetCredentials

func (vm *VirtualMachine) GetCredentials(client SkytapClient) ([]VmCredential, error)

func (*VirtualMachine) GetEnvironment

func (vm *VirtualMachine) GetEnvironment(client SkytapClient) (*Environment, error)

If a VM is in an environment, returns the environment, otherwise nil.

func (*VirtualMachine) GetTemplate

func (vm *VirtualMachine) GetTemplate(client SkytapClient) (*Template, error)

If VM is in a template, returns the template, otherwise nil.

func (*VirtualMachine) Kill

func (vm *VirtualMachine) Kill(client SkytapClient) (*VirtualMachine, error)

Kills a VM forcefully.

func (*VirtualMachine) Refresh

func (vm *VirtualMachine) Refresh(client SkytapClient) (RunstateAwareResource, error)

Fetch fresh representation.

func (*VirtualMachine) RemoveNetworkInterface added in v1.0.0

func (vm *VirtualMachine) RemoveNetworkInterface(client SkytapClient, envId, interfaceId string) error

Remove network interface from VM

func (*VirtualMachine) RenameNetworkInterface

func (vm *VirtualMachine) RenameNetworkInterface(client SkytapClient, envId string, interfaceId string, name string) (*NetworkInterface, error)

Rename network interface on VM

func (*VirtualMachine) ResizeDisk added in v1.0.0

func (vm *VirtualMachine) ResizeDisk(client SkytapClient, envId string, diskId string, diskSize int, restartVm bool) (*VirtualMachine, error)

Resize Disk with specified ID

func (*VirtualMachine) RunstateStr

func (vm *VirtualMachine) RunstateStr() string

func (*VirtualMachine) SetContainerHost added in v0.3.0

func (vm *VirtualMachine) SetContainerHost(client SkytapClient) (*VirtualMachine, error)

func (*VirtualMachine) SetName

func (vm *VirtualMachine) SetName(client SkytapClient, name string) (*VirtualMachine, error)

func (*VirtualMachine) Start

func (vm *VirtualMachine) Start(client SkytapClient) (*VirtualMachine, error)

Starts a VM.

func (*VirtualMachine) Stop

func (vm *VirtualMachine) Stop(client SkytapClient) (*VirtualMachine, error)

Stops a VM. Note that some VMs may require user input and cannot be stopped with the method.

func (*VirtualMachine) Suspend

func (vm *VirtualMachine) Suspend(client SkytapClient) (*VirtualMachine, error)

Suspends a VM.

func (*VirtualMachine) UpdateHardware

func (vm *VirtualMachine) UpdateHardware(client SkytapClient, hardware Hardware, restartVm bool) (*VirtualMachine, error)

func (*VirtualMachine) UpdateNetworkInterface added in v1.0.0

func (vm *VirtualMachine) UpdateNetworkInterface(client SkytapClient, network_interface *NetworkInterface, envId, interfaceId string) error

Update network interface on VM

func (*VirtualMachine) WaitUntilInState

func (vm *VirtualMachine) WaitUntilInState(client SkytapClient, desiredStates []string, requireStateChange bool) (*VirtualMachine, error)

Wait until the VM is in one of the desired states.

func (*VirtualMachine) WaitUntilReady

func (vm *VirtualMachine) WaitUntilReady(client SkytapClient) (*VirtualMachine, error)

Waits until VM is either stopped or started.

type VmCredential

type VmCredential struct {
	Id   string `json:"id"`
	Text string `json:"text"`
}

func (*VmCredential) Password

func (c *VmCredential) Password() (string, error)

func (*VmCredential) Username

func (c *VmCredential) Username() (string, error)

type Vpn

type Vpn struct {
	Id            string `json:"id"`
	Name          string `json:"name"`
	Enabled       bool   `json:"enabled"`
	NatEnabled    bool   `json:"nat_enabled"`
	RemoteSubnets string `json:"remote_subnets"`
	RemotePeerIp  string `json:"remote_subnets"`
	CanReconnect  bool   `json:"can_reconnect"`
}

func GetVpn added in v0.2.0

func GetVpn(client SkytapClient, vpnId string) (*Vpn, error)

Return an existing VPN by id.

type VpnAttachment

type VpnAttachment struct {
	Id        string `json:"id"`
	Connected bool   `json:"connected"`
	Vpn       Vpn    `json:"vpn"`
}

VPN attachments to network.

type VpnNatAddress

type VpnNatAddress struct {
	IpAddress string `json:"ip_address"`
	VpnId     string `json:"vpn_id"`
	VpnName   string `json:"vpn_name"`
	VpnUrl    string `json:"vpn_url"`
}

VPN based NAT address.

Jump to

Keyboard shortcuts

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