github.com/gophercloud/gophercloud@v1.11.0/internal/acceptance/openstack/networking/v2/extensions/portsbinding/portsbinding.go (about) 1 package portsbinding 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/portsbinding" 9 "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" 10 th "github.com/gophercloud/gophercloud/testhelper" 11 ) 12 13 // PortWithBindingExt represents a port with the binding fields 14 type PortWithBindingExt struct { 15 ports.Port 16 portsbinding.PortsBindingExt 17 } 18 19 // CreatePortsbinding will create a port on the specified subnet. An error will be 20 // returned if the port could not be created. 21 func CreatePortsbinding(t *testing.T, client *gophercloud.ServiceClient, networkID, subnetID, hostID string, profile map[string]interface{}) (PortWithBindingExt, error) { 22 portName := tools.RandomString("TESTACC-", 8) 23 portDescription := tools.RandomString("TESTACC-PORT-DESC-", 8) 24 iFalse := false 25 26 t.Logf("Attempting to create port: %s", portName) 27 28 portCreateOpts := ports.CreateOpts{ 29 NetworkID: networkID, 30 Name: portName, 31 Description: portDescription, 32 AdminStateUp: &iFalse, 33 FixedIPs: []ports.IP{{SubnetID: subnetID}}, 34 } 35 36 createOpts := portsbinding.CreateOptsExt{ 37 CreateOptsBuilder: portCreateOpts, 38 HostID: hostID, 39 Profile: profile, 40 } 41 42 var s PortWithBindingExt 43 44 err := ports.Create(client, createOpts).ExtractInto(&s) 45 if err != nil { 46 return s, err 47 } 48 49 t.Logf("Successfully created port: %s", portName) 50 51 th.AssertEquals(t, s.Name, portName) 52 th.AssertEquals(t, s.Description, portDescription) 53 54 return s, nil 55 }