func TestCreateDestroyServer(t *testing.T) {
	choices, err := ComputeChoicesFromEnv()
	if err != nil {
		t.Fatal(err)
	}

	client, err := newClient()
	if err != nil {
		t.Fatalf("Unable to create a compute client: %v", err)
	}

	server, err := createServer(t, client, choices)
	if err != nil {
		t.Fatalf("Unable to create server: %v", err)
	}
	defer func() {
		servers.Delete(client, server.ID)
		t.Logf("Server deleted.")
	}()

	if err = waitForStatus(client, server, "ACTIVE"); err != nil {
		t.Fatalf("Unable to wait for server: %v", err)
	}

	pager := servers.ListAddresses(client, server.ID)
	pager.EachPage(func(page pagination.Page) (bool, error) {
		networks, err := servers.ExtractAddresses(page)
		if err != nil {
			return false, err
		}

		for n, a := range networks {
			t.Logf("%s: %+v\n", n, a)
		}
		return true, nil
	})

	pager = servers.ListAddressesByNetwork(client, server.ID, choices.NetworkName)
	pager.EachPage(func(page pagination.Page) (bool, error) {
		addresses, err := servers.ExtractNetworkAddresses(page)
		if err != nil {
			return false, err
		}

		for _, a := range addresses {
			t.Logf("%+v\n", a)
		}
		return true, nil
	})
}
Exemple #2
0
// ListAddressesByNetwork makes a request against the API to list the servers IP addresses
// for the given network.
func ListAddressesByNetwork(client *gophercloud.ServiceClient, id, network string) pagination.Pager {
	return os.ListAddressesByNetwork(client, id, network)
}