blob: 1164260109e21328b330ec22bacad4cab1236372 [file] [log] [blame]
Jon Perrittb55847b2015-03-17 20:43:48 -06001package publicips
2
3import (
4 "github.com/rackspace/gophercloud"
5 "github.com/rackspace/gophercloud/pagination"
6)
7
8// List returns all public IPs.
9func 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.
18func 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 Hannaford5497f942015-03-25 11:55:51 +010025 _, res.Err = c.Post(createURL(c), reqBody, &res.Body, nil)
Jon Perrittb55847b2015-03-17 20:43:48 -060026 return res
27}
28
29// ListForServer returns all public IPs for the server with the given serverID.
30func 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.
39func Get(c *gophercloud.ServiceClient, id string) GetResult {
40 var res GetResult
Jamie Hannaford5497f942015-03-25 11:55:51 +010041 _, res.Err = c.Get(getURL(c, id), &res.Body, nil)
Jon Perrittb55847b2015-03-17 20:43:48 -060042 return res
43}
44
45// Delete removes the public IP with the given id.
46func Delete(c *gophercloud.ServiceClient, id string) DeleteResult {
47 var res DeleteResult
Jamie Hannaford5497f942015-03-25 11:55:51 +010048 _, res.Err = c.Delete(deleteURL(c, id), nil)
Jon Perrittb55847b2015-03-17 20:43:48 -060049 return res
50}