blob: 8b08c56ae7643726eb9873b3b23d70ef7f611118 [file] [log] [blame]
Jon Perritt857b3122014-10-22 18:17:44 -05001// +build acceptance rackspace networking v2
2
3package v2
Jon Perritt1176d852014-10-22 19:50:03 -05004
5import (
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
16func 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}