PageRenderTime 25ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/github.com/gophercloud/gophercloud/acceptance/openstack/networking/v2/extensions/portsbinding/portsbinding.go

https://gitlab.com/unofficial-mirrors/openshift-origin
Go | 48 lines | 34 code | 11 blank | 3 comment | 2 complexity | a5cc4eb787bd1cd480466af923a9c588 MD5 | raw file
  1. package portsbinding
  2. import (
  3. "testing"
  4. "github.com/gophercloud/gophercloud"
  5. "github.com/gophercloud/gophercloud/acceptance/tools"
  6. "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/portsbinding"
  7. "github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
  8. )
  9. // PortWithBindingExt represents a port with the binding fields
  10. type PortWithBindingExt struct {
  11. ports.Port
  12. portsbinding.PortsBindingExt
  13. }
  14. // CreatePortsbinding will create a port on the specified subnet. An error will be
  15. // returned if the port could not be created.
  16. func CreatePortsbinding(t *testing.T, client *gophercloud.ServiceClient, networkID, subnetID, hostID string) (PortWithBindingExt, error) {
  17. portName := tools.RandomString("TESTACC-", 8)
  18. iFalse := false
  19. t.Logf("Attempting to create port: %s", portName)
  20. portCreateOpts := ports.CreateOpts{
  21. NetworkID: networkID,
  22. Name: portName,
  23. AdminStateUp: &iFalse,
  24. FixedIPs: []ports.IP{ports.IP{SubnetID: subnetID}},
  25. }
  26. createOpts := portsbinding.CreateOptsExt{
  27. CreateOptsBuilder: portCreateOpts,
  28. HostID: hostID,
  29. }
  30. var s PortWithBindingExt
  31. err := ports.Create(client, createOpts).ExtractInto(&s)
  32. if err != nil {
  33. return s, err
  34. }
  35. t.Logf("Successfully created port: %s", portName)
  36. return s, nil
  37. }