From b152907f95d784d1cf64d073772c9876fade8b91 Mon Sep 17 00:00:00 2001 From: Steve McIntyre Date: Tue, 23 Dec 2014 17:17:22 +0000 Subject: The detault VLAN will already exist, and will have a different name from switch to switch... Change-Id: I7df9c821b48bd71e9211cf3065b179b481486909 --- util.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'util.py') diff --git a/util.py b/util.py index 8a7caa8..800e7f2 100644 --- a/util.py +++ b/util.py @@ -655,26 +655,28 @@ class VlanUtil: # If a VLAN is already in the database, then that's easy - # we can just ignore it. However, we have to check that # there is not a different name for the existing VLAN tag - # - bail out if so... + # - bail out if so... UNLESS we're looking at the default + # VLAN # # 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 None: - vlan_db_name = db.get_vlan_name_by_id(vlan_id) - if vlan_name != vlan_db_name: - raise InputError("Can't add VLAN tag %d (name %s) for this switch - VLAN tag %d already exists in the database, but with a different name (%s)" % (vlan_tag, vlan_name, vlan_tag, vlan_db_name)) + 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: + raise InputError("Can't add VLAN tag %d (name %s) for this switch - VLAN tag %d already exists in the database, but with a different name (%s)" % (vlan_tag, vlan_name, vlan_tag, vlan_db_name)) - else: - # OK, we'll need to set up the new VLAN now. It can't - # be a base VLAN - switches don't have such a concept! - # Rather than create individually here, add to a - # list. *Only* once we've worked through all the - # switch's VLANs successfully (checking for existing - # records and possible clashes!) should we start - # committing changes - new_vlan_tags.append(vlan_tag) + else: + # OK, we'll need to set up the new VLAN now. It can't + # be a base VLAN - switches don't have such a concept! + # Rather than create individually here, add to a + # list. *Only* once we've worked through all the + # switch's VLANs successfully (checking for existing + # records and possible clashes!) should we start + # committing changes + new_vlan_tags.append(vlan_tag) # Now create the VLAN DB entries for vlan_tag in new_vlan_tags: -- cgit v1.2.3