Fetches a list of L3 agents hosting a router.
350955
def list_routers_on_l3_agent(self, l3_agent, **_params):
        """"""
        return self.get((self.agent_path + self.L3_ROUTERS) % l3_agent,
                        params=_params)
479999
def add_router_to_hosting_device(self, client, hosting_device_id, body):
        """"""
        res_path = hostingdevice.HostingDevice.resource_path
        return client.post((res_path + DEVICE_L3_ROUTERS) %
                           hosting_device_id, body=body)
1145662
def _filter_unscheduled_routers(self, plugin, context, routers):
        
        if NEUTRON_VERSION.version[0] <= NEUTRON_NEWTON_VERSION.version[0]:
            context, plugin = plugin, context
        unscheduled_routers = []
        for router in routers:
            if (router[routertype.TYPE_ATTR] !=
                    plugin.get_namespace_router_type_id(context)):
                # ignore non-namespace routers
                continue
            l3_agents = plugin.get_l3_agents_hosting_routers(
                context, [router['id']])
            if l3_agents:
                LOG.debug('Router %(router_id)s has already been '
                          'hosted by L3 agent %(agent_id)s',
                          {'router_id': router['id'],
                           'agent_id': l3_agents[0]['id']})
            else:
                unscheduled_routers.append(router)
        return unscheduled_routers
972015
def list(gandi, state, id, vhosts, type, limit):
    """"""
    options = {
        'items_per_page': limit,
    }
    if state:
        options['state'] = state

    output_keys = ['name', 'state']
    if id:
        output_keys.append('id')
    if vhosts:
        output_keys.append('vhost')
    if type:
        output_keys.append('type')

    paas_hosts = {}
    result = gandi.paas.list(options)
    for num, paas in enumerate(result):
        paas_hosts[paas['id']] = []
        if vhosts:
            list_vhost = gandi.vhost.list({'paas_id': paas['id']})
            for host in list_vhost:
                paas_hosts[paas['id']].append(host['name'])

        if num:
            gandi.separator_line()
        output_paas(gandi, paas, [], paas_hosts[paas['id']],
                    output_keys)

    return result
489951
def getHosts(filename=None, hostlist=None):
    """"""
    if filename:
        return getHostsFromFile(filename)
    elif hostlist:
        return getHostsFromList(hostlist)
    elif getEnv() == "SLURM":
        return getHostsFromSLURM()
    elif getEnv() == "PBS":
        return getHostsFromPBS()
    elif getEnv() == "SGE":
        return getHostsFromSGE()
    else:
        return getDefaultHosts()
884373
def user_agents(self):
        
        return (self.get_query()
                .select(
                    PageView.headers['User-Agent'],
                    fn.Count(PageView.id))
                .group_by(PageView.headers['User-Agent'])
                .order_by(fn.Count(PageView.id).desc())
                .tuples())
212990
def get_lldp_neighbors(self):
        """"""
        lldp = {}
        command = 'show lldp neighbors'
        output = self._send_command(command)

        # Check if router supports the command
        if '% Invalid input' in output:
            return {}

        # Process the output to obtain just the LLDP entries
        try:
            split_output = re.split(r'^Device ID.*$', output, flags=re.M)[1]
            split_output = re.split(r'^Total entries displayed.*$', split_output, flags=re.M)[0]
        except IndexError:
            return {}

        split_output = split_output.strip()

        for lldp_entry in split_output.splitlines():
            # Example, twb-sf-hpsw1    Fa4   120   B   17
            try:
                device_id, local_int_brief, hold_time, capability, remote_port = lldp_entry.split()
            except ValueError:
                if len(lldp_entry.split()) == 4:
                    # Four fields might be long_name or missing capability
                    capability_missing = True if lldp_entry[46] == ' ' else False
                    if capability_missing:
                        device_id, local_int_brief, hold_time, remote_port = lldp_entry.split()
                    else:
                        # Might be long_name issue
                        tmp_field, hold_time, capability, remote_port = lldp_entry.split()
                        device_id = tmp_field[:20]
                        local_int_brief = tmp_field[20:]
                        # device_id might be abbreviated, try to get full name
                        lldp_tmp = self._lldp_detail_parser(local_int_brief)
                        device_id_new = lldp_tmp[3][0]
                        # Verify abbreviated and full name are consistent
                        if device_id_new[:20] == device_id:
                            device_id = device_id_new
                        else:
                            raise ValueError("Unable to obtain remote device name")
            local_port = self._expand_interface_name(local_int_brief)

            entry = {'port': remote_port, 'hostname': device_id}
            lldp.setdefault(local_port, [])
            lldp[local_port].append(entry)

        return lldp
905538
def get_hosting_devices_qry(self, context, hosting_device_ids,
                                load_agent=True):
        """"""
        query = context.session.query(hd_models.HostingDevice)
        if load_agent:
            query = query.options(joinedload('cfg_agent'))
        if len(hosting_device_ids) > 1:
            query = query.filter(hd_models.HostingDevice.id.in_(
                hosting_device_ids))
        else:
            query = query.filter(hd_models.HostingDevice.id ==
                                 hosting_device_ids[0])
        return query
107276
def _notification(self, context, method, routers, operation,
                      shuffle_agents):
        """"""
        if extensions.is_extension_supported(self._l3plugin, L3AGENT_SCHED):
            adm_context = (context.is_admin and context or context.elevated())
            # This is where hosting device gets scheduled to Cisco cfg agent
            self._l3plugin.schedule_routers(adm_context, routers)
            self._agent_notification(
                context, method, routers, operation, shuffle_agents)
        else:
            cctxt = self.client.prepare(topics=topics.L3_AGENT, fanout=True)
            cctxt.cast(context, method, routers=[r['id'] for r in routers])
943708
def get_available_routers(self, dc=None):
        
        mask = "mask[locations]"
        # Step 1, get the package id
        package = self.ordering_manager.get_package_by_key(self.capacity_package, mask="id")

        # Step 2, get the regions this package is orderable in
        regions = self.client.call('Product_Package', 'getRegions', id=package['id'], mask=mask, iter=True)
        _filter = None
        routers = {}
        if dc is not None:
            _filter = {'datacenterName': {'operation': dc}}

        # Step 3, for each location in each region, get the pod details, which contains the router id
        pods = self.client.call('Network_Pod', 'getAllObjects', filter=_filter, iter=True)
        for region in regions:
            routers[region['keyname']] = []
            for location in region['locations']:
                location['location']['pods'] = list()
                for pod in pods:
                    if pod['datacenterName'] == location['location']['name']:
                        location['location']['pods'].append(pod)

        # Step 4, return the data.
        return regions
1156572
def access_route(self):
        
        if "HTTP_X_FORWARDED_FOR" in self.environ:
            addr = self.environ["HTTP_X_FORWARDED_FOR"].split(",")
            return self.list_storage_class([x.strip() for x in addr])
        elif "REMOTE_ADDR" in self.environ:
            return self.list_storage_class([self.environ["REMOTE_ADDR"]])
        return self.list_storage_class()
454120
def divideHosts(self, hosts, qty):
        """"""
        maximumWorkers = sum(host[1] for host in hosts)

        # If specified amount of workers is greater than sum of each specified.
        if qty > maximumWorkers:
            index = 0
            while qty > maximumWorkers:
                hosts[index] = (hosts[index][0], hosts[index][1] + 1)
                index = (index + 1) % len(hosts)
                maximumWorkers += 1

        # If specified amount of workers if lower than sum of each specified.
        elif qty < maximumWorkers:

            while qty < maximumWorkers:
                maximumWorkers -= hosts[-1][1]
                if qty > maximumWorkers:
                    hosts[-1] = (hosts[-1][0], qty - maximumWorkers)
                    maximumWorkers += hosts[-1][1]
                else:
                    del hosts[-1]


        # Checking if the broker if externally routable
        if self.externalHostname in utils.loopbackReferences and \
                len(hosts) > 1 and \
                not self.tunnel:
            raise Exception("\n"
                            "Could not find route from external worker to the "
                            "broker: Unresolvable hostname or IP address.\n "
                            "Please specify your externally routable hostname "
                            "or IP using the --external-hostname parameter or "
                            "use the --tunnel flag.")
        return hosts
1133338
def index(self, req, drivers):
        
        result = []
        for driver in drivers:
            result.append(driver.list_network(req.params))
        data = {
                'action': "index",
                'controller': "network",
                'cloud': req.environ['calplus.cloud'],
                'result': result
        }
        return data
119570
def getNeighbouringRouters(self):
        
        print '%s call getNeighbouringRouters' % self.port
        try:
            routerInfo = []
            routerList = []
            routerList = self.__sendCommand('router list')[0].split()
            print routerList

            if 'Done' in routerList:
                print 'no neighbouring routers'
                return None

            for index in routerList:
                router = []
                cmd = 'router %s' % index
                router = self.__sendCommand(cmd)

                for line in router:
                    if 'Done' in line:
                        break
                    #elif 'Rloc' in line:
                    #    rloc16 = line.split()[1]
                    elif 'Ext Addr' in line:
                        eui = line.split()[2]
                        routerInfo.append(int(eui, 16))
                    #elif 'LQI In' in line:
                    #    lqi_in = line.split()[1]
                    #elif 'LQI Out' in line:
                    #    lqi_out = line.split()[1]
                    else:
                        pass

            print routerInfo
            return routerInfo
        except Exception, e:
            ModuleHelper.WriteIntoDebugLogger("getNeighbouringDevice() Error: " + str(e))
597823
def list_routers(self, retrieve_all=True, **_params):
        """"""
        # Pass filters in "params" argument to do_request
        return self.list('routers', self.routers_path, retrieve_all,
                         **_params)
439281
def get_network():
    """"""
    meta = SoftLayer.MetadataManager()
    network_tables = []
    for network_func in [meta.public_network, meta.private_network]:
        network = network_func()

        table = formatting.KeyValueTable(['name', 'value'])
        table.align['name'] = 'r'
        table.align['value'] = 'l'
        table.add_row(['mac addresses',
                       formatting.listing(network['mac_addresses'],
                                          separator=',')])
        table.add_row(['router', network['router']])
        table.add_row(['vlans',
                       formatting.listing(network['vlans'], separator=',')])
        table.add_row(['vlan ids',
                       formatting.listing(network['vlan_ids'], separator=',')])
        network_tables.append(table)

    return network_tables
294652
def get(self, request):
        '''
        '''
        data = {}
        for router in self.routes:
            data[router.name] = request.absolute_uri(router.path())
        return Json(data).http_response(request)