github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/aggregates/requests.go (about) 1 package aggregates 2 3 import ( 4 "strconv" 5 6 "github.com/huaweicloud/golangsdk" 7 "github.com/huaweicloud/golangsdk/pagination" 8 ) 9 10 // List makes a request against the API to list aggregates. 11 func List(client *golangsdk.ServiceClient) pagination.Pager { 12 return pagination.NewPager(client, aggregatesListURL(client), func(r pagination.PageResult) pagination.Page { 13 return AggregatesPage{pagination.SinglePageBase(r)} 14 }) 15 } 16 17 type CreateOpts struct { 18 // The name of the host aggregate. 19 Name string `json:"name" required:"true"` 20 21 // The availability zone of the host aggregate. 22 // You should use a custom availability zone rather than 23 // the default returned by the os-availability-zone API. 24 // The availability zone must not include ‘:’ in its name. 25 AvailabilityZone string `json:"availability_zone,omitempty"` 26 } 27 28 func (opts CreateOpts) ToAggregatesCreateMap() (map[string]interface{}, error) { 29 return golangsdk.BuildRequestBody(opts, "aggregate") 30 } 31 32 // Create makes a request against the API to create an aggregate. 33 func Create(client *golangsdk.ServiceClient, opts CreateOpts) (r CreateResult) { 34 b, err := opts.ToAggregatesCreateMap() 35 if err != nil { 36 r.Err = err 37 return 38 } 39 _, r.Err = client.Post(aggregatesCreateURL(client), b, &r.Body, &golangsdk.RequestOpts{ 40 OkCodes: []int{200}, 41 }) 42 return 43 } 44 45 // Delete makes a request against the API to delete an aggregate. 46 func Delete(client *golangsdk.ServiceClient, aggregateID int) (r DeleteResult) { 47 v := strconv.Itoa(aggregateID) 48 _, r.Err = client.Delete(aggregatesDeleteURL(client, v), &golangsdk.RequestOpts{ 49 OkCodes: []int{200}, 50 }) 51 return 52 } 53 54 // Get makes a request against the API to get details for a specific aggregate. 55 func Get(client *golangsdk.ServiceClient, aggregateID int) (r GetResult) { 56 v := strconv.Itoa(aggregateID) 57 _, r.Err = client.Get(aggregatesGetURL(client, v), &r.Body, &golangsdk.RequestOpts{ 58 OkCodes: []int{200}, 59 }) 60 return 61 } 62 63 type UpdateOpts struct { 64 // The name of the host aggregate. 65 Name string `json:"name,omitempty"` 66 67 // The availability zone of the host aggregate. 68 // You should use a custom availability zone rather than 69 // the default returned by the os-availability-zone API. 70 // The availability zone must not include ‘:’ in its name. 71 AvailabilityZone string `json:"availability_zone,omitempty"` 72 } 73 74 func (opts UpdateOpts) ToAggregatesUpdateMap() (map[string]interface{}, error) { 75 return golangsdk.BuildRequestBody(opts, "aggregate") 76 } 77 78 // Update makes a request against the API to update a specific aggregate. 79 func Update(client *golangsdk.ServiceClient, aggregateID int, opts UpdateOpts) (r UpdateResult) { 80 v := strconv.Itoa(aggregateID) 81 82 b, err := opts.ToAggregatesUpdateMap() 83 if err != nil { 84 r.Err = err 85 return 86 } 87 _, r.Err = client.Put(aggregatesUpdateURL(client, v), b, &r.Body, &golangsdk.RequestOpts{ 88 OkCodes: []int{200}, 89 }) 90 return 91 } 92 93 type AddHostOpts struct { 94 // The name of the host. 95 Host string `json:"host" required:"true"` 96 } 97 98 func (opts AddHostOpts) ToAggregatesAddHostMap() (map[string]interface{}, error) { 99 return golangsdk.BuildRequestBody(opts, "add_host") 100 } 101 102 // AddHost makes a request against the API to add host to a specific aggregate. 103 func AddHost(client *golangsdk.ServiceClient, aggregateID int, opts AddHostOpts) (r ActionResult) { 104 v := strconv.Itoa(aggregateID) 105 106 b, err := opts.ToAggregatesAddHostMap() 107 if err != nil { 108 r.Err = err 109 return 110 } 111 _, r.Err = client.Post(aggregatesAddHostURL(client, v), b, &r.Body, &golangsdk.RequestOpts{ 112 OkCodes: []int{200}, 113 }) 114 return 115 } 116 117 type RemoveHostOpts struct { 118 // The name of the host. 119 Host string `json:"host" required:"true"` 120 } 121 122 func (opts RemoveHostOpts) ToAggregatesRemoveHostMap() (map[string]interface{}, error) { 123 return golangsdk.BuildRequestBody(opts, "remove_host") 124 } 125 126 // RemoveHost makes a request against the API to remove host from a specific aggregate. 127 func RemoveHost(client *golangsdk.ServiceClient, aggregateID int, opts RemoveHostOpts) (r ActionResult) { 128 v := strconv.Itoa(aggregateID) 129 130 b, err := opts.ToAggregatesRemoveHostMap() 131 if err != nil { 132 r.Err = err 133 return 134 } 135 _, r.Err = client.Post(aggregatesRemoveHostURL(client, v), b, &r.Body, &golangsdk.RequestOpts{ 136 OkCodes: []int{200}, 137 }) 138 return 139 } 140 141 type SetMetadataOpts struct { 142 Metadata map[string]interface{} `json:"metadata" required:"true"` 143 } 144 145 func (opts SetMetadataOpts) ToSetMetadataMap() (map[string]interface{}, error) { 146 return golangsdk.BuildRequestBody(opts, "set_metadata") 147 } 148 149 // SetMetadata makes a request against the API to set metadata to a specific aggregate. 150 func SetMetadata(client *golangsdk.ServiceClient, aggregateID int, opts SetMetadataOpts) (r ActionResult) { 151 v := strconv.Itoa(aggregateID) 152 153 b, err := opts.ToSetMetadataMap() 154 if err != nil { 155 r.Err = err 156 return 157 } 158 _, r.Err = client.Post(aggregatesSetMetadataURL(client, v), b, &r.Body, &golangsdk.RequestOpts{ 159 OkCodes: []int{200}, 160 }) 161 return 162 }