github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/aggregates/results.go (about)

     1  package aggregates
     2  
     3  import (
     4  	"encoding/json"
     5  	"time"
     6  
     7  	"github.com/huaweicloud/golangsdk"
     8  	"github.com/huaweicloud/golangsdk/pagination"
     9  )
    10  
    11  // Aggregate represents a host aggregate in the OpenStack cloud.
    12  type Aggregate struct {
    13  	// The availability zone of the host aggregate.
    14  	AvailabilityZone string `json:"availability_zone"`
    15  
    16  	// A list of host ids in this aggregate.
    17  	Hosts []string `json:"hosts"`
    18  
    19  	// The ID of the host aggregate.
    20  	ID int `json:"id"`
    21  
    22  	// Metadata key and value pairs associate with the aggregate.
    23  	Metadata map[string]string `json:"metadata"`
    24  
    25  	// Name of the aggregate.
    26  	Name string `json:"name"`
    27  
    28  	// The date and time when the resource was created.
    29  	CreatedAt time.Time `json:"-"`
    30  
    31  	// The date and time when the resource was updated,
    32  	// if the resource has not been updated, this field will show as null.
    33  	UpdatedAt time.Time `json:"-"`
    34  
    35  	// The date and time when the resource was deleted,
    36  	// if the resource has not been deleted yet, this field will be null.
    37  	DeletedAt time.Time `json:"-"`
    38  
    39  	// A boolean indicates whether this aggregate is deleted or not,
    40  	// if it has not been deleted, false will appear.
    41  	Deleted bool `json:"deleted"`
    42  }
    43  
    44  // UnmarshalJSON to override default
    45  func (r *Aggregate) UnmarshalJSON(b []byte) error {
    46  	type tmp Aggregate
    47  	var s struct {
    48  		tmp
    49  		CreatedAt golangsdk.JSONRFC3339MilliNoZ `json:"created_at"`
    50  		UpdatedAt golangsdk.JSONRFC3339MilliNoZ `json:"updated_at"`
    51  		DeletedAt golangsdk.JSONRFC3339MilliNoZ `json:"deleted_at"`
    52  	}
    53  	err := json.Unmarshal(b, &s)
    54  	if err != nil {
    55  		return err
    56  	}
    57  	*r = Aggregate(s.tmp)
    58  
    59  	r.CreatedAt = time.Time(s.CreatedAt)
    60  	r.UpdatedAt = time.Time(s.UpdatedAt)
    61  	r.DeletedAt = time.Time(s.DeletedAt)
    62  
    63  	return nil
    64  }
    65  
    66  // AggregatesPage represents a single page of all Aggregates from a List
    67  // request.
    68  type AggregatesPage struct {
    69  	pagination.SinglePageBase
    70  }
    71  
    72  // IsEmpty determines whether or not a page of Aggregates contains any results.
    73  func (page AggregatesPage) IsEmpty() (bool, error) {
    74  	aggregates, err := ExtractAggregates(page)
    75  	return len(aggregates) == 0, err
    76  }
    77  
    78  // ExtractAggregates interprets a page of results as a slice of Aggregates.
    79  func ExtractAggregates(p pagination.Page) ([]Aggregate, error) {
    80  	var a struct {
    81  		Aggregates []Aggregate `json:"aggregates"`
    82  	}
    83  	err := (p.(AggregatesPage)).ExtractInto(&a)
    84  	return a.Aggregates, err
    85  }
    86  
    87  type aggregatesResult struct {
    88  	golangsdk.Result
    89  }
    90  
    91  func (r aggregatesResult) Extract() (*Aggregate, error) {
    92  	var s struct {
    93  		Aggregate *Aggregate `json:"aggregate"`
    94  	}
    95  	err := r.ExtractInto(&s)
    96  	return s.Aggregate, err
    97  }
    98  
    99  type CreateResult struct {
   100  	aggregatesResult
   101  }
   102  
   103  type GetResult struct {
   104  	aggregatesResult
   105  }
   106  
   107  type DeleteResult struct {
   108  	golangsdk.ErrResult
   109  }
   110  
   111  type UpdateResult struct {
   112  	aggregatesResult
   113  }
   114  
   115  type ActionResult struct {
   116  	aggregatesResult
   117  }