github.com/gophercloud/gophercloud@v1.11.0/openstack/compute/v2/extensions/servergroups/results.go (about)

     1  package servergroups
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/pagination"
     6  )
     7  
     8  // A ServerGroup creates a policy for instance placement in the cloud.
     9  // You should use extract methods from microversions.go to retrieve additional
    10  // fields.
    11  type ServerGroup struct {
    12  	// ID is the unique ID of the Server Group.
    13  	ID string `json:"id"`
    14  
    15  	// Name is the common name of the server group.
    16  	Name string `json:"name"`
    17  
    18  	// Polices are the group policies.
    19  	//
    20  	// Normally a single policy is applied:
    21  	//
    22  	// "affinity" will place all servers within the server group on the
    23  	// same compute node.
    24  	//
    25  	// "anti-affinity" will place servers within the server group on different
    26  	// compute nodes.
    27  	Policies []string `json:"policies"`
    28  
    29  	// Members are the members of the server group.
    30  	Members []string `json:"members"`
    31  
    32  	// UserID of the server group.
    33  	UserID string `json:"user_id"`
    34  
    35  	// ProjectID of the server group.
    36  	ProjectID string `json:"project_id"`
    37  
    38  	// Metadata includes a list of all user-specified key-value pairs attached
    39  	// to the Server Group.
    40  	Metadata map[string]interface{}
    41  
    42  	// Policy is the policy of a server group.
    43  	// This requires microversion 2.64 or later.
    44  	Policy *string `json:"policy"`
    45  
    46  	// Rules are the rules of the server group.
    47  	// This requires microversion 2.64 or later.
    48  	Rules *Rules `json:"rules"`
    49  }
    50  
    51  // Rules represents set of rules for a policy.
    52  // This requires microversion 2.64 or later.
    53  type Rules struct {
    54  	// MaxServerPerHost specifies how many servers can reside on a single compute host.
    55  	// It can be used only with the "anti-affinity" policy.
    56  	MaxServerPerHost int `json:"max_server_per_host"`
    57  }
    58  
    59  // ServerGroupPage stores a single page of all ServerGroups results from a
    60  // List call.
    61  type ServerGroupPage struct {
    62  	pagination.SinglePageBase
    63  }
    64  
    65  // IsEmpty determines whether or not a ServerGroupsPage is empty.
    66  func (page ServerGroupPage) IsEmpty() (bool, error) {
    67  	if page.StatusCode == 204 {
    68  		return true, nil
    69  	}
    70  
    71  	va, err := ExtractServerGroups(page)
    72  	return len(va) == 0, err
    73  }
    74  
    75  // ExtractServerGroups interprets a page of results as a slice of
    76  // ServerGroups.
    77  func ExtractServerGroups(r pagination.Page) ([]ServerGroup, error) {
    78  	var s struct {
    79  		ServerGroups []ServerGroup `json:"server_groups"`
    80  	}
    81  	err := (r.(ServerGroupPage)).ExtractInto(&s)
    82  	return s.ServerGroups, err
    83  }
    84  
    85  type ServerGroupResult struct {
    86  	gophercloud.Result
    87  }
    88  
    89  // Extract is a method that attempts to interpret any Server Group resource
    90  // response as a ServerGroup struct.
    91  func (r ServerGroupResult) Extract() (*ServerGroup, error) {
    92  	var s struct {
    93  		ServerGroup *ServerGroup `json:"server_group"`
    94  	}
    95  	err := r.ExtractInto(&s)
    96  	return s.ServerGroup, err
    97  }
    98  
    99  // CreateResult is the response from a Create operation. Call its Extract method
   100  // to interpret it as a ServerGroup.
   101  type CreateResult struct {
   102  	ServerGroupResult
   103  }
   104  
   105  // GetResult is the response from a Get operation. Call its Extract method to
   106  // interpret it as a ServerGroup.
   107  type GetResult struct {
   108  	ServerGroupResult
   109  }
   110  
   111  // DeleteResult is the response from a Delete operation. Call its ExtractErr
   112  // method to determine if the call succeeded or failed.
   113  type DeleteResult struct {
   114  	gophercloud.ErrResult
   115  }