Documentation ¶
Overview ¶
Package nodegroups provides methods for interacting with the Magnum node group API.
All node group actions must be performed on a specific cluster, so the cluster UUID/name is required as a parameter in each method.
Create a client to use:
opts, err := openstack.AuthOptionsFromEnv() if err != nil { panic(err) } provider, err := openstack.AuthenticatedClient(opts) if err != nil { panic(err) } client, err := openstack.NewContainerInfraV1(provider, gophercloud.EndpointOpts{Region: os.Getenv("OS_REGION_NAME")}) if err != nil { panic(err) } client.Microversion = "1.9"
Example of Getting a node group:
ng, err := nodegroups.Get(client, clusterUUID, nodeGroupUUID).Extract() if err != nil { panic(err) } fmt.Printf("%#v\n", ng)
Example of Listing node groups:
listOpts := nodegroup.ListOpts{ Role: "worker", } allPages, err := nodegroups.List(client, clusterUUID, listOpts).AllPages() if err != nil { panic(err) } ngs, err := nodegroups.ExtractNodeGroups(allPages) if err != nil { panic(err) } for _, ng := range ngs { fmt.Printf("%#v\n", ng) }
Example of Creating a node group:
// Labels, node image and node flavor will be inherited from the cluster value if not set. // Role will default to "worker" if not set. // To add a label to the new node group, need to know the cluster labels cluster, err := clusters.Get(client, clusterUUID).Extract() if err != nil { panic(err) } // Add the new label labels := cluster.Labels labels["availability_zone"] = "A" maxNodes := 5 createOpts := nodegroups.CreateOpts{ Name: "new-nodegroup", MinNodeCount: 2, MaxNodeCount: &maxNodes, Labels: labels, } ng, err := nodegroups.Create(client, clusterUUID, createOpts).Extract() if err != nil { panic(err) } fmt.Printf("%#v\n", ng)
Example of Updating a node group:
// Valid paths are "/min_node_count" and "/max_node_count". // Max node count can be unset with the "remove" op to have // no enforced maximum node count. updateOpts := []nodegroups.UpdateOptsBuilder{ nodegroups.UpdateOpts{ Op: nodegroups.ReplaceOp, Path: "/max_node_count", Value: 10, }, } ng, err = nodegroups.Update(client, clusterUUID, nodeGroupUUID, updateOpts).Extract() if err != nil { panic(err) } fmt.Printf("%#v\n", ng)
Example of Deleting a node group:
err = nodegroups.Delete(client, clusterUUID, nodeGroupUUID).ExtractErr() if err != nil { panic(err) }
Index ¶
- func List(client *gophercloud.ServiceClient, clusterID string, opts ListOptsBuilder) pagination.Pager
- type CreateOpts
- type CreateOptsBuilder
- type CreateResult
- type DeleteResult
- type GetResult
- type ListOpts
- type ListOptsBuilder
- type NodeGroup
- type NodeGroupPage
- type UpdateOp
- type UpdateOpts
- type UpdateOptsBuilder
- type UpdateResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func List ¶
func List(client *gophercloud.ServiceClient, clusterID string, opts ListOptsBuilder) pagination.Pager
List makes a request to the Magnum API to retrieve node groups belonging to the given cluster. The request can be modified to filter or sort the list using the options available in ListOpts.
Use the AllPages method of the returned Pager to ensure that all node groups are returned (for example when using the Limit option to limit the number of node groups returned per page).
Not all node group fields are returned in a list request. Only the fields UUID, Name, FlavorID, ImageID, NodeCount, Role, IsDefault, Status and StackID are returned, all other fields are omitted and will have their zero value when extracted.
Types ¶
type CreateOpts ¶
type CreateOpts struct { Name string `json:"name" required:"true"` DockerVolumeSize *int `json:"docker_volume_size,omitempty"` // Labels will default to the cluster labels if unset. Labels map[string]string `json:"labels,omitempty"` NodeCount *int `json:"node_count,omitempty"` MinNodeCount int `json:"min_node_count,omitempty"` // MaxNodeCount can be left unset for no maximum node count. MaxNodeCount *int `json:"max_node_count,omitempty"` // Role defaults to "worker" if unset. Role string `json:"role,omitempty"` // Node image ID. Defaults to cluster template image if unset. ImageID string `json:"image_id,omitempty"` // Node machine flavor ID. Defaults to cluster minion flavor if unset. FlavorID string `json:"flavor_id,omitempty"` MergeLabels *bool `json:"merge_labels,omitempty"` }
CreateOpts is used to set available fields upon node group creation.
If unset, some fields have defaults or will inherit from the cluster value.
func (CreateOpts) ToNodeGroupCreateMap ¶
func (opts CreateOpts) ToNodeGroupCreateMap() (map[string]interface{}, error)
type CreateOptsBuilder ¶
type CreateResult ¶
type CreateResult struct {
// contains filtered or unexported fields
}
CreateResult is the response from a Create request. Use the Extract method to retrieve the created node group.
func Create ¶
func Create(client *gophercloud.ServiceClient, clusterID string, opts CreateOptsBuilder) (r CreateResult)
Create makes a request to the Magnum API to create a node group for the the given cluster. Use the Extract method of the returned CreateResult to extract the returned node group.
type DeleteResult ¶
type DeleteResult struct {
gophercloud.ErrResult
}
DeleteResult is the response from a Delete request. Use the ExtractErr method to extract the error from the result.
func Delete ¶
func Delete(client *gophercloud.ServiceClient, clusterID, nodeGroupID string) (r DeleteResult)
Delete makes a request to the Magnum API to delete a node group.
type GetResult ¶
type GetResult struct {
// contains filtered or unexported fields
}
GetResult is the response from a Get request. Use the Extract method to retrieve the NodeGroup itself.
func Get ¶
func Get(client *gophercloud.ServiceClient, clusterID, nodeGroupID string) (r GetResult)
Get makes a request to the Magnum API to retrieve a node group with the given ID/name belonging to the given cluster. Use the Extract method of the returned GetResult to extract the node group from the result.
type ListOpts ¶
type ListOpts struct { // Pagination marker for large data sets. (UUID field from node group). Marker int `q:"marker"` // Maximum number of resources to return in a single page. Limit int `q:"limit"` // Column to sort results by. Default: id. SortKey string `q:"sort_key"` // Direction to sort. "asc" or "desc". Default: asc. SortDir string `q:"sort_dir"` // List all nodegroups with the specified role. Role string `q:"role"` }
ListOpts is used to filter and sort the node groups of a cluster when using List.
func (ListOpts) ToNodeGroupsListQuery ¶
type ListOptsBuilder ¶
type NodeGroup ¶
type NodeGroup struct { ID int `json:"id"` UUID string `json:"uuid"` Name string `json:"name"` ClusterID string `json:"cluster_id"` ProjectID string `json:"project_id"` DockerVolumeSize *int `json:"docker_volume_size"` Labels map[string]string `json:"labels"` LabelsAdded map[string]string `json:"labels_added"` LabelsOverridden map[string]string `json:"labels_overridden"` LabelsSkipped map[string]string `json:"labels_skipped"` Links []gophercloud.Link `json:"links"` FlavorID string `json:"flavor_id"` ImageID string `json:"image_id"` NodeAddresses []string `json:"node_addresses"` NodeCount int `json:"node_count"` Role string `json:"role"` MinNodeCount int `json:"min_node_count"` MaxNodeCount *int `json:"max_node_count"` IsDefault bool `json:"is_default"` StackID string `json:"stack_id"` Status string `json:"status"` StatusReason string `json:"status_reason"` Version string `json:"version"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` }
NodeGroup is the API representation of a Magnum node group.
func ExtractNodeGroups ¶
func ExtractNodeGroups(r pagination.Page) ([]NodeGroup, error)
ExtractNodeGroups takes a Page of node groups as returned from List or from AllPages and extracts it as a slice of NodeGroups.
type NodeGroupPage ¶
type NodeGroupPage struct {
pagination.LinkedPageBase
}
func (NodeGroupPage) IsEmpty ¶
func (r NodeGroupPage) IsEmpty() (bool, error)
func (NodeGroupPage) NextPageURL ¶
func (r NodeGroupPage) NextPageURL() (string, error)
type UpdateOpts ¶
type UpdateOpts struct { Op UpdateOp `json:"op" required:"true"` Path string `json:"path" required:"true"` Value interface{} `json:"value,omitempty"` }
UpdateOpts is used to define the action taken when updating a node group.
Valid Ops are "add", "remove", "replace" Valid Paths are "/min_node_count" and "/max_node_count"
func (UpdateOpts) ToResourceUpdateMap ¶
func (opts UpdateOpts) ToResourceUpdateMap() (map[string]interface{}, error)
type UpdateOptsBuilder ¶
type UpdateResult ¶
type UpdateResult struct {
// contains filtered or unexported fields
}
UpdateResult is the response from an Update request. Use the Extract method to retrieve the updated node group.
func Update ¶
func Update(client *gophercloud.ServiceClient, clusterID string, nodeGroupID string, opts []UpdateOptsBuilder) (r UpdateResult)
Update makes a request to the Magnum API to update a field of the given node group belonging to the given cluster. More than one UpdateOpts can be passed at a time. Use the Extract method of the returned UpdateResult to extract the updated node group from the result.