Jon Perritt | f95e3e4 | 2014-10-21 21:11:25 -0500 | [diff] [blame] | 1 | package virtualinterfaces |
Jon Perritt | 44b1ea2 | 2014-10-22 00:13:23 -0500 | [diff] [blame] | 2 | |
| 3 | import ( |
| 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. |
| 13 | func 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. |
| 23 | func 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 Perritt | b8edf08 | 2014-10-22 16:04:31 -0500 | [diff] [blame] | 34 | MoreHeaders: c.AuthenticatedHeaders(), |
Jon Perritt | 44b1ea2 | 2014-10-22 00:13:23 -0500 | [diff] [blame] | 35 | ReqBody: &reqBody, |
| 36 | Results: &res.Body, |
Jon Perritt | 1176d85 | 2014-10-22 19:50:03 -0500 | [diff] [blame] | 37 | OkCodes: []int{200, 201, 202}, |
Jon Perritt | 44b1ea2 | 2014-10-22 00:13:23 -0500 | [diff] [blame] | 38 | }) |
| 39 | return res |
| 40 | } |
| 41 | |
| 42 | // Delete deletes the interface with interfaceID attached to the instance with |
| 43 | // instanceID. |
| 44 | func 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 Perritt | b8edf08 | 2014-10-22 16:04:31 -0500 | [diff] [blame] | 47 | MoreHeaders: c.AuthenticatedHeaders(), |
Jon Perritt | 1176d85 | 2014-10-22 19:50:03 -0500 | [diff] [blame] | 48 | OkCodes: []int{200, 204}, |
Jon Perritt | 44b1ea2 | 2014-10-22 00:13:23 -0500 | [diff] [blame] | 49 | }) |
| 50 | return res |
| 51 | } |