github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/qos/policies/doc.go (about) 1 /* 2 Package policies provides information and interaction with the QoS policy extension 3 for the OpenStack Networking service. 4 5 Example to Get a Port with a QoS policy 6 7 var portWithQoS struct { 8 ports.Port 9 policies.QoSPolicyExt 10 } 11 12 portID := "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2" 13 14 err = ports.Get(client, portID).ExtractInto(&portWithQoS) 15 if err != nil { 16 log.Fatal(err) 17 } 18 19 fmt.Printf("Port: %+v\n", portWithQoS) 20 21 Example to Create a Port with a QoS policy 22 23 var portWithQoS struct { 24 ports.Port 25 policies.QoSPolicyExt 26 } 27 28 policyID := "d6ae28ce-fcb5-4180-aa62-d260a27e09ae" 29 networkID := "7069db8d-e817-4b39-a654-d2dd76e73d36" 30 31 portCreateOpts := ports.CreateOpts{ 32 NetworkID: networkID, 33 } 34 35 createOpts := policies.PortCreateOptsExt{ 36 CreateOptsBuilder: portCreateOpts, 37 QoSPolicyID: policyID, 38 } 39 40 err = ports.Create(client, createOpts).ExtractInto(&portWithQoS) 41 if err != nil { 42 panic(err) 43 } 44 45 fmt.Printf("Port: %+v\n", portWithQoS) 46 47 Example to Add a QoS policy to an existing Port 48 49 var portWithQoS struct { 50 ports.Port 51 policies.QoSPolicyExt 52 } 53 54 portUpdateOpts := ports.UpdateOpts{} 55 56 policyID := "d6ae28ce-fcb5-4180-aa62-d260a27e09ae" 57 58 updateOpts := policies.PortUpdateOptsExt{ 59 UpdateOptsBuilder: portUpdateOpts, 60 QoSPolicyID: &policyID, 61 } 62 63 err := ports.Update(client, "65c0ee9f-d634-4522-8954-51021b570b0d", updateOpts).ExtractInto(&portWithQoS) 64 if err != nil { 65 panic(err) 66 } 67 68 fmt.Printf("Port: %+v\n", portWithQoS) 69 70 Example to Delete a QoS policy from the existing Port 71 72 var portWithQoS struct { 73 ports.Port 74 policies.QoSPolicyExt 75 } 76 77 portUpdateOpts := ports.UpdateOpts{} 78 79 policyID := "" 80 81 updateOpts := policies.PortUpdateOptsExt{ 82 UpdateOptsBuilder: portUpdateOpts, 83 QoSPolicyID: &policyID, 84 } 85 86 err := ports.Update(client, "65c0ee9f-d634-4522-8954-51021b570b0d", updateOpts).ExtractInto(&portWithQoS) 87 if err != nil { 88 panic(err) 89 } 90 91 fmt.Printf("Port: %+v\n", portWithQoS) 92 93 Example to Get a Network with a QoS policy 94 95 var networkWithQoS struct { 96 networks.Network 97 policies.QoSPolicyExt 98 } 99 100 networkID := "46d4bfb9-b26e-41f3-bd2e-e6dcc1ccedb2" 101 102 err = networks.Get(client, networkID).ExtractInto(&networkWithQoS) 103 if err != nil { 104 log.Fatal(err) 105 } 106 107 fmt.Printf("Network: %+v\n", networkWithQoS) 108 109 Example to Create a Network with a QoS policy 110 111 var networkWithQoS struct { 112 networks.Network 113 policies.QoSPolicyExt 114 } 115 116 policyID := "d6ae28ce-fcb5-4180-aa62-d260a27e09ae" 117 networkID := "7069db8d-e817-4b39-a654-d2dd76e73d36" 118 119 networkCreateOpts := networks.CreateOpts{ 120 NetworkID: networkID, 121 } 122 123 createOpts := policies.NetworkCreateOptsExt{ 124 CreateOptsBuilder: networkCreateOpts, 125 QoSPolicyID: policyID, 126 } 127 128 err = networks.Create(client, createOpts).ExtractInto(&networkWithQoS) 129 if err != nil { 130 panic(err) 131 } 132 133 fmt.Printf("Network: %+v\n", networkWithQoS) 134 135 Example to add a QoS policy to an existing Network 136 137 var networkWithQoS struct { 138 networks.Network 139 policies.QoSPolicyExt 140 } 141 142 networkUpdateOpts := networks.UpdateOpts{} 143 144 policyID := "d6ae28ce-fcb5-4180-aa62-d260a27e09ae" 145 146 updateOpts := policies.NetworkUpdateOptsExt{ 147 UpdateOptsBuilder: networkUpdateOpts, 148 QoSPolicyID: &policyID, 149 } 150 151 err := networks.Update(client, "65c0ee9f-d634-4522-8954-51021b570b0d", updateOpts).ExtractInto(&networkWithQoS) 152 if err != nil { 153 panic(err) 154 } 155 156 fmt.Printf("Network: %+v\n", networkWithQoS) 157 158 Example to delete a QoS policy from the existing Network 159 160 var networkWithQoS struct { 161 networks.Network 162 policies.QoSPolicyExt 163 } 164 165 networkUpdateOpts := networks.UpdateOpts{} 166 167 policyID := "" 168 169 updateOpts := policies.NetworkUpdateOptsExt{ 170 UpdateOptsBuilder: networkUpdateOpts, 171 QoSPolicyID: &policyID, 172 } 173 174 err := networks.Update(client, "65c0ee9f-d634-4522-8954-51021b570b0d", updateOpts).ExtractInto(&networkWithQoS) 175 if err != nil { 176 panic(err) 177 } 178 179 fmt.Printf("Network: %+v\n", networkWithQoS) 180 181 Example to List QoS policies 182 183 shared := true 184 listOpts := policies.ListOpts{ 185 Name: "shared-policy", 186 Shared: &shared, 187 } 188 189 allPages, err := policies.List(networkClient, listOpts).AllPages() 190 if err != nil { 191 panic(err) 192 } 193 194 allPolicies, err := policies.ExtractPolicies(allPages) 195 if err != nil { 196 panic(err) 197 } 198 199 for _, policy := range allPolicies { 200 fmt.Printf("%+v\n", policy) 201 } 202 203 Example to Get a specific QoS policy 204 205 policyID := "30a57f4a-336b-4382-8275-d708babd2241" 206 207 policy, err := policies.Get(networkClient, policyID).Extract() 208 if err != nil { 209 panic(err) 210 } 211 212 fmt.Printf("%+v\n", policy) 213 214 Example to Create a QoS policy 215 216 createOpts := policies.CreateOpts{ 217 Name: "shared-default-policy", 218 Shared: true, 219 IsDefault: true, 220 } 221 222 policy, err := policies.Create(networkClient, createOpts).Extract() 223 if err != nil { 224 panic(err) 225 } 226 227 fmt.Printf("%+v\n", policy) 228 229 Example to Update a QoS policy 230 231 shared := true 232 isDefault := false 233 opts := policies.UpdateOpts{ 234 Name: "new-name", 235 Shared: &shared, 236 IsDefault: &isDefault, 237 } 238 239 policyID := "30a57f4a-336b-4382-8275-d708babd2241" 240 241 policy, err := policies.Update(networkClient, policyID, opts).Extract() 242 if err != nil { 243 panic(err) 244 } 245 246 fmt.Printf("%+v\n", policy) 247 248 Example to Delete a QoS policy 249 250 policyID := "30a57f4a-336b-4382-8275-d708babd2241" 251 252 err := policies.Delete(networkClient, policyID).ExtractErr() 253 if err != nil { 254 panic(err) 255 } 256 */ 257 package policies