Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 1 | package servergroups |
| 2 | |
| 3 | import ( |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 4 | "github.com/gophercloud/gophercloud" |
| 5 | "github.com/gophercloud/gophercloud/pagination" |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 6 | ) |
| 7 | |
| 8 | // List returns a Pager that allows you to iterate over a collection of ServerGroups. |
| 9 | func List(client *gophercloud.ServiceClient) pagination.Pager { |
| 10 | return pagination.NewPager(client, listURL(client), func(r pagination.PageResult) pagination.Page { |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 11 | return ServerGroupPage{pagination.SinglePageBase(r)} |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 12 | }) |
| 13 | } |
| 14 | |
| 15 | // CreateOptsBuilder describes struct types that can be accepted by the Create call. Notably, the |
| 16 | // CreateOpts struct in this package does. |
| 17 | type CreateOptsBuilder interface { |
| 18 | ToServerGroupCreateMap() (map[string]interface{}, error) |
| 19 | } |
| 20 | |
| 21 | // CreateOpts specifies a Server Group allocation request |
| 22 | type CreateOpts struct { |
| 23 | // Name is the name of the server group |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 24 | Name string `json:"name" required:"true"` |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 25 | // Policies are the server group policies |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 26 | Policies []string `json:"policies" required:"true"` |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | // ToServerGroupCreateMap constructs a request body from CreateOpts. |
| 30 | func (opts CreateOpts) ToServerGroupCreateMap() (map[string]interface{}, error) { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 31 | return gophercloud.BuildRequestBody(opts, "server_group") |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | // Create requests the creation of a new Server Group |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 35 | func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 36 | b, err := opts.ToServerGroupCreateMap() |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 37 | if err != nil { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 38 | r.Err = err |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 39 | return |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 40 | } |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 41 | _, r.Err = client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{ |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 42 | OkCodes: []int{200}, |
| 43 | }) |
jrperritt | 29ae6b3 | 2016-04-13 12:59:37 -0500 | [diff] [blame] | 44 | return |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | // Get returns data about a previously created ServerGroup. |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 48 | func Get(client *gophercloud.ServiceClient, id string) (r GetResult) { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 49 | _, r.Err = client.Get(getURL(client, id), &r.Body, nil) |
jrperritt | 29ae6b3 | 2016-04-13 12:59:37 -0500 | [diff] [blame] | 50 | return |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | // Delete requests the deletion of a previously allocated ServerGroup. |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 54 | func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) { |
Jon Perritt | db0ae14 | 2016-03-13 00:33:41 -0600 | [diff] [blame] | 55 | _, r.Err = client.Delete(deleteURL(client, id), nil) |
jrperritt | 29ae6b3 | 2016-04-13 12:59:37 -0500 | [diff] [blame] | 56 | return |
Joe Topjian | c9fb21b | 2015-02-22 05:55:48 +0000 | [diff] [blame] | 57 | } |