blob: 745151829d84bccad0566fe0b419258305bcc56e [file] [log] [blame]
Joe Topjian99a06132015-02-22 05:06:25 +00001// +build acceptance compute servers
2
3package v2
4
5import (
Joe Topjian99a06132015-02-22 05:06:25 +00006 "testing"
7
Joe Topjian1c15e3f2016-08-08 10:48:38 -06008 "github.com/gophercloud/gophercloud/acceptance/clients"
Joe Topjian66a046c2017-01-19 22:07:26 -07009 "github.com/gophercloud/gophercloud/acceptance/tools"
Jon Perritt27249f42016-02-18 10:35:59 -060010 "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/networks"
Joe Topjian99a06132015-02-22 05:06:25 +000011)
12
Joe Topjian924f7012016-07-25 18:19:17 +000013func TestNetworksList(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060014 client, err := clients.NewComputeV2Client()
Joe Topjian924f7012016-07-25 18:19:17 +000015 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 Topjian66a046c2017-01-19 22:07:26 -070030 tools.PrintResource(t, network)
Joe Topjian924f7012016-07-25 18:19:17 +000031 }
32}
33
34func TestNetworksGet(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060035 choices, err := clients.AcceptanceTestChoicesFromEnv()
Joe Topjian924f7012016-07-25 18:19:17 +000036 if err != nil {
37 t.Fatal(err)
38 }
39
Joe Topjian1c15e3f2016-08-08 10:48:38 -060040 client, err := clients.NewComputeV2Client()
Joe Topjian924f7012016-07-25 18:19:17 +000041 if err != nil {
42 t.Fatalf("Unable to create a compute client: %v", err)
43 }
44
Joe Topjian1c15e3f2016-08-08 10:48:38 -060045 networkID, err := GetNetworkIDFromNetworks(t, client, choices.NetworkName)
Joe Topjian924f7012016-07-25 18:19:17 +000046 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 Topjian66a046c2017-01-19 22:07:26 -070055 tools.PrintResource(t, network)
Joe Topjian99a06132015-02-22 05:06:25 +000056}