ehdou | 10f1f85 | 2016-10-14 20:58:23 +0300 | [diff] [blame] | 1 | package v2 |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/gophercloud/gophercloud" |
| 7 | "github.com/gophercloud/gophercloud/acceptance/tools" |
| 8 | "github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/sharenetworks" |
| 9 | ) |
| 10 | |
| 11 | // CreateShareNetwork will create a share network with a random name. An |
| 12 | // error will be returned if the share network was unable to be created. |
| 13 | func CreateShareNetwork(t *testing.T, client *gophercloud.ServiceClient) (*sharenetworks.ShareNetwork, error) { |
| 14 | if testing.Short() { |
| 15 | t.Skip("Skipping test that requires share network creation in short mode.") |
| 16 | } |
| 17 | |
| 18 | shareNetworkName := tools.RandomString("ACPTTEST", 16) |
| 19 | t.Logf("Attempting to create share network: %s", shareNetworkName) |
| 20 | |
| 21 | createOpts := sharenetworks.CreateOpts{ |
| 22 | Name: shareNetworkName, |
| 23 | Description: "This is a shared network", |
| 24 | } |
| 25 | |
| 26 | shareNetwork, err := sharenetworks.Create(client, createOpts).Extract() |
| 27 | if err != nil { |
| 28 | return shareNetwork, err |
| 29 | } |
| 30 | |
| 31 | return shareNetwork, nil |
| 32 | } |
| 33 | |
ehdou | 5368725 | 2016-10-14 22:10:13 +0300 | [diff] [blame] | 34 | // DeleteShareNetwork will delete a share network. An error will occur if |
| 35 | // the share network was unable to be deleted. |
| 36 | func DeleteShareNetwork(t *testing.T, client *gophercloud.ServiceClient, shareNetwork *sharenetworks.ShareNetwork) { |
| 37 | err := sharenetworks.Delete(client, shareNetwork.ID).ExtractErr() |
| 38 | if err != nil { |
| 39 | t.Fatalf("Failed to delete share network %s: %v", shareNetwork.ID, err) |
| 40 | } |
| 41 | |
| 42 | t.Logf("Deleted share network: %s", shareNetwork.ID) |
| 43 | } |
| 44 | |
ehdou | 10f1f85 | 2016-10-14 20:58:23 +0300 | [diff] [blame] | 45 | // PrintShareNetwork will print a share network and all of its attributes. |
| 46 | func PrintShareNetwork(t *testing.T, sharenetwork *sharenetworks.ShareNetwork) { |
| 47 | t.Logf("ID: %s", sharenetwork.ID) |
| 48 | t.Logf("Project ID: %s", sharenetwork.ProjectID) |
| 49 | t.Logf("Neutron network ID: %s", sharenetwork.NeutronNetID) |
| 50 | t.Logf("Neutron sub-network ID: %s", sharenetwork.NeutronSubnetID) |
| 51 | t.Logf("Nova network ID: %s", sharenetwork.NovaNetID) |
| 52 | t.Logf("Network type: %s", sharenetwork.NetworkType) |
| 53 | t.Logf("Segmentation ID: %d", sharenetwork.SegmentationID) |
| 54 | t.Logf("CIDR: %s", sharenetwork.CIDR) |
| 55 | t.Logf("IP version: %d", sharenetwork.IPVersion) |
| 56 | t.Logf("Name: %s", sharenetwork.Name) |
| 57 | t.Logf("Description: %s", sharenetwork.Description) |
ehdou | 0794333 | 2016-10-24 21:21:58 +0300 | [diff] [blame] | 58 | t.Logf("Created at: %v", sharenetwork.CreatedAt) |
| 59 | t.Logf("Updated at: %v", sharenetwork.UpdatedAt) |
ehdou | 10f1f85 | 2016-10-14 20:58:23 +0300 | [diff] [blame] | 60 | } |