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) }
Example to List Flavor Access
flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b" allPages, err := flavors.ListAccesses(computeClient, flavorID).AllPages() if err != nil { panic(err) } allAccesses, err := flavors.ExtractAccesses(allPages) if err != nil { panic(err) } for _, access := range allAccesses { fmt.Printf("%+v", access) }
Example to Grant Access to a Flavor
flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b" accessOpts := flavors.AddAccessOpts{ Tenant: "15153a0979884b59b0592248ef947921", } accessList, err := flavors.AddAccess(computeClient, flavor.ID, accessOpts).Extract() if err != nil { panic(err) }
Example to Remove/Revoke Access to a Flavor
flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b" accessOpts := flavors.RemoveAccessOpts{ Tenant: "15153a0979884b59b0592248ef947921", } accessList, err := flavors.RemoveAccess(computeClient, flavor.ID, accessOpts).Extract() if err != nil { panic(err) }
Example to Create Extra Specs for a Flavor
flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b" createOpts := flavors.ExtraSpecsOpts{ "hw:cpu_policy": "CPU-POLICY", "hw:cpu_thread_policy": "CPU-THREAD-POLICY", } createdExtraSpecs, err := flavors.CreateExtraSpecs(computeClient, flavorID, createOpts).Extract() if err != nil { panic(err) } fmt.Printf("%+v", createdExtraSpecs)
Example to Get Extra Specs for a Flavor
flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b" extraSpecs, err := flavors.ListExtraSpecs(computeClient, flavorID).Extract() if err != nil { panic(err) } fmt.Printf("%+v", extraSpecs)
Example to Update Extra Specs for a Flavor
flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b" updateOpts := flavors.ExtraSpecsOpts{ "hw:cpu_thread_policy": "CPU-THREAD-POLICY-UPDATED", } updatedExtraSpec, err := flavors.UpdateExtraSpec(computeClient, flavorID, updateOpts).Extract() if err != nil { panic(err) } fmt.Printf("%+v", updatedExtraSpec)
Example to Delete an Extra Spec for a Flavor
flavorID := "e91758d6-a54a-4778-ad72-0c73a1cb695b" err := flavors.DeleteExtraSpec(computeClient, flavorID, "hw:cpu_thread_policy").ExtractErr() if err != nil { panic(err) }
Index ¶
- func IDFromName(client *gophercloud.ServiceClient, name string) (string, error)
- func ListAccesses(client *gophercloud.ServiceClient, id string) pagination.Pager
- func ListDetail(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager
- type AccessPage
- type AccessType
- type AddAccessOpts
- type AddAccessOptsBuilder
- type AddAccessResult
- type CreateExtraSpecsOptsBuilder
- type CreateExtraSpecsResult
- type CreateOpts
- type CreateOptsBuilder
- type CreateResult
- type DeleteExtraSpecResult
- type DeleteResult
- type ExtraSpecsOpts
- type Flavor
- type FlavorAccess
- type FlavorPage
- type GetExtraSpecResult
- type GetResult
- type ListExtraSpecsResult
- type ListOpts
- type ListOptsBuilder
- type RemoveAccessOpts
- type RemoveAccessOptsBuilder
- type RemoveAccessResult
- type UpdateExtraSpecOptsBuilder
- type UpdateExtraSpecResult
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 ListAccesses ¶
func ListAccesses(client *gophercloud.ServiceClient, id string) pagination.Pager
ListAccesses retrieves the tenants which have access to a flavor.
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 AccessPage ¶
type AccessPage struct {
pagination.SinglePageBase
}
AccessPage contains a single page of all FlavorAccess entries for a flavor.
func (AccessPage) IsEmpty ¶
func (page AccessPage) IsEmpty() (bool, error)
IsEmpty indicates whether an AccessPage is empty.
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 AddAccessOpts ¶
type AddAccessOpts struct { // Tenant is the project/tenant ID to grant access. Tenant string `json:"tenant"` }
AddAccessOpts represents options for adding access to a flavor.
func (AddAccessOpts) ToFlavorAddAccessMap ¶
func (opts AddAccessOpts) ToFlavorAddAccessMap() (map[string]interface{}, error)
ToFlavorAddAccessMap constructs a request body from AddAccessOpts.
type AddAccessOptsBuilder ¶
AddAccessOptsBuilder allows extensions to add additional parameters to the AddAccess requests.
type AddAccessResult ¶
type AddAccessResult struct {
// contains filtered or unexported fields
}
AddAccessResult is the response of an AddAccess operation. Call its Extract method to interpret it as a slice of FlavorAccess.
func AddAccess ¶
func AddAccess(client *gophercloud.ServiceClient, id string, opts AddAccessOptsBuilder) (r AddAccessResult)
AddAccess grants a tenant/project access to a flavor.
func (AddAccessResult) Extract ¶
func (r AddAccessResult) Extract() ([]FlavorAccess, error)
Extract provides access to the result of an access create or delete. The result will be all accesses that the flavor has.
type CreateExtraSpecsOptsBuilder ¶
type CreateExtraSpecsOptsBuilder interface {
ToExtraSpecsCreateMap() (map[string]interface{}, error)
}
CreateExtraSpecsOptsBuilder allows extensions to add additional parameters to the CreateExtraSpecs requests.
type CreateExtraSpecsResult ¶
type CreateExtraSpecsResult struct {
// contains filtered or unexported fields
}
CreateExtraSpecResult contains the result of a Create operation. Call its Extract method to interpret it as a map[string]interface.
func CreateExtraSpecs ¶
func CreateExtraSpecs(client *gophercloud.ServiceClient, flavorID string, opts CreateExtraSpecsOptsBuilder) (r CreateExtraSpecsResult)
CreateExtraSpecs will create or update the extra-specs key-value pairs for the specified Flavor
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 CreateResult ¶
type CreateResult struct {
// contains filtered or unexported fields
}
CreateResult is the response of a Get operations. Call its Extract method to interpret it as a Flavor.
func Create ¶
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult)
Create requests the creation of a new flavor.
type DeleteExtraSpecResult ¶
type DeleteExtraSpecResult struct {
gophercloud.ErrResult
}
DeleteExtraSpecResult contains the result of a Delete operation. Call its ExtractErr method to determine if the call succeeded or failed.
func DeleteExtraSpec ¶
func DeleteExtraSpec(client *gophercloud.ServiceClient, flavorID, key string) (r DeleteExtraSpecResult)
DeleteExtraSpec will delete the key-value pair with the given key for the given flavor ID.
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 ExtraSpecsOpts ¶
ExtraSpecsOpts is a map that contains key-value pairs.
func (ExtraSpecsOpts) ToExtraSpecUpdateMap ¶
func (opts ExtraSpecsOpts) ToExtraSpecUpdateMap() (map[string]string, string, error)
ToExtraSpecUpdateMap assembles a body for an Update request based on the contents of a ExtraSpecOpts.
func (ExtraSpecsOpts) ToExtraSpecsCreateMap ¶
func (opts ExtraSpecsOpts) ToExtraSpecsCreateMap() (map[string]interface{}, error)
ToExtraSpecsCreateMap assembles a body for a Create request based on the contents of a ExtraSpecsOpts
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:"os-flavor-access:is_public"` // Ephemeral is the amount of ephemeral disk space, measured in GB. Ephemeral int `json:"OS-FLV-EXT-DATA:ephemeral"` }
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 ¶
type FlavorAccess ¶
type FlavorAccess struct { // FlavorID is the unique ID of the flavor. FlavorID string `json:"flavor_id"` // TenantID is the unique ID of the tenant. TenantID string `json:"tenant_id"` }
FlavorAccess represents an ACL of tenant access to a specific Flavor.
func ExtractAccesses ¶
func ExtractAccesses(r pagination.Page) ([]FlavorAccess, error)
ExtractAccesses interprets a page of results as a slice of FlavorAccess.
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 GetExtraSpecResult ¶
type GetExtraSpecResult struct {
// contains filtered or unexported fields
}
GetExtraSpecResult contains the result of a Get operation. Call its Extract method to interpret it as a map[string]interface.
func GetExtraSpec ¶
func GetExtraSpec(client *gophercloud.ServiceClient, flavorID string, key string) (r GetExtraSpecResult)
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.
type ListExtraSpecsResult ¶
type ListExtraSpecsResult struct {
// contains filtered or unexported fields
}
ListExtraSpecsResult contains the result of a Get operation. Call its Extract method to interpret it as a map[string]interface.
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 ¶
ToFlavorListQuery formats a ListOpts into a query string.
type ListOptsBuilder ¶
ListOptsBuilder allows extensions to add additional parameters to the List request.
type RemoveAccessOpts ¶
type RemoveAccessOpts struct { // Tenant is the project/tenant ID to grant access. Tenant string `json:"tenant"` }
RemoveAccessOpts represents options for removing access to a flavor.
func (RemoveAccessOpts) ToFlavorRemoveAccessMap ¶
func (opts RemoveAccessOpts) ToFlavorRemoveAccessMap() (map[string]interface{}, error)
ToFlavorRemoveAccessMap constructs a request body from RemoveAccessOpts.
type RemoveAccessOptsBuilder ¶
type RemoveAccessOptsBuilder interface {
ToFlavorRemoveAccessMap() (map[string]interface{}, error)
}
RemoveAccessOptsBuilder allows extensions to add additional parameters to the RemoveAccess requests.
type RemoveAccessResult ¶
type RemoveAccessResult struct {
// contains filtered or unexported fields
}
RemoveAccessResult is the response of a RemoveAccess operation. Call its Extract method to interpret it as a slice of FlavorAccess.
func RemoveAccess ¶
func RemoveAccess(client *gophercloud.ServiceClient, id string, opts RemoveAccessOptsBuilder) (r RemoveAccessResult)
RemoveAccess removes/revokes a tenant/project access to a flavor.
func (RemoveAccessResult) Extract ¶
func (r RemoveAccessResult) Extract() ([]FlavorAccess, error)
Extract provides access to the result of an access create or delete. The result will be all accesses that the flavor has.
type UpdateExtraSpecOptsBuilder ¶
type UpdateExtraSpecOptsBuilder interface {
ToExtraSpecUpdateMap() (map[string]string, string, error)
}
UpdateExtraSpecOptsBuilder allows extensions to add additional parameters to the Update request.
type UpdateExtraSpecResult ¶
type UpdateExtraSpecResult struct {
// contains filtered or unexported fields
}
UpdateExtraSpecResult contains the result of an Update operation. Call its Extract method to interpret it as a map[string]interface.
func UpdateExtraSpec ¶
func UpdateExtraSpec(client *gophercloud.ServiceClient, flavorID string, opts UpdateExtraSpecOptsBuilder) (r UpdateExtraSpecResult)
UpdateExtraSpec will updates the value of the specified flavor's extra spec for the key in opts.