Jon Perritt | 26ff5b7 | 2014-10-23 11:54:39 -0500 | [diff] [blame] | 1 | // +build acceptance rackspace |
| 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
Ash Wilson | efbae20 | 2014-10-24 14:23:45 -0400 | [diff] [blame^] | 6 | "testing" |
Jon Perritt | 26ff5b7 | 2014-10-23 11:54:39 -0500 | [diff] [blame] | 7 | |
Ash Wilson | efbae20 | 2014-10-24 14:23:45 -0400 | [diff] [blame^] | 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" |
Jon Perritt | 26ff5b7 | 2014-10-23 11:54:39 -0500 | [diff] [blame] | 12 | ) |
| 13 | |
| 14 | func TestVirtualInterfaces(t *testing.T) { |
Ash Wilson | efbae20 | 2014-10-24 14:23:45 -0400 | [diff] [blame^] | 15 | client, err := newClient() |
| 16 | th.AssertNoErr(t, err) |
Jon Perritt | 26ff5b7 | 2014-10-23 11:54:39 -0500 | [diff] [blame] | 17 | |
Ash Wilson | efbae20 | 2014-10-24 14:23:45 -0400 | [diff] [blame^] | 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 |
Jon Perritt | 26ff5b7 | 2014-10-23 11:54:39 -0500 | [diff] [blame] | 23 | |
Ash Wilson | efbae20 | 2014-10-24 14:23:45 -0400 | [diff] [blame^] | 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 |
Jon Perritt | 26ff5b7 | 2014-10-23 11:54:39 -0500 | [diff] [blame] | 30 | |
Ash Wilson | efbae20 | 2014-10-24 14:23:45 -0400 | [diff] [blame^] | 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) |
Jon Perritt | 26ff5b7 | 2014-10-23 11:54:39 -0500 | [diff] [blame] | 36 | |
Ash Wilson | efbae20 | 2014-10-24 14:23:45 -0400 | [diff] [blame^] | 37 | // List virtual interfaces |
| 38 | pager := virtualinterfaces.List(client, serverID) |
| 39 | err = pager.EachPage(func(page pagination.Page) (bool, error) { |
| 40 | t.Logf("--- Page ---") |
Jon Perritt | 26ff5b7 | 2014-10-23 11:54:39 -0500 | [diff] [blame] | 41 | |
Ash Wilson | efbae20 | 2014-10-24 14:23:45 -0400 | [diff] [blame^] | 42 | virtualinterfacesList, err := virtualinterfaces.ExtractVirtualInterfaces(page) |
| 43 | th.AssertNoErr(t, err) |
Jon Perritt | 26ff5b7 | 2014-10-23 11:54:39 -0500 | [diff] [blame] | 44 | |
Ash Wilson | efbae20 | 2014-10-24 14:23:45 -0400 | [diff] [blame^] | 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 | } |
Jon Perritt | 26ff5b7 | 2014-10-23 11:54:39 -0500 | [diff] [blame] | 49 | |
Ash Wilson | efbae20 | 2014-10-24 14:23:45 -0400 | [diff] [blame^] | 50 | return true, nil |
| 51 | }) |
| 52 | th.CheckNoErr(t, err) |
Jon Perritt | 26ff5b7 | 2014-10-23 11:54:39 -0500 | [diff] [blame] | 53 | } |