Documentation ¶
Index ¶
- Constants
- Variables
- type ImageMetadata
- type VM
- func (vm *VM) Destroy() error
- func (vm *VM) GetIPs() ([]net.IP, error)
- func (vm *VM) GetName() string
- func (vm *VM) GetSSH(options ssh.Options) (ssh.Client, error)
- func (vm *VM) GetState() (string, error)
- func (vm *VM) Halt() error
- func (vm *VM) Provision() error
- func (vm *VM) Resume() error
- func (vm *VM) Start() error
- func (vm *VM) Suspend() error
- type Volume
Constants ¶
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 = 300 // ImageUploadTimeout is the maximum seconds to wait before failing to // upload an image. ImageUploadTimeout = 300 // VolumeActionTimeout is the maximum seconds to wait before failing to // do an action (create, delete) on the volume. VolumeActionTimeout = 300 // SSHTimeout is the maximum seconds to wait before failing to // GetSSH. SSHTimeout = 300 // 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 ¶
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") )
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 // 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) Destroy ¶
Destroy terminates the VM on Openstack. It returns an error if there is no instance ID.
func (*VM) GetIPs ¶
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) GetSSH ¶
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 ¶
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) Provision ¶
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.
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