v1.7.0 Latest Latest

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

Go to latest
Published: Sep 25, 2023 License: Apache-2.0 Imports: 2 Imported by: 137



Package servergroups provides the ability to manage server groups.

Example to List Server Groups

allpages, err := servergroups.List(computeClient).AllPages()
if err != nil {

allServerGroups, err := servergroups.ExtractServerGroups(allPages)
if err != nil {

for _, sg := range allServerGroups {
	fmt.Printf("%#v\n", sg)

Example to Create a Server Group

createOpts := servergroups.CreateOpts{
	Name:     "my_sg",
	Policies: []string{"anti-affinity"},

sg, err := servergroups.Create(computeClient, createOpts).Extract()
if err != nil {

Example to Create a Server Group with additional microversion 2.64 fields

	createOpts := servergroups.CreateOpts{
		Name:   "my_sg",
		Policy: "anti-affinity",
        	Rules: &servergroups.Rules{
            		MaxServerPerHost: 3,

	computeClient.Microversion = "2.64"
	result := servergroups.Create(computeClient, createOpts)

	serverGroup, err := result.Extract()
	if err != nil {

Example to Delete a Server Group

sgID := "7a6f29ad-e34d-4368-951a-58a08f11cfb7"
err := servergroups.Delete(computeClient, sgID).ExtractErr()
if err != nil {



This section is empty.


This section is empty.


func List

List returns a Pager that allows you to iterate over a collection of ServerGroups.


type CreateOpts

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

	// Policies are the server group policies.
	Policies []string `json:"policies,omitempty"`

	// Policy specifies the name of a policy.
	// Requires microversion 2.64 or later.
	Policy string `json:"policy,omitempty"`

	// Rules specifies the set of rules.
	// Requires microversion 2.64 or later.
	Rules *Rules `json:"rules,omitempty"`

CreateOpts specifies Server Group creation parameters.

func (CreateOpts) ToServerGroupCreateMap

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

ToServerGroupCreateMap constructs a request body from CreateOpts.

type CreateOptsBuilder

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

CreateOptsBuilder allows extensions to add additional parameters to the Create request.

type CreateResult

type CreateResult struct {

CreateResult is the response from a Create operation. Call its Extract method to interpret it as a ServerGroup.

func Create

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

Create requests the creation of a new Server Group.

type DeleteResult

type DeleteResult struct {

DeleteResult is the response 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 requests the deletion of a previously allocated ServerGroup.

type GetResult

type GetResult struct {

GetResult is the response from a Get operation. Call its Extract method to interpret it as a ServerGroup.

func Get

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

Get returns data about a previously created ServerGroup.

type ListOpts added in v0.15.0

type ListOpts struct {
	// AllProjects is a bool to show all projects.
	AllProjects bool `q:"all_projects"`

	// Requests a page size of items.
	Limit int `q:"limit"`

	// Used in conjunction with limit to return a slice of items.
	Offset int `q:"offset"`

func (ListOpts) ToServerListQuery added in v0.15.0

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

ToServerListQuery formats a ListOpts into a query string.

type ListOptsBuilder added in v0.15.0

type ListOptsBuilder interface {
	ToServerListQuery() (string, error)

type Rules added in v0.3.0

type Rules struct {
	// MaxServerPerHost specifies how many servers can reside on a single compute host.
	// It can be used only with the "anti-affinity" policy.
	MaxServerPerHost int `json:"max_server_per_host"`

Rules represents set of rules for a policy. This requires microversion 2.64 or later.

type ServerGroup

type ServerGroup struct {
	// ID is the unique ID of the Server Group.
	ID string `json:"id"`

	// Name is the common name of the server group.
	Name string `json:"name"`

	// Polices are the group policies.
	// Normally a single policy is applied:
	// "affinity" will place all servers within the server group on the
	// same compute node.
	// "anti-affinity" will place servers within the server group on different
	// compute nodes.
	Policies []string `json:"policies"`

	// Members are the members of the server group.
	Members []string `json:"members"`

	// UserID of the server group.
	UserID string `json:"user_id"`

	// ProjectID of the server group.
	ProjectID string `json:"project_id"`

	// Metadata includes a list of all user-specified key-value pairs attached
	// to the Server Group.
	Metadata map[string]interface{}

	// Policy is the policy of a server group.
	// This requires microversion 2.64 or later.
	Policy *string `json:"policy"`

	// Rules are the rules of the server group.
	// This requires microversion 2.64 or later.
	Rules *Rules `json:"rules"`

A ServerGroup creates a policy for instance placement in the cloud. You should use extract methods from microversions.go to retrieve additional fields.

func ExtractServerGroups

func ExtractServerGroups(r pagination.Page) ([]ServerGroup, error)

ExtractServerGroups interprets a page of results as a slice of ServerGroups.

type ServerGroupPage

type ServerGroupPage struct {

ServerGroupPage stores a single page of all ServerGroups results from a List call.

func (ServerGroupPage) IsEmpty

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

IsEmpty determines whether or not a ServerGroupsPage is empty.

type ServerGroupResult

type ServerGroupResult struct {

func (ServerGroupResult) Extract

func (r ServerGroupResult) Extract() (*ServerGroup, error)

Extract is a method that attempts to interpret any Server Group resource response as a ServerGroup struct.


Path Synopsis
servergroups unit tests
servergroups unit tests

Jump to

Keyboard shortcuts

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