Example #1
0
def _populate(netdevices, data_source, data_format, production_only):
    """
    Populates the NetDevices with NetDevice objects.

    Abstracted from within NetDevices to prevent accidental repopulation of NetDevice
    objects.
    """
    #start = time.time()
    aclsdb = AclsDB()

    device_data = _munge_source_data(data_source=data_source, format=data_format)

    for obj in device_data:
        dev = NetDevice(data=obj)

        # Only return devices with adminStatus of 'PRODUCTION' unless
        # production_only is True
        if dev.adminStatus != 'PRODUCTION' and production_only:
            continue

        # These checks should be done on generation of netdevices.xml.
        ## skip empty nodenames
        if dev.nodeName is None:
            continue

        ## lowercase hostnames
        dev.nodeName = dev.nodeName.lower()

        ## cleanup whitespace from owning team
        dev.owningTeam = dev.owningTeam.strip()

        # Populate the ACLs for each device.
        dev.explicit_acls = dev.implicit_acls = dev.acls = dev.bulk_acls = set()
        acls_dict = aclsdb.get_acl_dict(dev)
        dev.explicit_acls = acls_dict['explicit']
        dev.implicit_acls = acls_dict['implicit']
        dev.acls = acls_dict['all']

        # Add to dict
        netdevices[dev.nodeName] = dev