Esempio n. 1
0
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
	})
}
Esempio n. 2
0
// ExtractNetworkAddresses interprets the results of a single page from a ListAddressesByNetwork() call, producing a map of Address slices.
func ExtractNetworkAddresses(page pagination.Page) ([]os.Address, error) {
	return os.ExtractNetworkAddresses(page)
}