blob: 1759753b43b10a048a82cf2c43fa565fe51df94f [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"
6
7 "github.com/racker/perigee"
8)
9
10// List returns a Pager which allows you to iterate over a collection of
11// networks. It accepts a ListOpts struct, which allows you to filter and sort
12// the returned collection for greater efficiency.
13func List(c *gophercloud.ServiceClient, instanceID string) pagination.Pager {
14 createPage := func(r pagination.PageResult) pagination.Page {
15 return VirtualInterfacePage{pagination.SinglePageBase(r)}
16 }
17
18 return pagination.NewPager(c, listURL(c, instanceID), createPage)
19}
20
21// Create creates a new virtual interface for a network and attaches the network
22// to the server instance.
23func Create(c *gophercloud.ServiceClient, instanceID, networkID string) CreateResult {
24 var res CreateResult
25
26 reqBody := map[string]map[string]string{
27 "virtual_interface": {
28 "network_id": networkID,
29 },
30 }
31
32 // Send request to API
33 _, res.Err = perigee.Request("POST", createURL(c, instanceID), perigee.Options{
Jon Perrittb8edf082014-10-22 16:04:31 -050034 MoreHeaders: c.AuthenticatedHeaders(),
Jon Perritt44b1ea22014-10-22 00:13:23 -050035 ReqBody: &reqBody,
36 Results: &res.Body,
37 OkCodes: []int{201, 202},
38 })
39 return res
40}
41
42// Delete deletes the interface with interfaceID attached to the instance with
43// instanceID.
44func Delete(c *gophercloud.ServiceClient, instanceID, interfaceID string) DeleteResult {
45 var res DeleteResult
46 _, res.Err = perigee.Request("DELETE", deleteURL(c, instanceID, interfaceID), perigee.Options{
Jon Perrittb8edf082014-10-22 16:04:31 -050047 MoreHeaders: c.AuthenticatedHeaders(),
Jon Perritt44b1ea22014-10-22 00:13:23 -050048 OkCodes: []int{204},
49 })
50 return res
51}