diff options
author | Steve McIntyre <steve.mcintyre@linaro.org> | 2014-12-23 22:28:30 +0000 |
---|---|---|
committer | Steve McIntyre <steve.mcintyre@linaro.org> | 2014-12-23 22:28:30 +0000 |
commit | fc5112453920415c0a6d765862307df294af070d (patch) | |
tree | 072cffd3cddab03288db5d3c39b44971bba742e8 /util.py | |
parent | 5904b87ba6db838db0da8cde1996db209cbaa67c (diff) | |
download | vland-fc5112453920415c0a6d765862307df294af070d.tar.gz |
More tweaks to auto_import_switch() after testing:
More debug on the daemon side
Cope with different VLAN setups for trunk ports
We can't use set_port_mode() - add trunk ports by hand here
Change-Id: Id8e001f5cf5f8a40cb4e4f88a9f1241aaf77f323
Diffstat (limited to 'util.py')
-rw-r--r-- | util.py | 44 |
1 files changed, 34 insertions, 10 deletions
@@ -632,6 +632,8 @@ class VlanUtil: if not switch_name in config.switches: raise InputError("Switch name %s not defined in config" % switch_name) + print 'args look ok' + # 2. Now start reading config from the switch try: s = self.get_switch_driver(switch_name, config) @@ -643,12 +645,16 @@ class VlanUtil: raise # DON'T create the switch record in the DB first - we'll want - # to create VLANs on *other* switches, and it's easier to do that before we've added our new switch + # to create VLANs on *other* switches, and it's easier to do + # that before we've added our new switch new_vlan_tags = [] # Grab the VLANs defined on this switch vlan_tags = s.vlan_get_list() + + print ' found %d vlans on the switch' % len(vlan_tags) + for vlan_tag in vlan_tags: vlan_name = s.vlan_get_name(vlan_tag) @@ -661,8 +667,8 @@ class VlanUtil: # If this VLAN tag is not already in the DB, we'll need to # add it there and to all the other switches (and their # trunk ports!) too. + vlan_id = db.get_vlan_id_by_tag(vlan_tag) if vlan_id is not state.default_vlan_id: - vlan_id = db.get_vlan_id_by_tag(vlan_tag) if vlan_id is not None: vlan_db_name = db.get_vlan_name_by_id(vlan_id) if vlan_name != vlan_db_name: @@ -690,7 +696,9 @@ class VlanUtil: # And now the ports trunk_ports = [] ports = s.switch_get_port_names() + print ' found %d ports on the switch' % len(ports) for port_name in ports: + print ' trying to import port %s' % port_name port_id = None port_mode = s.port_get_mode(port_name) if port_mode == 'access': @@ -700,31 +708,47 @@ class VlanUtil: # import if needed. port_vlan = s.port_get_access_vlan(port_name) port_id = db.create_port(switch_id, port_name, port_vlan, port_vlan) + print ' access port, VLAN %d' % int(port_vlan) # Nothing further needed elif port_mode == 'trunk': + print ' trunk port' # Trunk ports are a little more involved. First, # create the port in the DB, setting the VLANs to the # first VLAN found on the trunk port. This will *also* # be in access mode by default, and unlocked. port_vlans = s.port_get_trunk_vlan_list(port_name) - if port_vlans == 'ALL': + print ' trunk port has VLANs:' + print port_vlans + if port_vlans is None or 'ALL' in port_vlans: port_vlans = (state.default_vlan_id,) # easy for our purposes port_id = db.create_port(switch_id, port_name, port_vlans[0], port_vlans[0]) # Append to a list of trunk ports that we will need to # modify once we're done trunk_ports.append(port_id) + else: + raise CriticalError("Unrecognised port port mode %s???" % port_mode) + + print " Added port %s, got port ID %d" % (port_name, port_id) + + # Now, on each trunk port on the switch, we need to add all + # the VLANs already configured across our system + if not 'TrunkWildCardVlans' in s.switch_get_capabilities(): + for port_id in trunk_ports: + port = db.get_port_by_id(port_id) + db.set_port_mode(port_id, "trunk") + + for vlan in db.all_vlans(): + if vlan.vlan_id is not state.default_vlan_id: + print "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 in the main loop here + # Done with this switch \o/ + s.switch_save_running_config() s.switch_disconnect() del s - # Now on each trunk port we need to add all the VLANs across - # our system, so it's ready to go. Each time we call this, it - # will connect, disconnect, save config etc. - for port_id in trunk_ports: - self.set_port_mode(state, port_id, 'trunk') - ret = {} ret['switch_id'] = switch_id ret['num_ports_added'] = len(ports) |