github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/internal/acceptance/openstack/networking/v2/extensions/trunks/trunks.go (about)

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