Documentation
¶
Overview ¶
Package traits manages traits from the OpenStack Placement service.
Traits API requests are available starting from microversion 1.6.
Example to list traits
placementClient.Microversion = "1.6"
allPages, err := traits.List(placementClient, traits.ListOpts{}).AllPages(context.TODO())
if err != nil {
panic(err)
}
allTraits, err := traits.ExtractTraits(allPages)
if err != nil {
panic(err)
}
for _, t := range allTraits {
fmt.Println(t)
}
Example to check if a trait exists
placementClient.Microversion = "1.6"
traitName := "CUSTOM_HW_FPGA_CLASS1"
err := traits.Get(context.TODO(), placementClient, traitName).ExtractErr()
if err != nil {
if gophercloud.ResponseCodeIs(err, http.StatusNotFound) {
// 404 Not Found - The trait does not exist
fmt.Println("Trait does not exist.")
} else {
// Another error occurred
panic(err)
}
} else {
fmt.Println("Trait exists!")
}
Example to create a trait
placementClient.Microversion = "1.6"
traitName := "CUSTOM_HW_FPGA_CLASS1"
err := traits.Create(context.TODO(), placementClient, traitName).ExtractErr()
if err != nil {
panic(err)
} else {
fmt.Println("Trait created successfully!")
}
Example to delete a trait
placementClient.Microversion = "1.6"
traitName := "CUSTOM_HW_FPGA_CLASS1"
err := traits.Delete(context.TODO(), placementClient, traitName).ExtractErr()
if err != nil {
panic(err)
} else {
fmt.Println("Trait deleted successfully!")
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractTraits ¶
func ExtractTraits(p pagination.Page) ([]string, error)
ExtractTraits takes a List result and extracts the collection of traits returned by the API.
func List ¶
func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager
List retrieves a list of traits.
Types ¶
type CreateResult ¶
type CreateResult struct {
gophercloud.ErrResult
}
CreateResult is the response from a Create operation. Call its ExtractErr to determine if the request succeeded or failed.
func Create ¶
func Create(ctx context.Context, client *gophercloud.ServiceClient, traitName string) (r CreateResult)
Create creates a new trait.
type DeleteResult ¶
type DeleteResult struct {
gophercloud.ErrResult
}
DeleteResult is the response from a Delete operation. Call its ExtractErr to determine if the request succeeded or failed.
func Delete ¶
func Delete(ctx context.Context, client *gophercloud.ServiceClient, traitName string) (r DeleteResult)
Delete deletes the trait specified by name.
type GetResult ¶
type GetResult struct {
gophercloud.ErrResult
}
GetResult is the response from a Get operation. Call its ExtractErr to determine if the request succeeded or failed.
func Get ¶
func Get(ctx context.Context, client *gophercloud.ServiceClient, traitName string) (r GetResult)
Get confirms the existence of a trait.
type ListOpts ¶
type ListOpts struct {
// Name is a string used to filter traits by name.
// It supports startswith operator to filter the traits whose name begins with
// a specific prefix, e.g. name=startswith:CUSTOM
// in operator filters the traits whose name is in the specified list,
// e.g. name=in:HW_CPU_X86_AVX,HW_CPU_X86_SSE,HW_CPU_X86_INVALID_FEATURE
Name string `q:"name"`
// Associated is a boolean used to filter traits by whether they are associated with
// at least one resource provider.
Associated *bool `q:"associated"`
}
ListOpts allows the filtering of traits. Filtering is achieved by passing in struct field values that map to the trait attributes you want to see returned.
func (ListOpts) ToTraitListQuery ¶
ToTraitListQuery formats a ListOpts into a query string.
type ListOptsBuilder ¶
ListOptsBuilder allows extensions to add additional parameters to the List request.
type TraitsPage ¶
type TraitsPage struct {
pagination.SinglePageBase
}
TraitsPage contains a single page of all traits from a List call.
func (TraitsPage) IsEmpty ¶
func (r TraitsPage) IsEmpty() (bool, error)
IsEmpty satisfies the IsEmpty method of the Page interface. It returns true if a List contains no results.