openstack

package
v0.0.0-...-492d7f2 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2018 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PublicIP is the index of the public IP address that GetIPs returns.
	PublicIP = 0
	// PrivateIP is the index of the private IP address that GetIPs returns.
	PrivateIP = 1

	// ActionTimeout is the maximum seconds to wait before failing to
	// any action on VM, such as Provision, Halt or Destroy.
	ActionTimeout = 900
	// ImageUploadTimeout is the maximum seconds to wait before failing to
	// upload an image.
	ImageUploadTimeout = 900
	// VolumeActionTimeout is the maximum seconds to wait before failing to
	// do an action (create, delete) on the volume.
	VolumeActionTimeout = 900

	// StateActive is the state Openstack reports when the VM is started.
	StateActive = "ACTIVE"
	// StateShutOff is the state Openstack reports when the VM is stopped.
	StateShutOff = "SHUTOFF"
	// StateError is the state Openstack reports when the given action fails on VM.
	StateError = "ERROR"
)

Variables

View Source
var (
	// ErrAuthOptions is returned if the credentials are not set properly as a environment variable
	ErrAuthOptions = errors.New("Openstack credentials (username and password) are not set properly")
	// ErrAuthenticatingClient is returned if the openstack do not return any provider.
	ErrAuthenticatingClient = errors.New("Failed to authenticate the client")
	// ErrInvalidRegion is returned if the region is an invalid.
	ErrInvalidRegion = errors.New("Invalid Openstack region")
	// ErrNoRegion is returned if the region is missing.
	ErrNoRegion = errors.New("Missing Openstack region")
	// ErrNoFlavor is returned querying an flavor, but none is found.
	ErrNoFlavor = errors.New("Requested flavor is not found")
	// ErrNoImage is returned querying an image, but none is found.
	ErrNoImage = errors.New("Requested image is not found")
	// ErrCreatingInstance is returned if a new server/instance is not created successfully.
	ErrCreatingInstance = errors.New("Failed to create instance")
	// ErrNoInstanceID is returned when attempting to perform an operation on an instance, but the ID is missing.
	ErrNoInstanceID = errors.New("Missing instance ID")
	// ErrNoInstance is returned querying an instance, but none is found.
	ErrNoInstance = errors.New("No instance found")
	// ErrActionTimeout is returned when the Openstack instance takes too long to enter waited state.
	ErrActionTimeout = errors.New("Openstack action timeout")
	// ErrNoIPs is returned when no IP addresses are found for an instance.
	ErrNoIPs = errors.New("No IPs found for instance")
)
View Source
var SSHTimeout = 900 * time.Second

SSHTimeout is the maximum time to wait before failing to GetSSH. This is not thread-safe.

Functions

This section is empty.

Types

type ImageMetadata

type ImageMetadata struct {
	// Container Format for the Image, Required
	ContainerFormat string `json:"container_format,omitempty"`
	// Disk Format of the Image, Required
	DiskFormat string `json:"disk_format,omitempty"`
	// Min. amount of disk (GB) required for the image, Optional
	MinDisk int `json:"min_disk,omitempty"`
	// Min. amount of disk (GB) required for the image, Optional
	MinRAM int `json:"min_ram,omitempty"`
	// Name of the image
	Name string `json:"name"`
}

ImageMetadata represents what kind of Image will be loaded to the VM

func NewDefaultImageMetadata

func NewDefaultImageMetadata() ImageMetadata

NewDefaultImageMetadata creates a ImageMetadata with default values

type VM

type VM struct {
	// IdentityEndpoint represents the Openstack Endpoint to use for creating this VM.
	IdentityEndpoint string
	// Username represents the username to use for connecting to the sdk.
	Username string
	// Password represents the password to use for connecting to the sdk.
	Password string
	// Region represents the Openstack region that this VM belongs to.
	Region string
	// TenantName represents the Openstack tenant name that this VM belnogs to
	TenantName string

	// FlavorName represents the flavor that will be used by th VM.
	FlavorName string

	// ImageID represents the image that will be used (or being used) by the VM
	ImageID string
	// Metadata contains the necessary image upload information (metadata and path)
	// about the image that will be uploaded by the VM to the Openstack.
	ImageMetadata ImageMetadata
	// ImagePath is the path that Image will be read from
	ImagePath string

	// Volume represents the volume that will be attached to this VM on provision.
	Volume Volume

	// UUID of this instance (server). Set after provisioning
	InstanceID string // optional
	// Instance Name of the VM (optional)
	Name string

	// List of network UUIDs that this VM will be attached to
	Networks []string

	// Pool to choose a floating IP for this VM, it is required to assign an external IP
	// to the VM.
	FloatingIPPool string
	// FloatingIP is the object that stores the necessary floating ip information for this VM
	FloatingIP *floatingip.FloatingIP

	// SecurityGroup represents the name of the security group to which this VM should belong
	SecurityGroup string

	// UserData [optional] contains configuration information or scripts to use upon launch,
	// known as cloud-init scripts.
	UserData []byte

	// AdminPassword [optional] sets the root user password. If not set, a randomly-generated password
	// will be created by OpenStack API.
	AdminPassword string

	// Credentials are the credentials to use when connecting to the VM over SSH
	Credentials ssh.Credentials
	// contains filtered or unexported fields
}

VM represents an Openstack EC2 virtual machine.

func (*VM) AddDisk

func (vm *VM) AddDisk() error

func (*VM) Destroy

func (vm *VM) Destroy() error

Destroy terminates the VM on Openstack. It returns an error if there is no instance ID.

func (*VM) GetIPs

func (vm *VM) GetIPs() ([]net.IP, error)

GetIPs returns a slice of IP addresses assigned to the VM. The PublicIP or PrivateIP consts can be used to retrieve respective IP address type. It returns nil if there was an error obtaining the IPs.

func (*VM) GetName

func (vm *VM) GetName() string

GetName returns the name of the virtual machine

func (*VM) GetSSH

func (vm *VM) GetSSH(options ssh.Options) (ssh.Client, error)

GetSSH returns an SSH client that can be used to connect to a VM. An error is returned if the VM has no IPs.

func (*VM) GetState

func (vm *VM) GetState() (string, error)

GetState returns the state of the VM, such as "ACTIVE". An error is returned if the instance ID is missing, if there was a problem querying Openstack, or if there are no instances.

func (*VM) Halt

func (vm *VM) Halt() error

Halt shuts down the insance on Openstack.

func (*VM) Provision

func (vm *VM) Provision() error

Provision creates a virtual machine on Openstack. It returns an error if there was a problem during creation, if there was a problem adding a tag, or if the VM takes too long to enter "running" state.

func (*VM) RemoveDisk

func (vm *VM) RemoveDisk(diskName string) error

func (*VM) Resume

func (vm *VM) Resume() error

Resume always returns an error since we do not support for Openstack for now. TODO Remove this error message, when resume is supported by libretto in the future.

func (*VM) Start

func (vm *VM) Start() error

Start boots a stopped VM.

func (*VM) Suspend

func (vm *VM) Suspend() error

Suspend always returns an error since we do not support for Openstack for now. TODO Remove this error message, when suspend is supported by libretto in the future.

type Volume

type Volume struct {
	// ID represents the ID of the volume that attached to this VM
	ID string
	// Device is the device that the volume will attach to the instance as. Omit for "auto"
	Device string
	// Name represents the name of the volume that will be attached to this VM
	Name string
	// Size represents the size of the volume that will be attached to this VM
	Size int
	// Type represents the ID of the volume type that will be attached to this VM
	Type string
}

Volume represents an Openstack disk volume

func NewDefaultVolume

func NewDefaultVolume() Volume

NewDefaultVolume creates a Volume with default values

Jump to

Keyboard shortcuts

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