1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
/*
Package trunks provides the ability to retrieve and manage trunks through the Neutron API.
Trunks allow you to multiplex multiple ports traffic on a single port. For example, you could
have a compute instance port be the parent port of a trunk and inside the VM run workloads
using other ports, without the need of plugging those ports.
Example of a new empty Trunk creation
iTrue := true
createOpts := trunks.CreateOpts{
Name: "gophertrunk",
Description: "Trunk created by gophercloud",
AdminStateUp: &iTrue,
PortID: "a6f0560c-b7a8-401f-bf6e-d0a5c851ae10",
}
trunk, err := trunks.Create(networkClient, createOpts).Extract()
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", trunk)
Example of a new Trunk creation with 2 subports
iTrue := true
createOpts := trunks.CreateOpts{
Name: "gophertrunk",
Description: "Trunk created by gophercloud",
AdminStateUp: &iTrue,
PortID: "a6f0560c-b7a8-401f-bf6e-d0a5c851ae10",
Subports: []trunks.Subport{
{
SegmentationID: 1,
SegmentationType: "vlan",
PortID: "bf4efcc0-b1c7-4674-81f0-31f58a33420a",
},
{
SegmentationID: 10,
SegmentationType: "vlan",
PortID: "2cf671b9-02b3-4121-9e85-e0af3548d112",
},
},
}
trunk, err := trunks.Create(client, createOpts).Extract()
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", trunk)
Example of deleting a Trunk
trunkID := "c36e7f2e-0c53-4742-8696-aee77c9df159"
err := trunks.Delete(networkClient, trunkID).ExtractErr()
if err != nil {
panic(err)
}
Example of listing Trunks
listOpts := trunks.ListOpts{}
allPages, err := trunks.List(networkClient, listOpts).AllPages()
if err != nil {
panic(err)
}
allTrunks, err := trunks.ExtractTrunks(allPages)
if err != nil {
panic(err)
}
for _, trunk := range allTrunks {
fmt.Printf("%+v\n", trunk)
}
Example of getting a Trunk
trunkID = "52d8d124-3dc9-4563-9fef-bad3187ecf2d"
trunk, err := trunks.Get(networkClient, trunkID).Extract()
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", trunk)
Example of updating a Trunk
trunkID := "c36e7f2e-0c53-4742-8696-aee77c9df159"
subports, err := trunks.GetSubports(client, trunkID).Extract()
iFalse := false
updateOpts := trunks.UpdateOpts{
AdminStateUp: &iFalse,
Name: "updated_gophertrunk",
Description: "trunk updated by gophercloud",
}
trunk, err = trunks.Update(networkClient, trunkID, updateOpts).Extract()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%+v\n", trunk)
Example of showing subports of a Trunk
trunkID := "c36e7f2e-0c53-4742-8696-aee77c9df159"
subports, err := trunks.GetSubports(client, trunkID).Extract()
fmt.Printf("%+v\n", subports)
Example of adding two subports to a Trunk
trunkID := "c36e7f2e-0c53-4742-8696-aee77c9df159"
addSubportsOpts := trunks.AddSubportsOpts{
Subports: []trunks.Subport{
{
SegmentationID: 1,
SegmentationType: "vlan",
PortID: "bf4efcc0-b1c7-4674-81f0-31f58a33420a",
},
{
SegmentationID: 10,
SegmentationType: "vlan",
PortID: "2cf671b9-02b3-4121-9e85-e0af3548d112",
},
},
}
trunk, err := trunks.AddSubports(client, trunkID, addSubportsOpts).Extract()
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", trunk)
Example of deleting two subports from a Trunk
trunkID := "c36e7f2e-0c53-4742-8696-aee77c9df159"
removeSubportsOpts := trunks.RemoveSubportsOpts{
Subports: []trunks.RemoveSubport{
{PortID: "bf4efcc0-b1c7-4674-81f0-31f58a33420a"},
{PortID: "2cf671b9-02b3-4121-9e85-e0af3548d112"},
},
}
trunk, err := trunks.RemoveSubports(networkClient, trunkID, removeSubportsOpts).Extract()
if err != nil {
panic(err)
}
fmt.Printf("%+v\n", trunk)
*/
package trunks
|