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" |
Jon Perritt | 44b1ea2 | 2014-10-22 00:13:23 -0500 | [diff] [blame] | 6 | ) |
| 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. |
| 11 | func 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. |
| 21 | func 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 Wilson | 59fb6c4 | 2015-02-12 16:21:13 -0500 | [diff] [blame] | 31 | _, res.Err = c.Request("POST", createURL(c, instanceID), gophercloud.RequestOpts{ |
| 32 | JSONBody: &reqBody, |
| 33 | JSONResponse: &res.Body, |
| 34 | OkCodes: []int{200, 201, 202}, |
Jon Perritt | 44b1ea2 | 2014-10-22 00:13:23 -0500 | [diff] [blame] | 35 | }) |
| 36 | return res |
| 37 | } |
| 38 | |
| 39 | // Delete deletes the interface with interfaceID attached to the instance with |
| 40 | // instanceID. |
| 41 | func Delete(c *gophercloud.ServiceClient, instanceID, interfaceID string) DeleteResult { |
| 42 | var res DeleteResult |
Ash Wilson | 59fb6c4 | 2015-02-12 16:21:13 -0500 | [diff] [blame] | 43 | _, res.Err = c.Request("DELETE", deleteURL(c, instanceID, interfaceID), gophercloud.RequestOpts{ |
| 44 | OkCodes: []int{200, 204}, |
Jon Perritt | 44b1ea2 | 2014-10-22 00:13:23 -0500 | [diff] [blame] | 45 | }) |
| 46 | return res |
| 47 | } |