github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/ecs/v1/servergroups/results.go (about)

     1  package servergroups
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  // FaultDomainInfo represents the response of `fault_domain`
     9  type FaultDomainInfo struct {
    10  	Names []string `json:"fault_domain_names"`
    11  }
    12  
    13  // A ServerGroup creates a policy for instance placement in the cloud.
    14  type ServerGroup struct {
    15  	// ID is the unique ID of the Server Group.
    16  	ID string `json:"id"`
    17  
    18  	// Name is the common name of the server group.
    19  	Name string `json:"name"`
    20  
    21  	// Polices are the group policies.
    22  	//
    23  	// Normally a single policy is applied:
    24  	//
    25  	// "affinity" will place all servers within the server group on the
    26  	// same compute node.
    27  	//
    28  	// "anti-affinity" will place servers within the server group on different
    29  	// compute nodes.
    30  	Policies []string `json:"policies"`
    31  
    32  	// Members are the members of the server group.
    33  	Members []string `json:"members"`
    34  
    35  	// FaultDomain is valid when policy is "fault_domain"
    36  	FaultDomain FaultDomainInfo `json:"fault_domain"`
    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  
    43  // ServerGroupPage stores a single page of all ServerGroups results from a
    44  // List call.
    45  type ServerGroupPage struct {
    46  	pagination.SinglePageBase
    47  }
    48  
    49  // IsEmpty determines whether or not a ServerGroupsPage is empty.
    50  func (page ServerGroupPage) IsEmpty() (bool, error) {
    51  	sgs, err := ExtractServerGroups(page)
    52  	return len(sgs) == 0, err
    53  }
    54  
    55  // ExtractServerGroups interprets a page of results as a slice of
    56  // ServerGroups.
    57  func ExtractServerGroups(r pagination.Page) ([]ServerGroup, error) {
    58  	var s struct {
    59  		ServerGroups []ServerGroup `json:"server_groups"`
    60  	}
    61  	err := (r.(ServerGroupPage)).ExtractInto(&s)
    62  	return s.ServerGroups, err
    63  }
    64  
    65  type commonResult struct {
    66  	golangsdk.Result
    67  }
    68  
    69  // Extract is a method that attempts to interpret any Server Group resource
    70  // response as a ServerGroup struct.
    71  func (r commonResult) Extract() (*ServerGroup, error) {
    72  	var s struct {
    73  		ServerGroup *ServerGroup `json:"server_group"`
    74  	}
    75  	err := r.ExtractInto(&s)
    76  	return s.ServerGroup, err
    77  }
    78  
    79  // CreateResult is the response from a Create operation. Call its Extract method
    80  // to interpret it as a ServerGroup.
    81  type CreateResult struct {
    82  	commonResult
    83  }
    84  
    85  // GetResult is the response from a Get operation. Call its Extract method to
    86  // interpret it as a ServerGroup.
    87  type GetResult struct {
    88  	commonResult
    89  }
    90  
    91  // DeleteResult is the response from a Delete operation. Call its ExtractErr
    92  // method to determine if the call succeeded or failed.
    93  type DeleteResult struct {
    94  	golangsdk.ErrResult
    95  }
    96  
    97  // MemberResult is the response from a Member update operation. Call its ExtractErr
    98  // method to determine if the call succeeded or failed.
    99  type MemberResult struct {
   100  	golangsdk.ErrResult
   101  }