Documentation ¶
Overview ¶
Package resourcetypes provides ability to manage resource types through the Gnocchi API.
Example of Listing resource types
allPages, err := resourcetypes.List(client).AllPages() if err != nil { panic(err) } allResourceTypes, err := resourcetypes.ExtractResourceTypes(allPages) if err != nil { panic(err) } for _, resourceType := range allResourceTypes { fmt.Printf("%+v\n", resourceType) }
Example of Getting a resource type
resourceTypeName := "compute_instance" resourceType, err := resourcetypes.Get(gnocchiClient, resourceTypeName).Extract() if err != nil { panic(err) }
Example of Creating a resource type
resourceTypeOpts := resourcetypes.CreateOpts{ Name: "compute_instance_network", Attributes: map[string]resourcetypes.AttributeOpts{ "port_name": resourcetypes.AttributeOpts{ Type: "string", Details: map[string]interface{}{ "max_length": 128, "required": false, }, }, "port_id": resourcetypes.AttributeOpts{ Type: "uuid", Details: map[string]interface{}{ "required": true, }, }, }, } resourceType, err := resourcetypes.Create(gnocchiClient, resourceTypeOpts).Extract() if err != nil { panic(err) }
Example of Updating a resource type
enabledAttributeOptions := resourcetypes.AttributeOpts{ Details: map[string]interface{}{ "required": true, "options": map[string]interface{}{ "fill": true, }, }, Type: "bool", } parendIDAttributeOptions := resourcetypes.AttributeOpts{ Details: map[string]interface{}{ "required": false, }, Type: "uuid", } resourceTypeOpts := resourcetypes.UpdateOpts{ Attributes: []resourcetypes.AttributeUpdateOpts{ { Name: "enabled", Operation: resourcetypes.AttributeAdd, Value: &enabledAttributeOptions, }, { Name: "parent_id", Operation: resourcetypes.AttributeAdd, Value: &parendIDAttributeOptions, }, { Name: "domain_id", Operation: resourcetypes.AttributeRemove, }, }, } resourceType, err := resourcetypes.Update(gnocchiClient, resourceTypeOpts).Extract() if err != nil { panic(err) }
Example of Deleting a resource type
err := resourcetypes.Delete(gnocchiClient, resourceType).ExtractErr() if err != nil { panic(err) }
Index ¶
- func List(client *gophercloud.ServiceClient) pagination.Pager
- type Attribute
- type AttributeOperation
- type AttributeOpts
- type AttributeUpdateOpts
- type CreateOpts
- type CreateOptsBuilder
- type CreateResult
- type DeleteResult
- type GetResult
- type ResourceType
- type ResourceTypePage
- type UpdateOpts
- type UpdateOptsBuilder
- type UpdateResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func List ¶
func List(client *gophercloud.ServiceClient) pagination.Pager
List makes a request against the Gnocchi API to list resource types.
Types ¶
type Attribute ¶
type Attribute struct { // Type is an attribute type. Type string `json:"type"` // Details represents different attribute fields. Details map[string]interface{} }
Attribute represents single attribute of a Gnocchi resource type.
type AttributeOperation ¶
type AttributeOperation string
AttributeOperation represents a type of operation that can be performed over Gnocchi resource type attribute.
const ( // AttributeAdd represents Gnocchi resource type attribute add operation. AttributeAdd AttributeOperation = "add" // AttributeRemove represents Gnocchi resource type attribute remove operation. AttributeRemove AttributeOperation = "remove" // AttributeCommonPath represents a prefix for every attribute in the Gnocchi // resource type. AttributeCommonPath = "/attributes" )
type AttributeOpts ¶
type AttributeOpts struct { // Type is an attribute type. Type string `json:"type"` // Details represents different attribute fields. Details map[string]interface{} `json:"-"` }
AttributeOpts represents options of a single resource type attribute that can be created in the Gnocchi.
func (AttributeOpts) ToMap ¶
func (opts AttributeOpts) ToMap() (map[string]interface{}, error)
ToMap is a helper function to convert individual AttributeOpts structure into a sub-map.
type AttributeUpdateOpts ¶
type AttributeUpdateOpts struct { // Name is a human-readable name of an attribute that needs to be added or removed. Name string `json:"-" required:"true"` // Operation represent action that needs to be performed over the attribute. Operation AttributeOperation `json:"-" required:"true"` // Value is an attribute options. Value *AttributeOpts `json:"-"` }
AttributeUpdateOpts represents update options over a single Gnocchi resource type attribute.
type CreateOpts ¶
type CreateOpts struct { // Attributes is a collection of keys and values of different resource types. Attributes map[string]AttributeOpts `json:"-"` // Name is a human-readable resource type identifier. Name string `json:"name" required:"true"` }
CreateOpts specifies parameters of a new Gnocchi resource type.
func (CreateOpts) ToResourceTypeCreateMap ¶
func (opts CreateOpts) ToResourceTypeCreateMap() (map[string]interface{}, error)
ToResourceTypeCreateMap constructs a request body from CreateOpts.
type CreateOptsBuilder ¶
CreateOptsBuilder allows to add additional parameters to the Create request.
type CreateResult ¶
type CreateResult struct {
// contains filtered or unexported fields
}
CreateResult represents the result of a create operation. Call its Extract method to interpret it as a Gnocchi resource type.
func Create ¶
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult)
Create requests the creation of a new Gnocchi resource type on the server.
func (CreateResult) Extract ¶
func (r CreateResult) Extract() (*ResourceType, error)
Extract is a function that accepts a result and extracts a Gnocchi resource type.
type DeleteResult ¶
type DeleteResult struct {
gophercloud.ErrResult
}
DeleteResult represents the result of a delete operation. Call its ExtractErr method to determine if the request succeeded or failed.
func Delete ¶
func Delete(c *gophercloud.ServiceClient, resourceTypeName string) (r DeleteResult)
Delete accepts a human-readable name and deletes the Gnocchi resource type associated with it.
type GetResult ¶
type GetResult struct {
// contains filtered or unexported fields
}
GetResult represents the result of a get operation. Call its Extract method to interpret it as a Gnocchi resource type.
func Get ¶
func Get(c *gophercloud.ServiceClient, resourceTypeName string) (r GetResult)
Get retrieves a specific Gnocchi resource type based on its name.
func (GetResult) Extract ¶
func (r GetResult) Extract() (*ResourceType, error)
Extract is a function that accepts a result and extracts a Gnocchi resource type.
type ResourceType ¶
type ResourceType struct { // Attributes is a collection of keys and values of different resource types. Attributes map[string]Attribute `json:"-"` // Name is a human-readable resource type identifier. Name string `json:"name"` // State represents current status of a resource type. State string `json:"state"` }
ResourceType represents custom Gnocchi resource type.
func ExtractResourceTypes ¶
func ExtractResourceTypes(r pagination.Page) ([]ResourceType, error)
ExtractResourceTypes interprets the results of a single page from a List() call, producing a slice of ResourceType structs.
func (*ResourceType) UnmarshalJSON ¶
func (r *ResourceType) UnmarshalJSON(b []byte) error
UnmarshalJSON helps to unmarshal ResourceType fields into needed values.
type ResourceTypePage ¶
type ResourceTypePage struct {
pagination.SinglePageBase
}
ResourceTypePage abstracts the raw results of making a List() request against the Gnocchi API.
As Gnocchi API may freely alter the response bodies of structures returned to the client, you may only safely access the data provided through the ExtractResources call.
func (ResourceTypePage) IsEmpty ¶
func (r ResourceTypePage) IsEmpty() (bool, error)
IsEmpty checks whether a ResourceTypePage struct is empty.
type UpdateOpts ¶
type UpdateOpts struct { // AttributesOperations is a collection of operations that need to be performed // over Gnocchi resource type attributes. Attributes []AttributeUpdateOpts `json:"-"` }
UpdateOpts specifies parameters for a Gnocchi resource type update request.
func (UpdateOpts) ToResourceTypeUpdateMap ¶
func (opts UpdateOpts) ToResourceTypeUpdateMap() ([]map[string]interface{}, error)
ToResourceTypeUpdateMap constructs a request body from UpdateOpts.
type UpdateOptsBuilder ¶
UpdateOptsBuilder allows to add additional parameters to the Update request.
type UpdateResult ¶
type UpdateResult struct {
// contains filtered or unexported fields
}
UpdateResult represents the result of an update operation. Call its Extract method to interpret it as a Gnocchi resource type.
func Update ¶
func Update(client *gophercloud.ServiceClient, resourceTypeName string, opts UpdateOptsBuilder) (r UpdateResult)
Update requests the update operation over existsing Gnocchi resource type.
func (UpdateResult) Extract ¶
func (r UpdateResult) Extract() (*ResourceType, error)
Extract is a function that accepts a result and extracts a Gnocchi resource type.