PageRenderTime 33ms CodeModel.GetById 11ms RepoModel.GetById 1ms 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
  1. package v2
  2. import (
  3. "testing"
  4. "github.com/gophercloud/gophercloud"
  5. "github.com/gophercloud/gophercloud/acceptance/tools"
  6. "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/subnetpools"
  7. )
  8. // CreateSubnetPool will create a subnetpool. An error will be returned if the
  9. // subnetpool could not be created.
  10. func CreateSubnetPool(t *testing.T, client *gophercloud.ServiceClient) (*subnetpools.SubnetPool, error) {
  11. subnetPoolName := tools.RandomString("TESTACC-", 8)
  12. subnetPoolPrefixes := []string{
  13. "10.0.0.0/8",
  14. }
  15. createOpts := subnetpools.CreateOpts{
  16. Name: subnetPoolName,
  17. Prefixes: subnetPoolPrefixes,
  18. }
  19. t.Logf("Attempting to create a subnetpool: %s", subnetPoolName)
  20. subnetPool, err := subnetpools.Create(client, createOpts).Extract()
  21. if err != nil {
  22. return nil, err
  23. }
  24. t.Logf("Successfully created the subnetpool.")
  25. return subnetPool, nil
  26. }
  27. // DeleteSubnetPool will delete a subnetpool with a specified ID.
  28. // A fatal error will occur if the delete was not successful.
  29. func DeleteSubnetPool(t *testing.T, client *gophercloud.ServiceClient, subnetPoolID string) {
  30. t.Logf("Attempting to delete the subnetpool: %s", subnetPoolID)
  31. err := subnetpools.Delete(client, subnetPoolID).ExtractErr()
  32. if err != nil {
  33. t.Fatalf("Unable to delete subnetpool %s: %v", subnetPoolID, err)
  34. }
  35. t.Logf("Deleted subnetpool: %s", subnetPoolID)
  36. }