PageRenderTime 36ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/sharedfilesystems/v2/sharenetworks.go

https://gitlab.com/unofficial-mirrors/openshift-origin
Go | 60 lines | 45 code | 10 blank | 5 comment | 5 complexity | 1d330baec6b9383e4bb8131fc1c5eb13 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/sharedfilesystems/v2/sharenetworks"
  7. )
  8. // CreateShareNetwork will create a share network with a random name. An
  9. // error will be returned if the share network was unable to be created.
  10. func CreateShareNetwork(t *testing.T, client *gophercloud.ServiceClient) (*sharenetworks.ShareNetwork, error) {
  11. if testing.Short() {
  12. t.Skip("Skipping test that requires share network creation in short mode.")
  13. }
  14. shareNetworkName := tools.RandomString("ACPTTEST", 16)
  15. t.Logf("Attempting to create share network: %s", shareNetworkName)
  16. createOpts := sharenetworks.CreateOpts{
  17. Name: shareNetworkName,
  18. Description: "This is a shared network",
  19. }
  20. shareNetwork, err := sharenetworks.Create(client, createOpts).Extract()
  21. if err != nil {
  22. return shareNetwork, err
  23. }
  24. return shareNetwork, nil
  25. }
  26. // DeleteShareNetwork will delete a share network. An error will occur if
  27. // the share network was unable to be deleted.
  28. func DeleteShareNetwork(t *testing.T, client *gophercloud.ServiceClient, shareNetwork *sharenetworks.ShareNetwork) {
  29. err := sharenetworks.Delete(client, shareNetwork.ID).ExtractErr()
  30. if err != nil {
  31. t.Fatalf("Failed to delete share network %s: %v", shareNetwork.ID, err)
  32. }
  33. t.Logf("Deleted share network: %s", shareNetwork.ID)
  34. }
  35. // PrintShareNetwork will print a share network and all of its attributes.
  36. func PrintShareNetwork(t *testing.T, sharenetwork *sharenetworks.ShareNetwork) {
  37. t.Logf("ID: %s", sharenetwork.ID)
  38. t.Logf("Project ID: %s", sharenetwork.ProjectID)
  39. t.Logf("Neutron network ID: %s", sharenetwork.NeutronNetID)
  40. t.Logf("Neutron sub-network ID: %s", sharenetwork.NeutronSubnetID)
  41. t.Logf("Nova network ID: %s", sharenetwork.NovaNetID)
  42. t.Logf("Network type: %s", sharenetwork.NetworkType)
  43. t.Logf("Segmentation ID: %d", sharenetwork.SegmentationID)
  44. t.Logf("CIDR: %s", sharenetwork.CIDR)
  45. t.Logf("IP version: %d", sharenetwork.IPVersion)
  46. t.Logf("Name: %s", sharenetwork.Name)
  47. t.Logf("Description: %s", sharenetwork.Description)
  48. t.Logf("Created at: %v", sharenetwork.CreatedAt)
  49. t.Logf("Updated at: %v", sharenetwork.UpdatedAt)
  50. }