Form the non contiguous ranges based on currently assigned range in physical network
(apiclient, zoneid)
| 1200 | |
| 1201 | |
| 1202 | def setNonContiguousVlanIds(apiclient, zoneid): |
| 1203 | """ |
| 1204 | Form the non contiguous ranges based on currently assigned range in physical network |
| 1205 | """ |
| 1206 | |
| 1207 | NonContigVlanIdsAcquired = False |
| 1208 | |
| 1209 | list_physical_networks_response = PhysicalNetwork.list( |
| 1210 | apiclient, |
| 1211 | zoneid=zoneid |
| 1212 | ) |
| 1213 | assert isinstance(list_physical_networks_response, list) |
| 1214 | assert len( |
| 1215 | list_physical_networks_response) > 0, "No physical networks found in zone %s" % zoneid |
| 1216 | |
| 1217 | for physical_network in list_physical_networks_response: |
| 1218 | if not hasattr(physical_network, 'vlan'): |
| 1219 | continue |
| 1220 | |
| 1221 | vlans = xsplit(physical_network.vlan, ['-', ',']) |
| 1222 | |
| 1223 | assert len(vlans) > 0 |
| 1224 | assert int(vlans[0]) < int( |
| 1225 | vlans[-1]), "VLAN range %s was improperly split" % physical_network.vlan |
| 1226 | |
| 1227 | # Keep some gap between existing vlan and the new vlans which we are going to add |
| 1228 | # So that they are non contiguous |
| 1229 | |
| 1230 | non_contig_end_vlan_id = int(vlans[-1]) + 6 |
| 1231 | non_contig_start_vlan_id = int(vlans[0]) - 6 |
| 1232 | |
| 1233 | # Form ranges which are consecutive to existing ranges but not immediately contiguous |
| 1234 | # There should be gap in between existing range and new non contiguous |
| 1235 | # ranage |
| 1236 | |
| 1237 | # If you can't add range after existing range, because it's crossing 4095, then |
| 1238 | # select VLAN ids before the existing range such that they are greater than 0, and |
| 1239 | # then add this non contiguoud range |
| 1240 | vlan = {"partial_range": ["", ""], "full_range": ""} |
| 1241 | |
| 1242 | if non_contig_end_vlan_id < 4095: |
| 1243 | vlan["partial_range"][0] = str( |
| 1244 | non_contig_end_vlan_id - 4) + '-' + str(non_contig_end_vlan_id - 3) |
| 1245 | vlan["partial_range"][1] = str( |
| 1246 | non_contig_end_vlan_id - 1) + '-' + str(non_contig_end_vlan_id) |
| 1247 | vlan["full_range"] = str( |
| 1248 | non_contig_end_vlan_id - 4) + '-' + str(non_contig_end_vlan_id) |
| 1249 | NonContigVlanIdsAcquired = True |
| 1250 | |
| 1251 | elif non_contig_start_vlan_id > 0: |
| 1252 | vlan["partial_range"][0] = str( |
| 1253 | non_contig_start_vlan_id) + '-' + str(non_contig_start_vlan_id + 1) |
| 1254 | vlan["partial_range"][1] = str( |
| 1255 | non_contig_start_vlan_id + 3) + '-' + str(non_contig_start_vlan_id + 4) |
| 1256 | vlan["full_range"] = str( |
| 1257 | non_contig_start_vlan_id) + '-' + str(non_contig_start_vlan_id + 4) |
| 1258 | NonContigVlanIdsAcquired = True |
| 1259 |