Jon Perritt | b55847b | 2015-03-17 20:43:48 -0600 | [diff] [blame] | 1 | package publicips |
| 2 | |
| 3 | import ( |
| 4 | "github.com/rackspace/gophercloud" |
| 5 | "github.com/rackspace/gophercloud/pagination" |
| 6 | ) |
| 7 | |
| 8 | // List returns all public IPs. |
| 9 | func List(c *gophercloud.ServiceClient) pagination.Pager { |
| 10 | url := listURL(c) |
| 11 | createPage := func(r pagination.PageResult) pagination.Page { |
| 12 | return PublicIPPage{pagination.SinglePageBase(r)} |
| 13 | } |
| 14 | return pagination.NewPager(c, url, createPage) |
| 15 | } |
| 16 | |
| 17 | // Create adds a public IP to the server with the given serverID. |
| 18 | func Create(c *gophercloud.ServiceClient, serverID string) CreateResult { |
| 19 | var res CreateResult |
| 20 | reqBody := map[string]interface{}{ |
| 21 | "cloud_server": map[string]string{ |
| 22 | "id": serverID, |
| 23 | }, |
| 24 | } |
Jamie Hannaford | 5497f94 | 2015-03-25 11:55:51 +0100 | [diff] [blame] | 25 | _, res.Err = c.Post(createURL(c), reqBody, &res.Body, nil) |
Jon Perritt | b55847b | 2015-03-17 20:43:48 -0600 | [diff] [blame] | 26 | return res |
| 27 | } |
| 28 | |
| 29 | // ListForServer returns all public IPs for the server with the given serverID. |
| 30 | func ListForServer(c *gophercloud.ServiceClient, serverID string) pagination.Pager { |
| 31 | url := listForServerURL(c, serverID) |
| 32 | createPage := func(r pagination.PageResult) pagination.Page { |
| 33 | return PublicIPPage{pagination.SinglePageBase(r)} |
| 34 | } |
| 35 | return pagination.NewPager(c, url, createPage) |
| 36 | } |
| 37 | |
| 38 | // Get retrieves the public IP with the given id. |
| 39 | func Get(c *gophercloud.ServiceClient, id string) GetResult { |
| 40 | var res GetResult |
Jamie Hannaford | 5497f94 | 2015-03-25 11:55:51 +0100 | [diff] [blame] | 41 | _, res.Err = c.Get(getURL(c, id), &res.Body, nil) |
Jon Perritt | b55847b | 2015-03-17 20:43:48 -0600 | [diff] [blame] | 42 | return res |
| 43 | } |
| 44 | |
| 45 | // Delete removes the public IP with the given id. |
| 46 | func Delete(c *gophercloud.ServiceClient, id string) DeleteResult { |
| 47 | var res DeleteResult |
Jamie Hannaford | 5497f94 | 2015-03-25 11:55:51 +0100 | [diff] [blame] | 48 | _, res.Err = c.Delete(deleteURL(c, id), nil) |
Jon Perritt | b55847b | 2015-03-17 20:43:48 -0600 | [diff] [blame] | 49 | return res |
| 50 | } |