blob: 1ff7c5ae55f4ab14fd163dcda513fa5bd0726304 [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
Jamie Hannaford5497f942015-03-25 11:55:51 +010031 _, res.Err = c.Post(createURL(c, instanceID), reqBody, &res.Body, &gophercloud.RequestOpts{
32 OkCodes: []int{200, 201, 202},
Jon Perritt44b1ea22014-10-22 00:13:23 -050033 })
34 return res
35}
36
37// Delete deletes the interface with interfaceID attached to the instance with
38// instanceID.
39func Delete(c *gophercloud.ServiceClient, instanceID, interfaceID string) DeleteResult {
40 var res DeleteResult
Jamie Hannaford5497f942015-03-25 11:55:51 +010041 _, res.Err = c.Delete(deleteURL(c, instanceID, interfaceID), &gophercloud.RequestOpts{
Ash Wilson59fb6c42015-02-12 16:21:13 -050042 OkCodes: []int{200, 204},
Jon Perritt44b1ea22014-10-22 00:13:23 -050043 })
44 return res
45}