PageRenderTime 45ms CodeModel.GetById 40ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/subnetpools/subnetpools.go

https://gitlab.com/unofficial-mirrors/openshift-origin
Go | 45 lines | 32 code | 9 blank | 4 comment | 4 complexity | fda25712b26d4a7c76c17779cccbf9f4 MD5 | raw file
 1package v2
 2
 3import (
 4	"testing"
 5
 6	"github.com/gophercloud/gophercloud"
 7	"github.com/gophercloud/gophercloud/acceptance/tools"
 8	"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools"
 9)
10
11// CreateSubnetPool will create a subnetpool. An error will be returned if the
12// subnetpool could not be created.
13func CreateSubnetPool(t *testing.T, client *gophercloud.ServiceClient) (*subnetpools.SubnetPool, error) {
14	subnetPoolName := tools.RandomString("TESTACC-", 8)
15	subnetPoolPrefixes := []string{
16		"10.0.0.0/8",
17	}
18	createOpts := subnetpools.CreateOpts{
19		Name:     subnetPoolName,
20		Prefixes: subnetPoolPrefixes,
21	}
22
23	t.Logf("Attempting to create a subnetpool: %s", subnetPoolName)
24
25	subnetPool, err := subnetpools.Create(client, createOpts).Extract()
26	if err != nil {
27		return nil, err
28	}
29
30	t.Logf("Successfully created the subnetpool.")
31	return subnetPool, nil
32}
33
34// DeleteSubnetPool will delete a subnetpool with a specified ID.
35// A fatal error will occur if the delete was not successful.
36func DeleteSubnetPool(t *testing.T, client *gophercloud.ServiceClient, subnetPoolID string) {
37	t.Logf("Attempting to delete the subnetpool: %s", subnetPoolID)
38
39	err := subnetpools.Delete(client, subnetPoolID).ExtractErr()
40	if err != nil {
41		t.Fatalf("Unable to delete subnetpool %s: %v", subnetPoolID, err)
42	}
43
44	t.Logf("Deleted subnetpool: %s", subnetPoolID)
45}