Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 1 | // +build acceptance compute servers |
| 2 | |
| 3 | package v2 |
| 4 | |
| 5 | import ( |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 6 | "testing" |
| 7 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 8 | "github.com/gophercloud/gophercloud/acceptance/clients" |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame^] | 9 | "github.com/gophercloud/gophercloud/acceptance/tools" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 10 | "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/networks" |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 11 | ) |
| 12 | |
Joe Topjian | 924f701 | 2016-07-25 18:19:17 +0000 | [diff] [blame] | 13 | func TestNetworksList(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 14 | client, err := clients.NewComputeV2Client() |
Joe Topjian | 924f701 | 2016-07-25 18:19:17 +0000 | [diff] [blame] | 15 | if err != nil { |
| 16 | t.Fatalf("Unable to create a compute client: %v", err) |
| 17 | } |
| 18 | |
| 19 | allPages, err := networks.List(client).AllPages() |
| 20 | if err != nil { |
| 21 | t.Fatalf("Unable to list networks: %v", err) |
| 22 | } |
| 23 | |
| 24 | allNetworks, err := networks.ExtractNetworks(allPages) |
| 25 | if err != nil { |
| 26 | t.Fatalf("Unable to list networks: %v", err) |
| 27 | } |
| 28 | |
| 29 | for _, network := range allNetworks { |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame^] | 30 | tools.PrintResource(t, network) |
Joe Topjian | 924f701 | 2016-07-25 18:19:17 +0000 | [diff] [blame] | 31 | } |
| 32 | } |
| 33 | |
| 34 | func TestNetworksGet(t *testing.T) { |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 35 | choices, err := clients.AcceptanceTestChoicesFromEnv() |
Joe Topjian | 924f701 | 2016-07-25 18:19:17 +0000 | [diff] [blame] | 36 | if err != nil { |
| 37 | t.Fatal(err) |
| 38 | } |
| 39 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 40 | client, err := clients.NewComputeV2Client() |
Joe Topjian | 924f701 | 2016-07-25 18:19:17 +0000 | [diff] [blame] | 41 | if err != nil { |
| 42 | t.Fatalf("Unable to create a compute client: %v", err) |
| 43 | } |
| 44 | |
Joe Topjian | 1c15e3f | 2016-08-08 10:48:38 -0600 | [diff] [blame] | 45 | networkID, err := GetNetworkIDFromNetworks(t, client, choices.NetworkName) |
Joe Topjian | 924f701 | 2016-07-25 18:19:17 +0000 | [diff] [blame] | 46 | if err != nil { |
| 47 | t.Fatal(err) |
| 48 | } |
| 49 | |
| 50 | network, err := networks.Get(client, networkID).Extract() |
| 51 | if err != nil { |
| 52 | t.Fatalf("Unable to get network %s: %v", networkID, err) |
| 53 | } |
| 54 | |
Joe Topjian | 66a046c | 2017-01-19 22:07:26 -0700 | [diff] [blame^] | 55 | tools.PrintResource(t, network) |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 56 | } |