blob: 3c81ef80f8bf8d1981e29f85e3c51c861109f005 [file] [log] [blame]
Jon Perrittf95e3e42014-10-21 21:11:25 -05001package virtualinterfaces
Jon Perritt44b1ea22014-10-22 00:13:23 -05002
3import (
4 "github.com/rackspace/gophercloud"
5 "github.com/rackspace/gophercloud/pagination"
Jon Perritt44b1ea22014-10-22 00:13:23 -05006)
7
8// List returns a Pager which allows you to iterate over a collection of
9// networks. It accepts a ListOpts struct, which allows you to filter and sort
10// the returned collection for greater efficiency.
11func List(c *gophercloud.ServiceClient, instanceID string) pagination.Pager {
12 createPage := func(r pagination.PageResult) pagination.Page {
13 return VirtualInterfacePage{pagination.SinglePageBase(r)}
14 }
15
16 return pagination.NewPager(c, listURL(c, instanceID), createPage)
17}
18
19// Create creates a new virtual interface for a network and attaches the network
20// to the server instance.
21func Create(c *gophercloud.ServiceClient, instanceID, networkID string) CreateResult {
22 var res CreateResult
23
24 reqBody := map[string]map[string]string{
25 "virtual_interface": {
26 "network_id": networkID,
27 },
28 }
29
30 // Send request to API
Ash Wilson59fb6c42015-02-12 16:21:13 -050031 _, res.Err = c.Request("POST", createURL(c, instanceID), gophercloud.RequestOpts{
32 JSONBody: &reqBody,
33 JSONResponse: &res.Body,
34 OkCodes: []int{200, 201, 202},
Jon Perritt44b1ea22014-10-22 00:13:23 -050035 })
36 return res
37}
38
39// Delete deletes the interface with interfaceID attached to the instance with
40// instanceID.
41func Delete(c *gophercloud.ServiceClient, instanceID, interfaceID string) DeleteResult {
42 var res DeleteResult
Ash Wilson59fb6c42015-02-12 16:21:13 -050043 _, res.Err = c.Request("DELETE", deleteURL(c, instanceID, interfaceID), gophercloud.RequestOpts{
44 OkCodes: []int{200, 204},
Jon Perritt44b1ea22014-10-22 00:13:23 -050045 })
46 return res
47}