github.com/gophercloud/gophercloud@v1.11.0/openstack/compute/v2/extensions/aggregates/results.go (about) 1 package aggregates 2 3 import ( 4 "encoding/json" 5 "time" 6 7 "github.com/gophercloud/gophercloud" 8 "github.com/gophercloud/gophercloud/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 gophercloud.JSONRFC3339MilliNoZ `json:"created_at"` 50 UpdatedAt gophercloud.JSONRFC3339MilliNoZ `json:"updated_at"` 51 DeletedAt gophercloud.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 if page.StatusCode == 204 { 75 return true, nil 76 } 77 78 aggregates, err := ExtractAggregates(page) 79 return len(aggregates) == 0, err 80 } 81 82 // ExtractAggregates interprets a page of results as a slice of Aggregates. 83 func ExtractAggregates(p pagination.Page) ([]Aggregate, error) { 84 var a struct { 85 Aggregates []Aggregate `json:"aggregates"` 86 } 87 err := (p.(AggregatesPage)).ExtractInto(&a) 88 return a.Aggregates, err 89 } 90 91 type aggregatesResult struct { 92 gophercloud.Result 93 } 94 95 func (r aggregatesResult) Extract() (*Aggregate, error) { 96 var s struct { 97 Aggregate *Aggregate `json:"aggregate"` 98 } 99 err := r.ExtractInto(&s) 100 return s.Aggregate, err 101 } 102 103 type CreateResult struct { 104 aggregatesResult 105 } 106 107 type GetResult struct { 108 aggregatesResult 109 } 110 111 type DeleteResult struct { 112 gophercloud.ErrResult 113 } 114 115 type UpdateResult struct { 116 aggregatesResult 117 } 118 119 type ActionResult struct { 120 aggregatesResult 121 }