blob: 82a529513697bfee8446f7910630acccf6013046 [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 }
25 _, res.Err = c.Request("POST", createURL(c), gophercloud.RequestOpts{
26 JSONBody: &reqBody,
27 JSONResponse: &res.Body,
28 OkCodes: []int{201},
29 })
30 return res
31}
32
33// ListForServer returns all public IPs for the server with the given serverID.
34func ListForServer(c *gophercloud.ServiceClient, serverID string) pagination.Pager {
35 url := listForServerURL(c, serverID)
36 createPage := func(r pagination.PageResult) pagination.Page {
37 return PublicIPPage{pagination.SinglePageBase(r)}
38 }
39 return pagination.NewPager(c, url, createPage)
40}
41
42// Get retrieves the public IP with the given id.
43func Get(c *gophercloud.ServiceClient, id string) GetResult {
44 var res GetResult
45 _, res.Err = c.Request("GET", getURL(c, id), gophercloud.RequestOpts{
46 JSONResponse: &res.Body,
47 OkCodes: []int{200},
48 })
49 return res
50}
51
52// Delete removes the public IP with the given id.
53func Delete(c *gophercloud.ServiceClient, id string) DeleteResult {
54 var res DeleteResult
55 _, res.Err = c.Request("DELETE", deleteURL(c, id), gophercloud.RequestOpts{
56 OkCodes: []int{204},
57 })
58 return res
59}