compute

package
v0.0.0-...-3c0cf66 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2016 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const APIPort = 8774

APIPort is the OpenStack compute port

Variables

View Source
var (
	ErrQuota                = errors.New("Tenant over quota")
	ErrTenantNotFound       = errors.New("Tenant not found")
	ErrServerNotFound       = errors.New("Server not found")
	ErrServerOwner          = errors.New("You are not server owner")
	ErrInstanceNotAvailable = errors.New("Instance not currently available for this operation")
)

These errors can be returned by the Service interface

Functions

func DumpRequest

func DumpRequest(r *http.Request)

DumpRequest will dump an http request if log level is 2

func Routes

func Routes(config APIConfig) *mux.Router

Routes returns a gorilla mux router for the compute endpoints.

Types

type APIConfig

type APIConfig struct {
	Port           int     // the https port of the compute api service
	ComputeService Service // the service interface
}

APIConfig contains information needed to start the compute api service.

type APIHandler

type APIHandler struct {
	*Context
	Handler func(*Context, http.ResponseWriter, *http.Request) (APIResponse, error)
}

APIHandler is a custom handler for the compute APIs. This custom handler allows us to more cleanly return an error and response, and pass some package level context into the handler.

func (APIHandler) ServeHTTP

func (h APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP satisfies the interface for the http Handler. If the individual handler returns an error, then it will marshal an error response.

type APIResponse

type APIResponse struct {
	Status   int
	Response interface{}
}

APIResponse is returned from all compute API functions. It contains the http status and response to be marshalled if needed.

func ListServersDetails

func ListServersDetails(c *Context, w http.ResponseWriter, r *http.Request) (APIResponse, error)

ListServersDetails provides server details by tenant or by flavor. This function is exported for use by ciao-controller due to legacy endpoint using the "flavor" option. It is simpler to just overload this function than to reimplement the legacy code.

@Title ListServerDetails @Description Lists all servers with details. @Accept json @Success 200 {array} ServerDetails "Returns details of all servers." @Failure 400 {object} HTTPReturnErrorCode "The response contains the corresponding message and 40x corresponding code." @Failure 500 {object} HTTPReturnErrorCode "The response contains the corresponding message and 50x corresponding code." @Router /v2.1/{tenant}/servers/detail [get] @Resource /v2.1/{tenant}/servers

type Addresses

type Addresses struct {
	Private []PrivateAddresses `json:"private"`
}

Addresses contains information about an instance's networks.

type Context

type Context struct {
	Service
	// contains filtered or unexported fields
}

Context contains information needed by the compute API service

type CreateServerRequest

type CreateServerRequest struct {
	Server struct {
		ID           string `json:"id"`
		Name         string `json:"name"`
		Image        string `json:"imageRef"`
		Flavor       string `json:"flavorRef"`
		MaxInstances int    `json:"max_count"`
		MinInstances int    `json:"min_count"`
	} `json:"server"`
}

CreateServerRequest represents the unmarshalled version of the contents of a /v2.1/{tenant}/servers request. It contains the information needed to start one or more instances.

type Flavor

type Flavor struct {
	Flavor FlavorDetails `json:"flavor"`
}

Flavor represents the unmarshalled version of the contents of a /v2.1/{tenant}/flavors/{flavor} response. It contains information about a specific flavour.

type FlavorDetails

type FlavorDetails struct {
	OSFLVDISABLEDDisabled  bool   `json:"OS-FLV-DISABLED:disabled"`
	Disk                   string `json:"disk"` /* OpenStack API says this is an int */
	OSFLVEXTDATAEphemeral  int    `json:"OS-FLV-EXT-DATA:ephemeral"`
	OsFlavorAccessIsPublic bool   `json:"os-flavor-access:is_public"`
	ID                     string `json:"id"`
	Links                  []Link `json:"links"`
	Name                   string `json:"name"`
	RAM                    int    `json:"ram"`
	Swap                   string `json:"swap"`
	Vcpus                  int    `json:"vcpus"`
}

FlavorDetails contains information about a specific flavor.

type FlavorLinks struct {
	ID    string `json:"id"`
	Links []Link `json:"links"`
}

FlavorLinks provides links to a specific flavor ID.

type Flavors

type Flavors struct {
	Flavors []struct {
		ID    string `json:"id"`
		Links []Link `json:"links"`
		Name  string `json:"name"`
	} `json:"flavors"`
}

Flavors represents the unmarshalled version of the contents of a /v2.1/{tenant}/flavors response. It contains information about all the flavors in a cluster.

func NewComputeFlavors

func NewComputeFlavors() (flavors Flavors)

NewComputeFlavors allocates a ComputeFlavors structure. It allocates the Flavors slice as well so that the marshalled JSON is an empty array and not a nil pointer, as specified by the OpenStack APIs.

type FlavorsDetails

type FlavorsDetails struct {
	Flavors []FlavorDetails `json:"flavors"`
}

FlavorsDetails represents the unmarshalled version of the contents of a /v2.1/{tenant}/flavors/detail response. It contains detailed information about all flavour for a given tenant.

func NewComputeFlavorsDetails

func NewComputeFlavorsDetails() (flavors FlavorsDetails)

NewComputeFlavorsDetails allocates a ComputeFlavorsDetails structure. It allocates the Flavors slice as well so that the marshalled JSON is an empty array and not a nil pointer, as specified by the OpenStack APIs.

type HTTPErrorData

type HTTPErrorData struct {
	Code    int    `json:"code"`
	Name    string `json:"name"`
	Message string `json:"message"`
}

HTTPErrorData represents the HTTP response body for a compute API request error.

type HTTPReturnErrorCode

type HTTPReturnErrorCode struct {
	Error HTTPErrorData `json:"error"`
}

HTTPReturnErrorCode represents the unmarshalled version for Return codes when a API call is made and you need to return explicit data of the call as OpenStack format http://developer.openstack.org/api-guide/compute/faults.html

type Image

type Image struct {
	ID    string `json:"id"`
	Links []Link `json:"links"`
}

Image identifies the base image of the instance.

type Link struct {
	Href string `json:"href"`
	Rel  string `json:"rel"`
}

Link contains the address to a compute resource, like e.g. a Flavor or an Image.

type PrivateAddresses

type PrivateAddresses struct {
	Addr               string `json:"addr"`
	OSEXTIPSMACMacAddr string `json:"OS-EXT-IPS-MAC:mac_addr"`
	OSEXTIPSType       string `json:"OS-EXT-IPS:type"`
	Version            int    `json:"version"`
}

PrivateAddresses contains information about a single instance network interface.

type SecurityGroup

type SecurityGroup struct {
	Name string `json:"name"`
}

SecurityGroup represents the security group of an instance.

type Server

type Server struct {
	Server ServerDetails `json:"server"`
}

Server represents the unmarshalled version of the contents of a /v2.1/{tenant}/servers/{server} response. It contains information about a specific instance within a ciao cluster.

type ServerDetails

type ServerDetails struct {
	Addresses                        Addresses       `json:"addresses"`
	Created                          time.Time       `json:"created"`
	Flavor                           FlavorLinks     `json:"flavor"`
	HostID                           string          `json:"hostId"`
	ID                               string          `json:"id"`
	Image                            Image           `json:"image"`
	KeyName                          string          `json:"key_name"`
	Links                            []Link          `json:"links"`
	Name                             string          `json:"name"`
	AccessIPv4                       string          `json:"accessIPv4"`
	AccessIPv6                       string          `json:"accessIPv6"`
	ConfigDrive                      string          `json:"config_drive"`
	OSDCFDiskConfig                  string          `json:"OS-DCF:diskConfig"`
	OSEXTAZAvailabilityZone          string          `json:"OS-EXT-AZ:availability_zone"`
	OSEXTSRVATTRHost                 string          `json:"OS-EXT-SRV-ATTR:host"`
	OSEXTSRVATTRHypervisorHostname   string          `json:"OS-EXT-SRV-ATTR:hypervisor_hostname"`
	OSEXTSRVATTRInstanceName         string          `json:"OS-EXT-SRV-ATTR:instance_name"`
	OSEXTSTSPowerState               int             `json:"OS-EXT-STS:power_state"`
	OSEXTSTSTaskState                string          `json:"OS-EXT-STS:task_state"`
	OSEXTSTSVMState                  string          `json:"OS-EXT-STS:vm_state"`
	OsExtendedVolumesVolumesAttached []string        `json:"os-extended-volumes:volumes_attached"`
	OSSRVUSGLaunchedAt               time.Time       `json:"OS-SRV-USG:launched_at"`
	OSSRVUSGTerminatedAt             time.Time       `json:"OS-SRV-USG:terminated_at"`
	Progress                         int             `json:"progress"`
	SecurityGroups                   []SecurityGroup `json:"security_groups"`
	Status                           string          `json:"status"`
	HostStatus                       string          `json:"host_status"`
	TenantID                         string          `json:"tenant_id"`
	Updated                          time.Time       `json:"updated"`
	UserID                           string          `json:"user_id"`
	SSHIP                            string          `json:"ssh_ip"`
	SSHPort                          int             `json:"ssh_port"`
}

ServerDetails contains information about a specific instance.

type Servers

type Servers struct {
	TotalServers int             `json:"total_servers"`
	Servers      []ServerDetails `json:"servers"`
}

Servers represents the unmarshalled version of the contents of a /v2.1/{tenant}/servers/detail response. It contains information about a set of instances within a ciao cluster. http://developer.openstack.org/api-ref-compute-v2.1.html#listServersDetailed BUG - TotalServers is not specified by the openstack api. We are going to pretend it is for now.

func NewServers

func NewServers() (servers Servers)

NewServers allocates a Servers structure. It allocates the Servers slice as well so that the marshalled JSON is an empty array and not a nil pointer for, as specified by the OpenStack APIs.

type Service

type Service interface {
	// server interfaces
	CreateServer(string, CreateServerRequest) (interface{}, error)
	ListServersDetail(tenant string) ([]ServerDetails, error)
	ShowServerDetails(tenant string, server string) (Server, error)
	DeleteServer(tenant string, server string) error
	StartServer(tenant string, server string) error
	StopServer(tenant string, server string) error

	//flavor interfaces
	ListFlavors(string) (Flavors, error)
	ListFlavorsDetail(string) (FlavorsDetails, error)
	ShowFlavorDetails(string, string) (Flavor, error)
}

Service defines the interface required by the compute service.

Jump to

Keyboard shortcuts

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