blob: 39475e176e274e93f73db8a86e7749de242ac328 [file] [log] [blame]
Jon Perritt26ff5b72014-10-23 11:54:39 -05001// +build acceptance rackspace
2
3package v2
4
5import (
Ash Wilsonefbae202014-10-24 14:23:45 -04006 "testing"
Jon Perritt26ff5b72014-10-23 11:54:39 -05007
Ash Wilsonefbae202014-10-24 14:23:45 -04008 "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"
Jon Perritt26ff5b72014-10-23 11:54:39 -050012)
13
14func TestVirtualInterfaces(t *testing.T) {
Ash Wilsonefbae202014-10-24 14:23:45 -040015 client, err := newClient()
16 th.AssertNoErr(t, err)
Jon Perritt26ff5b72014-10-23 11:54:39 -050017
Ash Wilsonefbae202014-10-24 14:23:45 -040018 // 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
Jon Perritt26ff5b72014-10-23 11:54:39 -050023
Ash Wilsonefbae202014-10-24 14:23:45 -040024 // 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
Jon Perritt26ff5b72014-10-23 11:54:39 -050030
Ash Wilsonefbae202014-10-24 14:23:45 -040031 // 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)
Jon Perritt26ff5b72014-10-23 11:54:39 -050036
Ash Wilsonefbae202014-10-24 14:23:45 -040037 // List virtual interfaces
38 pager := virtualinterfaces.List(client, serverID)
39 err = pager.EachPage(func(page pagination.Page) (bool, error) {
40 t.Logf("--- Page ---")
Jon Perritt26ff5b72014-10-23 11:54:39 -050041
Ash Wilsonefbae202014-10-24 14:23:45 -040042 virtualinterfacesList, err := virtualinterfaces.ExtractVirtualInterfaces(page)
43 th.AssertNoErr(t, err)
Jon Perritt26ff5b72014-10-23 11:54:39 -050044
Ash Wilsonefbae202014-10-24 14:23:45 -040045 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 }
Jon Perritt26ff5b72014-10-23 11:54:39 -050049
Ash Wilsonefbae202014-10-24 14:23:45 -040050 return true, nil
51 })
52 th.CheckNoErr(t, err)
Jon Perritt26ff5b72014-10-23 11:54:39 -050053}