github.com/gophercloud/gophercloud@v1.11.0/internal/acceptance/openstack/networking/v2/extensions/subnetpools/subnetpools.go (about) 1 package v2 2 3 import ( 4 "testing" 5 6 "github.com/gophercloud/gophercloud" 7 "github.com/gophercloud/gophercloud/internal/acceptance/tools" 8 "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools" 9 th "github.com/gophercloud/gophercloud/testhelper" 10 ) 11 12 // CreateSubnetPool will create a subnetpool. An error will be returned if the 13 // subnetpool could not be created. 14 func CreateSubnetPool(t *testing.T, client *gophercloud.ServiceClient) (*subnetpools.SubnetPool, error) { 15 subnetPoolName := tools.RandomString("TESTACC-", 8) 16 subnetPoolDescription := tools.RandomString("TESTACC-DESC-", 8) 17 subnetPoolPrefixes := []string{ 18 "10.0.0.0/8", 19 } 20 createOpts := subnetpools.CreateOpts{ 21 Name: subnetPoolName, 22 Description: subnetPoolDescription, 23 Prefixes: subnetPoolPrefixes, 24 DefaultPrefixLen: 24, 25 } 26 27 t.Logf("Attempting to create a subnetpool: %s", subnetPoolName) 28 29 subnetPool, err := subnetpools.Create(client, createOpts).Extract() 30 if err != nil { 31 return nil, err 32 } 33 34 t.Logf("Successfully created the subnetpool.") 35 36 th.AssertEquals(t, subnetPool.Name, subnetPoolName) 37 th.AssertEquals(t, subnetPool.Description, subnetPoolDescription) 38 39 return subnetPool, nil 40 } 41 42 // DeleteSubnetPool will delete a subnetpool with a specified ID. 43 // A fatal error will occur if the delete was not successful. 44 func DeleteSubnetPool(t *testing.T, client *gophercloud.ServiceClient, subnetPoolID string) { 45 t.Logf("Attempting to delete the subnetpool: %s", subnetPoolID) 46 47 err := subnetpools.Delete(client, subnetPoolID).ExtractErr() 48 if err != nil { 49 t.Fatalf("Unable to delete subnetpool %s: %v", subnetPoolID, err) 50 } 51 52 t.Logf("Deleted subnetpool: %s", subnetPoolID) 53 }