github.com/gophercloud/gophercloud@v1.11.0/openstack/baremetal/v1/allocations/results.go (about)

     1  package allocations
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/gophercloud/gophercloud"
     7  	"github.com/gophercloud/gophercloud/pagination"
     8  )
     9  
    10  type Allocation struct {
    11  	// The UUID for the resource.
    12  	UUID string `json:"uuid"`
    13  
    14  	// A list of UUIDs of the nodes that are candidates for this allocation.
    15  	CandidateNodes []string `json:"candidate_nodes"`
    16  
    17  	// The error message for the allocation if it is in the error state, null otherwise.
    18  	LastError string `json:"last_error"`
    19  
    20  	// The unique name of the allocation.
    21  	Name string `json:"name"`
    22  
    23  	// The UUID of the node assigned to the allocation. Will be null if a node is not yet assigned.
    24  	NodeUUID string `json:"node_uuid"`
    25  
    26  	// The current state of the allocation. One of: allocation, active, error
    27  	State string `json:"state"`
    28  
    29  	// The resource class requested for the allocation.
    30  	ResourceClass string `json:"resource_class"`
    31  
    32  	// The list of the traits requested for the allocation.
    33  	Traits []string `json:"traits"`
    34  
    35  	// A set of one or more arbitrary metadata key and value pairs.
    36  	Extra map[string]string `json:"extra"`
    37  
    38  	// The UTC date and time when the resource was created, ISO 8601 format.
    39  	CreatedAt time.Time `json:"created_at"`
    40  
    41  	// The UTC date and time when the resource was updated, ISO 8601 format. May be “null”.
    42  	UpdatedAt time.Time `json:"updated_at"`
    43  
    44  	// A list of relative links. Includes the self and bookmark links.
    45  	Links []interface{} `json:"links"`
    46  }
    47  
    48  type allocationResult struct {
    49  	gophercloud.Result
    50  }
    51  
    52  func (r allocationResult) Extract() (*Allocation, error) {
    53  	var s Allocation
    54  	err := r.ExtractInto(&s)
    55  	return &s, err
    56  }
    57  
    58  func (r allocationResult) ExtractInto(v interface{}) error {
    59  	return r.Result.ExtractIntoStructPtr(v, "")
    60  }
    61  
    62  func ExtractAllocationsInto(r pagination.Page, v interface{}) error {
    63  	return r.(AllocationPage).Result.ExtractIntoSlicePtr(v, "allocations")
    64  }
    65  
    66  // AllocationPage abstracts the raw results of making a List() request against
    67  // the API.
    68  type AllocationPage struct {
    69  	pagination.LinkedPageBase
    70  }
    71  
    72  // IsEmpty returns true if a page contains no Allocation results.
    73  func (r AllocationPage) IsEmpty() (bool, error) {
    74  	if r.StatusCode == 204 {
    75  		return true, nil
    76  	}
    77  
    78  	s, err := ExtractAllocations(r)
    79  	return len(s) == 0, err
    80  }
    81  
    82  // NextPageURL uses the response's embedded link reference to navigate to the
    83  // next page of results.
    84  func (r AllocationPage) NextPageURL() (string, error) {
    85  	var s struct {
    86  		Links []gophercloud.Link `json:"allocations_links"`
    87  	}
    88  	err := r.ExtractInto(&s)
    89  	if err != nil {
    90  		return "", err
    91  	}
    92  	return gophercloud.ExtractNextURL(s.Links)
    93  }
    94  
    95  // ExtractAllocations interprets the results of a single page from a List() call,
    96  // producing a slice of Allocation entities.
    97  func ExtractAllocations(r pagination.Page) ([]Allocation, error) {
    98  	var s []Allocation
    99  	err := ExtractAllocationsInto(r, &s)
   100  	return s, err
   101  }
   102  
   103  // GetResult is the response from a Get operation. Call its Extract
   104  // method to interpret it as a Allocation.
   105  type GetResult struct {
   106  	allocationResult
   107  }
   108  
   109  // CreateResult is the response from a Create operation.
   110  type CreateResult struct {
   111  	allocationResult
   112  }
   113  
   114  // DeleteResult is the response from a Delete operation. Call its ExtractErr
   115  // method to determine if the call succeeded or failed.
   116  type DeleteResult struct {
   117  	gophercloud.ErrResult
   118  }