diff options
author | Steve McIntyre <steve.mcintyre@linaro.org> | 2018-02-05 18:52:59 +0000 |
---|---|---|
committer | Steve McIntyre <steve.mcintyre@linaro.org> | 2018-02-05 18:52:59 +0000 |
commit | e6ff7f0c227c5106703f23da17486e59d67cd833 (patch) | |
tree | 0d2ce291f5da16d641bdc8b54243e125eea21aab | |
parent | 3e4ec440e94d3bcdf42e2fb1f71f2c40bfec788d (diff) |
Fix up util API code to match the RealDict database changes
Change-Id: Iace86db00be309ca28a8c2febbf079c6328c298d
-rw-r--r-- | util.py | 82 |
1 files changed, 41 insertions, 41 deletions
@@ -291,7 +291,7 @@ class VlanUtil: try: for switch in db.all_switches(): trunk_ports = [] - switch_name = switch.name + switch_name = switch['name'] try: logging.debug('Adding new VLAN to switch %s', switch_name) # Get the right driver @@ -314,7 +314,7 @@ class VlanUtil: logging.debug('This switch does not need special trunk port handling') else: logging.debug('This switch needs special trunk port handling') - trunk_ports = db.get_trunk_port_names_by_switch(switch.switch_id) + trunk_ports = db.get_trunk_port_names_by_switch(switch['switch_id']) if trunk_ports is None: logging.debug("But it has no trunk ports defined") trunk_ports = [] @@ -331,7 +331,7 @@ class VlanUtil: del s except IOError as e: - logging.error('Failed to add VLAN %d to switch ID %d (%s): %s', tag, switch.switch_id, switch.name, e) + logging.error('Failed to add VLAN %d to switch ID %d (%s): %s', tag, switch['switch_id'], switch['name'], e) raise except IOError: @@ -386,7 +386,7 @@ class VlanUtil: vlan = db.get_vlan_by_id(vlan_id) if vlan is None: raise NotFoundError("VLAN ID %d does not exist" % vlan_id) - vlan_tag = vlan.tag + vlan_tag = vlan['tag'] ports = db.get_ports_by_current_vlan(vlan_id) if ports is not None: raise InputError("Cannot delete VLAN ID %d when it still has %d ports" % @@ -402,7 +402,7 @@ class VlanUtil: # 2. Now the switches try: for switch in db.all_switches(): - switch_name = switch.name + switch_name = switch['name'] trunk_ports = [] try: # Get the right driver @@ -420,7 +420,7 @@ class VlanUtil: logging.debug('This switch does not need special trunk port handling') else: logging.debug('This switch needs special trunk port handling') - trunk_ports = db.get_trunk_port_names_by_switch(switch.switch_id) + trunk_ports = db.get_trunk_port_names_by_switch(switch['switch_id']) if trunk_ports is None: logging.debug("But it has no trunk ports defined") trunk_ports = [] @@ -506,16 +506,16 @@ class VlanUtil: port = db.get_port_by_id(port_id) if port is None: raise NotFoundError("Port ID %d does not exist" % port_id) - if port.is_locked: + if port['is_locked']: raise InputError("Port ID %d is locked" % port_id) - if mode == 'trunk' and port.is_trunk: + if mode == 'trunk' and port['is_trunk']: raise InputError("Port ID %d is already in trunk mode" % port_id) - if mode == 'access' and not port.is_trunk: + if mode == 'access' and not port['is_trunk']: raise InputError("Port ID %d is already in access mode" % port_id) - base_vlan_tag = db.get_vlan_tag_by_id(port.base_vlan_id) + base_vlan_tag = db.get_vlan_tag_by_id(port['base_vlan_id']) # Get the right driver - switch_name = db.get_switch_name_by_id(port.switch_id) + switch_name = db.get_switch_name_by_id(port['switch_id']) s = self.get_switch_driver(switch_name, config) # 2. Now start configuring the switch @@ -528,36 +528,36 @@ class VlanUtil: raise try: - if port.is_trunk: + if port['is_trunk']: # 2a. We're going from a trunk port to an access port if 'TrunkWildCardVlans' in s.switch_get_capabilities(): logging.debug('This switch does not need special trunk port handling') else: logging.debug('This switch needs special trunk port handling') - vlans = s.port_get_trunk_vlan_list(port.name) + vlans = s.port_get_trunk_vlan_list(port['name']) if vlans is None: - logging.debug("But it has no VLANs defined on port %s", port.name) + logging.debug("But it has no VLANs defined on port %s", port['name']) vlans = [] else: - logging.debug('Found %d vlans that may need dropping on port %s', len(vlans), port.name) + logging.debug('Found %d vlans that may need dropping on port %s', len(vlans), port['name']) for vlan in vlans: if vlan != state.config.vland.default_vlan_tag: - s.port_remove_trunk_from_vlan(port.name, vlan) + s.port_remove_trunk_from_vlan(port['name'], vlan) - s.port_set_mode(port.name, "access") + s.port_set_mode(port['name'], "access") else: # 2b. We're going from an access port to a trunk port - s.port_set_access_vlan(port.name, base_vlan_tag) - s.port_set_mode(port.name, "trunk") + s.port_set_access_vlan(port['name'], base_vlan_tag) + s.port_set_mode(port['name'], "trunk") if 'TrunkWildCardVlans' in s.switch_get_capabilities(): logging.debug('This switch does not need special trunk port handling') else: vlans = db.all_vlans() for vlan in vlans: - if vlan.tag != state.config.vland.default_vlan_tag: - s.port_add_trunk_to_vlan(port.name, vlan.tag) + if vlan['tag'] != state.config.vland.default_vlan_tag: + s.port_add_trunk_to_vlan(port['name'], vlan['tag']) except IOError: logging.error('set_port_mode failed, resetting switch to recover') @@ -595,9 +595,9 @@ class VlanUtil: port = db.get_port_by_id(port_id) if port is None: raise NotFoundError("Port ID %d does not exist" % port_id) - if port.is_locked: + if port['is_locked']: raise InputError("Port ID %d is locked" % port_id) - if port.is_trunk: + if port['is_trunk']: raise InputError("Port ID %d is not an access port" % port_id) vlan = db.get_vlan_by_id(vlan_id) @@ -605,7 +605,7 @@ class VlanUtil: raise NotFoundError("VLAN ID %d does not exist" % vlan_id) # Get the right driver - switch_name = db.get_switch_name_by_id(port.switch_id) + switch_name = db.get_switch_name_by_id(port['switch_id']) s = self.get_switch_driver(switch_name, config) # 2. Now start configuring the switch @@ -618,7 +618,7 @@ class VlanUtil: raise try: - s.port_set_access_vlan(port.name, vlan.tag) + s.port_set_access_vlan(port['name'], vlan['tag']) except IOError: logging.error('set_current_vlan failed, resetting switch to recover') # Bugger. Looks like one of the switch calls above @@ -655,20 +655,20 @@ class VlanUtil: port = db.get_port_by_id(port_id) if port is None: raise NotFoundError("Port ID %d does not exist" % port_id) - if port.is_trunk: + if port['is_trunk']: raise InputError("Port ID %d is not an access port" % port_id) - if port.is_locked: + if port['is_locked']: raise InputError("Port ID %d is locked" % port_id) # Bail out early if we're *already* on the base VLAN. This is # not an error - if port.current_vlan_id == port.base_vlan_id: + if port['current_vlan_id'] == port['base_vlan_id']: return port_id - vlan = db.get_vlan_by_id(port.base_vlan_id) + vlan = db.get_vlan_by_id(port['base_vlan_id']) # Get the right driver - switch_name = db.get_switch_name_by_id(port.switch_id) + switch_name = db.get_switch_name_by_id(port['switch_id']) s = self.get_switch_driver(switch_name, config) # 2. Now start configuring the switch @@ -681,7 +681,7 @@ class VlanUtil: raise try: - s.port_set_access_vlan(port.name, vlan.tag) + s.port_set_access_vlan(port['name'], vlan['tag']) except IOError: logging.error('restore_base_vlan failed, resetting switch to recover') # Bugger. Looks like one of the switch calls above @@ -697,7 +697,7 @@ class VlanUtil: del s # 4. And update the DB - db.set_current_vlan(port_id, port.base_vlan_id) + db.set_current_vlan(port_id, port['base_vlan_id']) return port_id # If we're successful @@ -839,11 +839,11 @@ class VlanUtil: # Make sure this switch has all the VLANs we need for vlan in db.all_vlans(): - if vlan.tag != state.config.vland.default_vlan_tag: - if not vlan.tag in vlan_tags: - logging.debug("Adding VLAN tag %d to this switch", vlan.tag) - s.vlan_create(vlan.tag) - s.vlan_set_name(vlan.tag, vlan.name) + if vlan['tag'] != state.config.vland.default_vlan_tag: + if not vlan['tag'] in vlan_tags: + logging.debug("Adding VLAN tag %d to this switch", vlan['tag']) + s.vlan_create(vlan['tag']) + s.vlan_set_name(vlan['tag'], vlan['name']) # Now, on each trunk port on the switch, we need to add all # the VLANs already configured across our system @@ -852,10 +852,10 @@ class VlanUtil: port = db.get_port_by_id(port_id) for vlan in db.all_vlans(): - if vlan.vlan_id != state.default_vlan_id: - if not vlan.tag in port_vlans[port.name]: - logging.debug("Adding allowed VLAN tag %d to trunk port %s", vlan.tag, port.name) - s.port_add_trunk_to_vlan(port.name, vlan.tag) + if vlan['vlan_id'] != state.default_vlan_id: + if not vlan['tag'] in port_vlans[port['name']]: + logging.debug("Adding allowed VLAN tag %d to trunk port %s", vlan['tag'], port['name']) + s.port_add_trunk_to_vlan(port['name'], vlan['tag']) # Done with this switch \o/ s.switch_save_running_config() |