def _clear_vlan(self,
                    vfab_id,
                    vlanid,
                    ports,
                    config,
                    port_type=_EP,
                    vlan_type='untag',
                    lag_id=None,
                    commit=False):
        """Clear VLAN definition with specified ports.

        @param self  CFABdriver's instance
        @param vfab_id  the string of VFAB ID
        @param vlanid  the string of VLAN ID
        @param ports  a string of the ports which is separated by ','
        @param config a string of a candidate-config
        @return None or string of the modified ifgroups separated by ','
        """

        # (yushiro): ifgroup won't delete because it can not determine
        #            whether ifgroup is created by plugin or not.
        ifgroup_id = _search_ifgroup_index(ports, config, lag_id=lag_id)
        ifgroups = _get_ifgroups_of_vfab_vlan(vfab_id, vlanid, config)
        is_delete = False
        # Target ifgroup_id exists but vfab vlan definition does not exist or
        # ifgroup_id doesn't exist but vfab vlan definition exists.
        if None in [ifgroup_id, ifgroups]:
            LOG.debug(
                "ifgroup for %(p)s has already deleted."
                "Skip clear_vlan.", dict(p=ports))
            return None
        eliminated = fj_util.eliminate_val(ifgroups, ifgroup_id)
        # VLAN is configured with the only ifgroup_id
        if not eliminated:
            is_delete = True

        common_def = "vfab {vfab} vlan {vlan} {port_type} {vlan_type}"
        # Delete VFAB VLAN definition
        if is_delete:
            command = "no" + " " + common_def
            cmds = [
                command.format(vfab=vfab_id,
                               vlan=vlanid,
                               port_type=port_type,
                               vlan_type=vlan_type)
            ]
        # Reject ifgroup_id from VFAB VLAN definition
        else:
            command = common_def + " " + "{ifgroup}"
            cmds = [
                command.format(vfab=vfab_id,
                               vlan=vlanid,
                               port_type=port_type,
                               vlan_type=vlan_type,
                               ifgroup=eliminated)
            ]
        self.mgr.configure(cmds, commit=commit)
        return eliminated
    def _clear_vlan(self, vfab_id, vlanid, ports, config, port_type=_EP,
                    vlan_type='untag', lag_id=None, commit=False):
        """Clear VLAN definition with specified ports.

        @param self  CFABdriver's instance
        @param vfab_id  the string of VFAB ID
        @param vlanid  the string of VLAN ID
        @param ports  a string of the ports which is separated by ','
        @param config a string of a candidate-config
        @return None or string of the modified ifgroups separated by ','
        """

        # (yushiro): ifgroup won't delete because it can not determine
        #            whether ifgroup is created by plugin or not.
        ifgroup_id = _search_ifgroup_index(ports, config, lag_id=lag_id)
        ifgroups = _get_ifgroups_of_vfab_vlan(vfab_id, vlanid, config)
        is_delete = False
        # Target ifgroup_id exists but vfab vlan definition does not exist or
        # ifgroup_id doesn't exist but vfab vlan definition exists.
        if None in [ifgroup_id, ifgroups]:
            LOG.debug("ifgroup for %(p)s has already deleted."
                      "Skip clear_vlan.", dict(p=ports))
            return None
        eliminated = fj_util.eliminate_val(ifgroups, ifgroup_id)
        # VLAN is configured with the only ifgroup_id
        if not eliminated:
            is_delete = True

        common_def = "vfab {vfab} vlan {vlan} {port_type} {vlan_type}"
        # Delete VFAB VLAN definition
        if is_delete:
            command = "no" + " " + common_def
            cmds = [command.format(vfab=vfab_id, vlan=vlanid,
                                   port_type=port_type, vlan_type=vlan_type)]
        # Reject ifgroup_id from VFAB VLAN definition
        else:
            command = common_def + " " + "{ifgroup}"
            cmds = [command.format(vfab=vfab_id, vlan=vlanid,
                                   port_type=port_type, vlan_type=vlan_type,
                                   ifgroup=eliminated)]
        self.mgr.configure(cmds, commit=commit)
        return eliminated
 def test_found_range_of_high(self):
     definition = "1-10"
     target = "10"
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("1-9", result)
 def test_found_the_highest(self):
     definition = "1,2,3"
     target = "3"
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("1,2", result)
 def test_found_range_of_lowest_next_to_highest(self):
     definition = "1-2"
     target = "1"
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("2", result)
 def test_no_matched_with_boundary(self):
     definition = "1-10"
     target = "100"
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("1-10", result)
 def test_definition_is_None(self):
     definition = None
     target = "1"
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual(None, result)
Esempio n. 8
0
 def test_definition_is_None(self):
     definition = None
     target = "1"
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual(None, result)
 def test_no_matched(self):
     definition = "10,11"
     target = "100"
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("10,11", result)
Esempio n. 10
0
 def test_found_between_ranges_next_to_the_lowest_and_highest(self):
     definition = "1-3"
     target = "2"
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("1,3", result)
 def test_found_between_ranges_next_to_the_lowest_and_highest(self):
     definition = "1-3"
     target = "2"
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("1,3", result)
Esempio n. 12
0
 def test_found_between_ranges(self):
     definition = "1-10"
     target = "5"
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("1-4,6-10", result)
Esempio n. 13
0
 def test_found_between_ranges_next_to_the_highest(self):
     definition = "1-10"
     target = "9"
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("10,1-8", result)
Esempio n. 14
0
 def test_found_range_of_high(self):
     definition = "1-10"
     target = "10"
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("1-9", result)
Esempio n. 15
0
 def test_found_range_of_lowest_next_to_highest(self):
     definition = "1-2"
     target = "1"
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("2", result)
Esempio n. 16
0
 def test_found_the_highest(self):
     definition = "1,2,3"
     target = "3"
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("1,2", result)
 def test_found_between_ranges(self):
     definition = "1-10"
     target = "5"
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("1-4,6-10", result)
Esempio n. 18
0
 def test_no_matched(self):
     definition = "10,11"
     target = "100"
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("10,11", result)
 def test_found_between_ranges_next_to_the_highest(self):
     definition = "1-10"
     target = "9"
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("10,1-8", result)
Esempio n. 20
0
 def test_no_matched_with_boundary(self):
     definition = "1-10"
     target = "100"
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("1-10", result)
 def test_matches_only_one(self):
     definition = "100"
     target = "100"
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("", result)
Esempio n. 22
0
 def test_matches_only_one(self):
     definition = "100"
     target = "100"
     result = fj_util.eliminate_val(definition, target)
     self.assertEqual("", result)