github.com/gophercloud/gophercloud@v1.11.0/internal/acceptance/openstack/networking/v2/extensions/trunks/trunks.go (about) 1 package trunks 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/trunks" 9 ) 10 11 func CreateTrunk(t *testing.T, client *gophercloud.ServiceClient, parentPortID string, subportIDs ...string) (trunk *trunks.Trunk, err error) { 12 trunkName := tools.RandomString("TESTACC-", 8) 13 iTrue := true 14 opts := trunks.CreateOpts{ 15 Name: trunkName, 16 Description: "Trunk created by gophercloud", 17 AdminStateUp: &iTrue, 18 PortID: parentPortID, 19 } 20 21 opts.Subports = make([]trunks.Subport, len(subportIDs)) 22 for id, subportID := range subportIDs { 23 opts.Subports[id] = trunks.Subport{ 24 SegmentationID: id + 1, 25 SegmentationType: "vlan", 26 PortID: subportID, 27 } 28 } 29 30 t.Logf("Attempting to create trunk: %s", opts.Name) 31 trunk, err = trunks.Create(client, opts).Extract() 32 if err == nil { 33 t.Logf("Successfully created trunk") 34 } 35 return 36 } 37 38 func DeleteTrunk(t *testing.T, client *gophercloud.ServiceClient, trunkID string) { 39 t.Logf("Attempting to delete trunk: %s", trunkID) 40 err := trunks.Delete(client, trunkID).ExtractErr() 41 if err != nil { 42 t.Fatalf("Unable to delete trunk %s: %v", trunkID, err) 43 } 44 45 t.Logf("Deleted trunk: %s", trunkID) 46 }