~ubuntu-branches/ubuntu/raring/quantum/raring

« back to all changes in this revision

Viewing changes to quantum/plugins/linuxbridge/db/l2network_db_v2.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-09-21 13:01:18 UTC
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20120921130118-6x31znohp1psfc74
Tags: upstream-2012.2~rc2
ImportĀ upstreamĀ versionĀ 2012.2~rc2

Show diffs side-by-side

added added

removed removed

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