github.com/gophercloud/gophercloud@v1.11.0/internal/acceptance/openstack/networking/v2/extensions/vlantransparent/vlantransparent.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/vlantransparent" 9 "github.com/gophercloud/gophercloud/openstack/networking/v2/networks" 10 th "github.com/gophercloud/gophercloud/testhelper" 11 ) 12 13 // VLANTransparentNetwork represents OpenStack V2 Networking Network with the 14 // "vlan-transparent" extension enabled. 15 type VLANTransparentNetwork struct { 16 networks.Network 17 vlantransparent.TransparentExt 18 } 19 20 // ListVLANTransparentNetworks will list networks with the "vlan-transparent" 21 // extension. An error will be returned networks could not be listed. 22 func ListVLANTransparentNetworks(t *testing.T, client *gophercloud.ServiceClient) ([]*VLANTransparentNetwork, error) { 23 iTrue := true 24 networkListOpts := networks.ListOpts{} 25 listOpts := vlantransparent.ListOptsExt{ 26 ListOptsBuilder: networkListOpts, 27 VLANTransparent: &iTrue, 28 } 29 30 var allNetworks []*VLANTransparentNetwork 31 32 t.Log("Attempting to list VLAN-transparent networks") 33 34 allPages, err := networks.List(client, listOpts).AllPages() 35 if err != nil { 36 return nil, err 37 } 38 err = networks.ExtractNetworksInto(allPages, &allNetworks) 39 if err != nil { 40 return nil, err 41 } 42 43 t.Log("Successfully retrieved networks.") 44 45 return allNetworks, nil 46 } 47 48 // CreateVLANTransparentNetwork will create a network with the 49 // "vlan-transparent" extension. An error will be returned if the network could 50 // not be created. 51 func CreateVLANTransparentNetwork(t *testing.T, client *gophercloud.ServiceClient) (*VLANTransparentNetwork, error) { 52 networkName := tools.RandomString("TESTACC-", 8) 53 networkCreateOpts := networks.CreateOpts{ 54 Name: networkName, 55 } 56 57 iTrue := true 58 createOpts := vlantransparent.CreateOptsExt{ 59 CreateOptsBuilder: &networkCreateOpts, 60 VLANTransparent: &iTrue, 61 } 62 63 t.Logf("Attempting to create a VLAN-transparent network: %s", networkName) 64 65 var network VLANTransparentNetwork 66 err := networks.Create(client, createOpts).ExtractInto(&network) 67 if err != nil { 68 return nil, err 69 } 70 71 t.Logf("Successfully created the network.") 72 73 th.AssertEquals(t, networkName, network.Name) 74 75 return &network, nil 76 } 77 78 // UpdateVLANTransparentNetwork will update a network with the 79 // "vlan-transparent" extension. An error will be returned if the network could 80 // not be updated. 81 func UpdateVLANTransparentNetwork(t *testing.T, client *gophercloud.ServiceClient, networkID string) (*VLANTransparentNetwork, error) { 82 networkName := tools.RandomString("TESTACC-NEW-", 6) 83 networkUpdateOpts := networks.UpdateOpts{ 84 Name: &networkName, 85 } 86 87 iFalse := false 88 updateOpts := vlantransparent.UpdateOptsExt{ 89 UpdateOptsBuilder: &networkUpdateOpts, 90 VLANTransparent: &iFalse, 91 } 92 93 t.Logf("Attempting to update a VLAN-transparent network: %s", networkID) 94 95 var network VLANTransparentNetwork 96 err := networks.Update(client, networkID, updateOpts).ExtractInto(&network) 97 if err != nil { 98 return nil, err 99 } 100 101 t.Logf("Successfully updated the network.") 102 103 th.AssertEquals(t, networkName, network.Name) 104 105 return &network, nil 106 }