示例#1
0
 def test_find_vlans_in_org_one_child(self):
     """Should return all vlans in this org and child org"""
     self.assertEqual(
         sorted(find_vlans_in_org(self.org2)),
         sorted(
             [FantasyVlan(self.vlan3.vlan),
              FantasyVlan(self.vlan2.vlan)]))
示例#2
0
 def test_find_vlans_in_org_filter_nonevalues(self):
     """Should filter vlans with no vlan value"""
     self.vlan1.vlan = None
     self.assertEqual(
         sorted(find_vlans_in_org(self.org1)),
         sorted(
             [FantasyVlan(self.vlan3.vlan),
              FantasyVlan(self.vlan2.vlan)]))
示例#3
0
 def test_find_vlans_in_org_two_children(self):
     """Should return all vlans in this org and all children orgs"""
     self.assertEqual(
         sorted(find_vlans_in_org(self.org1)),
         sorted([
             FantasyVlan(self.vlan3.vlan),
             FantasyVlan(self.vlan2.vlan),
             FantasyVlan(self.vlan1.vlan)
         ]))
示例#4
0
 def test_find_vlans_in_org_no_duplicates(self):
     """Should filter duplicates"""
     self.org3.vlan_set.all.return_value = [self.vlan3, self.vlan2]
     self.assertEqual(
         sorted(find_vlans_in_org(self.org1)),
         sorted([
             FantasyVlan(self.vlan3.vlan),
             FantasyVlan(self.vlan2.vlan),
             FantasyVlan(self.vlan1.vlan)
         ]))
示例#5
0
    def test_find_allowed_vlans_for_user(self):
        """Should return all vlans for this users org and child orgs"""

        account = Mock()
        account.organizations.all.return_value = [self.org1]

        self.assertEqual(
            sorted(find_allowed_vlans_for_user(account)),
            sorted([
                FantasyVlan(self.vlan1.vlan),
                FantasyVlan(self.vlan2.vlan),
                FantasyVlan(self.vlan3.vlan)
            ]))
示例#6
0
def find_vlans_in_org(org):
    """Find all vlans in an organization and child organizations

    :returns: list of FantasyVlans
    :rtype: list
    """
    vlans = list(org.vlan_set.all())
    for child_org in org.organization_set.all():
        vlans.extend(find_vlans_in_org(child_org))
    return [FantasyVlan(x.vlan, x.net_ident) for x in list(set(vlans)) if
            x.vlan]
示例#7
0
文件: utils.py 项目: Cloudxtreme/nav
def find_default_vlan(include_netident=False):
    """Check config to see if a default vlan is set

    :rtype: FantasyVlan
    """
    defaultvlan = ""
    netident = ""

    config = read_config()
    if config.has_section("defaultvlan"):
        if config.has_option("defaultvlan", "vlan"):
            defaultvlan = config.getint("defaultvlan", "vlan")
        if config.has_option("defaultvlan", "netident"):
            netident = config.get("defaultvlan", "netident")

    if defaultvlan:
        if include_netident:
            return FantasyVlan(defaultvlan, netident)
        else:
            return FantasyVlan(defaultvlan)
示例#8
0
 def test_find_vlans_in_org_no_children(self):
     """Should return all vlans in this org"""
     self.assertEqual(find_vlans_in_org(self.org3),
                      [FantasyVlan(self.vlan3.vlan)])