コード例 #1
0
def scan_all_rack_networks(scan_all=None,
                           cidrs=None,
                           ping=None,
                           threads=None,
                           slow=None) -> RPCResults:
    """Call each rack controller and instruct it to scan its attached networks.

    Interprets the results and returns a dict with the following keys:
        result: A human-readable string summarizing the results.
        scan_attempted_on: A list of rack system_id values where a scan
            was attempted. (That is, an RPC connection was successful and
            a subsequent call was intended.)
        failed_to_connect_to: A list of rack system_id values where the
            RPC connection failed.
        scan_started_on: A list of rack system_id values where a scan
            was successfully started.
        scan_failed_on: A list of rack system_id values where
            a scan was attempted, but failed because a scan was already in
            progress.
        rpc_call_timed_out_on: A list of rack system_id values where the
            RPC connection was made, but the call timed out before the
            ten second timeout elapsed.

    This function is intended to be used directly by the API and websocket
    layers, so must return a dict that is safe to encode to JSON.

    :param scan_all: If True, allows scanning all networks if no `cidrs` were
        passed in.
    :param cidrs: An iterable of netaddr.IPNetwork objects to instruct the
        rack controllers to scan. If omitted, the rack will scan all of its
        attached networks.
    :param ping: If True, forces the use of 'ping' rather than 'nmap'.
    :param threads: If specified, overrides the default number of concurrent
        scanning threads.
    :param slow: If True, forces 'nmap' to scan slower (if it is being used).
    :return: dict
    """
    kwargs = {}
    controllers = None
    if scan_all is not None:
        kwargs['scan_all'] = scan_all
    if cidrs is not None:
        kwargs['cidrs'] = cidrs
        controllers = list(
            RackController.objects.filter_by_subnet_cidrs(cidrs))
    if ping is not None:
        kwargs['force_ping'] = ping
    if threads is not None:
        kwargs['threads'] = threads
    if slow is not None:
        kwargs['slow'] = slow
    rpc_results = call_racks_synchronously(cluster.ScanNetworks,
                                           controllers=controllers,
                                           kwargs=kwargs)
    return rpc_results
コード例 #2
0
ファイル: test_utils.py プロジェクト: shawnallen85/maas
    def test_gets_clients(self):
        rack = factory.make_RackController()
        getClientFor = self.patch(utils, "getClientFor")
        getClientFor.return_value = lambda: None
        async_gather = self.patch(asynchronous, "gatherCallResults")
        async_gather.return_value = []

        # call_clusters returns with nothing because we patched out
        # asynchronous.gather, but we're interested in the side-effect:
        # getClientFor has been called for the accepted nodegroup.
        self.assertItemsEqual([],
                              call_racks_synchronously(
                                  sentinel.command).results)
        self.assertThat(getClientFor, MockCalledOnceWith(rack.system_id))