This repository has been archived by the owner on Dec 10, 2018. It is now read-only.
/
requests.go
50 lines (44 loc) · 1.46 KB
/
requests.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package publicips
import (
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/pagination"
)
// List returns all public IPs.
func List(c *gophercloud.ServiceClient) pagination.Pager {
url := listURL(c)
createPage := func(r pagination.PageResult) pagination.Page {
return PublicIPPage{pagination.SinglePageBase(r)}
}
return pagination.NewPager(c, url, createPage)
}
// Create adds a public IP to the server with the given serverID.
func Create(c *gophercloud.ServiceClient, serverID string) CreateResult {
var res CreateResult
reqBody := map[string]interface{}{
"cloud_server": map[string]string{
"id": serverID,
},
}
_, res.Err = c.Post(createURL(c), reqBody, &res.Body, nil)
return res
}
// ListForServer returns all public IPs for the server with the given serverID.
func ListForServer(c *gophercloud.ServiceClient, serverID string) pagination.Pager {
url := listForServerURL(c, serverID)
createPage := func(r pagination.PageResult) pagination.Page {
return PublicIPPage{pagination.SinglePageBase(r)}
}
return pagination.NewPager(c, url, createPage)
}
// Get retrieves the public IP with the given id.
func Get(c *gophercloud.ServiceClient, id string) GetResult {
var res GetResult
_, res.Err = c.Get(getURL(c, id), &res.Body, nil)
return res
}
// Delete removes the public IP with the given id.
func Delete(c *gophercloud.ServiceClient, id string) DeleteResult {
var res DeleteResult
_, res.Err = c.Delete(deleteURL(c, id), nil)
return res
}