This file is indexed.

/usr/lib/python2.7/dist-packages/maasserver/clusterrpc/utils.py is in python-django-maas 1.5.4+bzr2294-0ubuntu1.2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Copyright 2014 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Common code for MAAS Cluster RPC operations."""

from __future__ import (
    absolute_import,
    print_function,
    unicode_literals,
    )

str = None

__metaclass__ = type
__all__ = [
    'call_clusters',
    ]


from functools import partial

from maasserver import logger
from maasserver.exceptions import ClusterUnavailable
from maasserver.models import NodeGroup
from maasserver.rpc import getClientFor
from maasserver.utils import async
from provisioningserver.rpc.exceptions import NoConnectionsAvailable
from twisted.python.failure import Failure


def call_clusters(command, nodegroups=None, ignore_errors=True):
    """Make an RPC call to all clusters in parallel.

    :param nodegroups: The :class:`NodeGroup`s on which to make the RPC
        call. If None, defaults to all :class:`NodeGroup`s.
    :param command: An :class:`amp.Command` to call on the clusters.
    :param ignore_errors: If True, errors encountered whilst calling
        `command` on the clusters won't raise an exception.
    :return: A generator of results, i.e. the dicts returned by the RPC
        call.
    :raises: :py:class:`ClusterUnavailable` when a cluster is not
        connected or there's an error during the call, and errors are
        not being ignored.
    """
    calls = []
    if nodegroups is None:
        nodegroups = NodeGroup.objects.all()
    for ng in nodegroups:
        try:
            client = getClientFor(ng.uuid).wait()
        except NoConnectionsAvailable:
            logger.error(
                "Unable to get RPC connection for cluster '%s'", ng.name)
            if not ignore_errors:
                raise ClusterUnavailable(
                    "Unable to get RPC connection for cluster '%s'" % ng.name)
        else:
            call = partial(client, command)
            calls.append(call)

    for response in async.gather(calls, timeout=10):
        if isinstance(response, Failure):
            # XXX: How to get the cluster ID/name here?
            logger.error("Failure while communicating with cluster")
            logger.error(response.getTraceback())
            if not ignore_errors:
                raise ClusterUnavailable(
                    "Failure while communicating with cluster.")
        else:
            yield response