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