blob: 446d3a3374765f473b8d6ad025b0ccf6915f19c9 [file] [log] [blame]
Jon Perritt26ff5b72014-10-23 11:54:39 -05001// +build acceptance rackspace
2
3package v2
4
5import (
6 "testing"
7
8 "github.com/rackspace/gophercloud/pagination"
9 "github.com/rackspace/gophercloud/rackspace/compute/v2/networks"
10 "github.com/rackspace/gophercloud/rackspace/compute/v2/virtualinterfaces"
11 th "github.com/rackspace/gophercloud/testhelper"
12)
13
14func TestVirtualInterfaces(t *testing.T) {
15 client, err := newClient()
16 th.AssertNoErr(t, err)
17
18 // Create a server
19 server := createServer(t, client)
20 t.Logf("Created Server: %v\n", server)
21 defer deleteServer(t, client, server)
22 serverID := server.ID
23
24 // Create a network
25 n, err := networks.Create(client, networks.CreateOpts{Label: "sample_network", CIDR: "172.20.0.0/24"}).Extract()
26 th.AssertNoErr(t, err)
27 t.Logf("Created Network: %v\n", n)
28 defer networks.Delete(client, n.ID)
29 networkID := n.ID
30
31 // Create a virtual interface
32 vi, err := virtualinterfaces.Create(client, serverID, networkID).Extract()
33 th.AssertNoErr(t, err)
34 t.Logf("Created virtual interface: %+v\n", vi)
35 defer virtualinterfaces.Delete(client, serverID, vi.ID)
36
37 // List virtual interfaces
38 pager := virtualinterfaces.List(client, serverID)
39 err = pager.EachPage(func(page pagination.Page) (bool, error) {
40 t.Logf("--- Page ---")
41
42 virtualinterfacesList, err := virtualinterfaces.ExtractVirtualInterfaces(page)
43 th.AssertNoErr(t, err)
44
45 for _, vi := range virtualinterfacesList {
46 t.Logf("Virtual Interface: ID [%s] MAC Address [%s] IP Addresses [%v]",
47 vi.ID, vi.MACAddress, vi.IPAddresses)
48 }
49
50 return true, nil
51 })
52 th.CheckNoErr(t, err)
53}