flavors

package
v0.0.0-...-8db8df1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2017 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package flavors provides information and interaction with the flavor API in the OpenStack Compute service.

A flavor is an available hardware configuration for a server. Each flavor has a unique combination of disk space, memory capacity and priority for CPU time.

Example to List Flavors

listOpts := flavors.ListOpts{
	AccessType: flavors.PublicAccess,
}

allPages, err := flavors.ListDetail(computeClient, listOpts).AllPages()
if err != nil {
	panic(err)
}

allFlavors, err := flavors.ExtractFlavors(allPages)
if err != nil {
	panic(err)
}

for _, flavor := range allFlavors {
	fmt.Printf("%+v\n", flavor)
}

Example to Create a Flavor

createOpts := flavors.CreateOpts{
	ID:         "1",
	Name:       "m1.tiny",
	Disk:       gophercloud.IntToPointer(1),
	RAM:        512,
	VCPUs:      1,
	RxTxFactor: 1.0,
}

flavor, err := flavors.Create(computeClient, createOpts).Extract()
if err != nil {
	panic(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IDFromName

func IDFromName(client *gophercloud.ServiceClient, name string) (string, error)

IDFromName is a convienience function that returns a flavor's ID given its name.

func ListDetail

func ListDetail(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager

ListDetail instructs OpenStack to provide a list of flavors. You may provide criteria by which List curtails its results for easier processing.

Types

type AccessType

type AccessType string

AccessType maps to OpenStack's Flavor.is_public field. Although the is_public field is boolean, the request options are ternary, which is why AccessType is a string. The following values are allowed:

The AccessType arguement is optional, and if it is not supplied, OpenStack returns the PublicAccess flavors.

const (
	// PublicAccess returns public flavors and private flavors associated with
	// that project.
	PublicAccess AccessType = "true"

	// PrivateAccess (admin only) returns private flavors, across all projects.
	PrivateAccess AccessType = "false"

	// AllAccess (admin only) returns public and private flavors across all
	// projects.
	AllAccess AccessType = "None"
)

type CreateOpts

type CreateOpts struct {
	// Name is the name of the flavor.
	Name string `json:"name" required:"true"`

	// RAM is the memory of the flavor, measured in MB.
	RAM int `json:"ram" required:"true"`

	// VCPUs is the number of vcpus for the flavor.
	VCPUs int `json:"vcpus" required:"true"`

	// Disk the amount of root disk space, measured in GB.
	Disk *int `json:"disk" required:"true"`

	// ID is a unique ID for the flavor.
	ID string `json:"id,omitempty"`

	// Swap is the amount of swap space for the flavor, measured in MB.
	Swap *int `json:"swap,omitempty"`

	// RxTxFactor alters the network bandwidth of a flavor.
	RxTxFactor float64 `json:"rxtx_factor,omitempty"`

	// IsPublic flags a flavor as being available to all projects or not.
	IsPublic *bool `json:"os-flavor-access:is_public,omitempty"`

	// Ephemeral is the amount of ephemeral disk space, measured in GB.
	Ephemeral *int `json:"OS-FLV-EXT-DATA:ephemeral,omitempty"`
}

CreateOpts specifies parameters used for creating a flavor.

func (CreateOpts) ToFlavorCreateMap

func (opts CreateOpts) ToFlavorCreateMap() (map[string]interface{}, error)

ToFlavorCreateMap constructs a request body from CreateOpts.

type CreateOptsBuilder

type CreateOptsBuilder interface {
	ToFlavorCreateMap() (map[string]interface{}, error)
}

type CreateResult

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

func Create

func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult)

Create requests the creation of a new flavor.

func (CreateResult) Extract

func (r CreateResult) Extract() (*Flavor, error)

Extract provides access to the individual Flavor returned by the Get and Create functions.

type DeleteResult

type DeleteResult struct {
	gophercloud.ErrResult
}

DeleteResult is the result from a Delete operation. Call its ExtractErr method to determine if the call succeeded or failed.

func Delete

func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult)

Delete deletes the specified flavor ID.

type Flavor

type Flavor struct {
	// ID is the flavor's unique ID.
	ID string `json:"id"`

	// Disk is the amount of root disk, measured in GB.
	Disk int `json:"disk"`

	// RAM is the amount of memory, measured in MB.
	RAM int `json:"ram"`

	// Name is the name of the flavor.
	Name string `json:"name"`

	// RxTxFactor describes bandwidth alterations of the flavor.
	RxTxFactor float64 `json:"rxtx_factor"`

	// Swap is the amount of swap space, measured in MB.
	Swap int `json:"swap"`

	// VCPUs indicates how many (virtual) CPUs are available for this flavor.
	VCPUs int `json:"vcpus"`

	// IsPublic indicates whether the flavor is public.
	IsPublic bool `json:"is_public"`
}

Flavor represent (virtual) hardware configurations for server resources in a region.

func ExtractFlavors

func ExtractFlavors(r pagination.Page) ([]Flavor, error)

ExtractFlavors provides access to the list of flavors in a page acquired from the ListDetail operation.

func (*Flavor) UnmarshalJSON

func (r *Flavor) UnmarshalJSON(b []byte) error

type FlavorPage

type FlavorPage struct {
	pagination.LinkedPageBase
}

FlavorPage contains a single page of all flavors from a ListDetails call.

func (FlavorPage) IsEmpty

func (page FlavorPage) IsEmpty() (bool, error)

IsEmpty determines if a FlavorPage contains any results.

func (FlavorPage) NextPageURL

func (page FlavorPage) NextPageURL() (string, error)

NextPageURL uses the response's embedded link reference to navigate to the next page of results.

type GetResult

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

GetResult is the response of a Get operations. Call its Extract method to interpret it as a Flavor.

func Get

func Get(client *gophercloud.ServiceClient, id string) (r GetResult)

Get retrieves details of a single flavor. Use ExtractFlavor to convert its result into a Flavor.

func (GetResult) Extract

func (r GetResult) Extract() (*Flavor, error)

Extract provides access to the individual Flavor returned by the Get and Create functions.

type ListOpts

type ListOpts struct {

	// ChangesSince, if provided, instructs List to return only those things which
	// have changed since the timestamp provided.
	ChangesSince string `q:"changes-since"`

	// MinDisk and MinRAM, if provided, elides flavors which do not meet your
	// criteria.
	MinDisk int `q:"minDisk"`
	MinRAM  int `q:"minRam"`

	// Marker and Limit control paging.
	// Marker instructs List where to start listing from.
	Marker string `q:"marker"`

	// Limit instructs List to refrain from sending excessively large lists of
	// flavors.
	Limit int `q:"limit"`

	// AccessType, if provided, instructs List which set of flavors to return.
	// If IsPublic not provided, flavors for the current project are returned.
	AccessType AccessType `q:"is_public"`
}

ListOpts filters the results returned by the List() function. For example, a flavor with a minDisk field of 10 will not be returned if you specify MinDisk set to 20.

Typically, software will use the last ID of the previous call to List to set the Marker for the current call.

func (ListOpts) ToFlavorListQuery

func (opts ListOpts) ToFlavorListQuery() (string, error)

ToFlavorListQuery formats a ListOpts into a query string.

type ListOptsBuilder

type ListOptsBuilder interface {
	ToFlavorListQuery() (string, error)
}

ListOptsBuilder allows extensions to add additional parameters to the List request.

Directories

Path Synopsis
flavors unit tests
flavors unit tests

Jump to

Keyboard shortcuts

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