Jon Perritt | 857b312 | 2014-10-22 18:17:44 -0500 | [diff] [blame] | 1 | // +build acceptance rackspace networking v2 |
| 2 | |
| 3 | package v2 |
Jon Perritt | 1176d85 | 2014-10-22 19:50:03 -0500 | [diff] [blame^] | 4 | |
| 5 | import ( |
| 6 | "testing" |
| 7 | |
| 8 | osServers "github.com/rackspace/gophercloud/openstack/compute/v2/servers" |
| 9 | "github.com/rackspace/gophercloud/pagination" |
| 10 | "github.com/rackspace/gophercloud/rackspace/networking/v2/networks" |
| 11 | "github.com/rackspace/gophercloud/rackspace/compute/v2/servers" |
| 12 | "github.com/rackspace/gophercloud/rackspace/networking/v2/virtualinterfaces" |
| 13 | th "github.com/rackspace/gophercloud/testhelper" |
| 14 | ) |
| 15 | |
| 16 | func TestVirtualInterfaces(t *testing.T) { |
| 17 | Setup(t) |
| 18 | defer Teardown() |
| 19 | |
| 20 | // Get a Server |
| 21 | var serverID string |
| 22 | pager := servers.List(Client, osServers.ListOpts{Limit:1}) |
| 23 | err := pager.EachPage(func(page pagination.Page) (bool, error) { |
| 24 | servers, err := servers.ExtractServers(page) |
| 25 | if err != nil { |
| 26 | return false, err |
| 27 | } |
| 28 | serverID = servers[0].ID |
| 29 | return true, nil |
| 30 | }) |
| 31 | th.AssertNoErr(t, err) |
| 32 | |
| 33 | t.Logf("ServerID: %s", serverID) |
| 34 | |
| 35 | // Create a network |
| 36 | n, err := networks.Create(Client, networks.CreateOpts{Label: "sample_network", CIDR: "172.20.0.0/24"}).Extract() |
| 37 | th.AssertNoErr(t, err) |
| 38 | defer networks.Delete(Client, n.ID) |
| 39 | networkID := n.ID |
| 40 | |
| 41 | t.Logf("NetworkID: %s", networkID) |
| 42 | |
| 43 | // Create a virtual interface |
| 44 | vi, err := virtualinterfaces.Create(Client, serverID, networkID).Extract() |
| 45 | th.AssertNoErr(t, err) |
| 46 | t.Logf("Created virtual interface: %+v\n", vi) |
| 47 | defer virtualinterfaces.Delete(Client, serverID, vi.ID) |
| 48 | |
| 49 | // List virtual interfaces |
| 50 | pager = virtualinterfaces.List(Client, serverID) |
| 51 | err = pager.EachPage(func(page pagination.Page) (bool, error) { |
| 52 | t.Logf("--- Page ---") |
| 53 | |
| 54 | virtualinterfacesList, err := virtualinterfaces.ExtractVirtualInterfaces(page) |
| 55 | th.AssertNoErr(t, err) |
| 56 | |
| 57 | for _, vi := range virtualinterfacesList { |
| 58 | t.Logf("Virtual Interface: ID [%s] MAC Address [%s] IP Addresses [%v]", |
| 59 | vi.ID, vi.MACAddress, vi.IPAddresses) |
| 60 | } |
| 61 | |
| 62 | return true, nil |
| 63 | }) |
| 64 | th.CheckNoErr(t, err) |
| 65 | } |