40
40
def sync_network_states(network_vlan_ranges):
41
41
"""Synchronize network_states table with current configured VLAN ranges."""
43
# process vlan ranges for each physical network separately
44
for physical_network, vlan_ranges in network_vlan_ranges.iteritems():
46
# determine current configured allocatable vlans for this
49
for vlan_range in vlan_ranges:
50
vlan_ids |= set(xrange(vlan_range[0], vlan_range[1] + 1))
52
session = db.get_session()
43
session = db.get_session()
45
# get existing allocations for all physical networks
47
states = (session.query(l2network_models_v2.NetworkState).
50
if state.physical_network not in allocations:
51
allocations[state.physical_network] = set()
52
allocations[state.physical_network].add(state)
54
# process vlan ranges for each configured physical network
55
for physical_network, vlan_ranges in network_vlan_ranges.iteritems():
56
# determine current configured allocatable vlans for this
59
for vlan_range in vlan_ranges:
60
vlan_ids |= set(xrange(vlan_range[0], vlan_range[1] + 1))
54
62
# remove from table unallocated vlans not currently allocatable
56
states = (session.query(l2network_models_v2.NetworkState).
57
filter_by(physical_network=physical_network).
63
if physical_network in allocations:
64
for state in allocations[physical_network]:
61
66
# see if vlan is allocatable
62
67
vlan_ids.remove(state.vlan_id)
69
74
(state.vlan_id, physical_network))
70
75
session.delete(state)
71
except exc.NoResultFound:
76
del allocations[physical_network]
74
78
# add missing allocatable vlans to table
75
79
for vlan_id in sorted(vlan_ids):
84
# remove from table unallocated vlans for any unconfigured physical
86
for states in allocations.itervalues():
88
if not state.allocated:
89
LOG.debug("removing vlan %s on physical network %s"
91
(state.vlan_id, physical_network))
81
95
def get_network_state(physical_network, vlan_id):
82
96
"""Get state of specified network"""