25
26
from maasserver.models import NodeGroup
26
27
from maasserver.rpc import getClientFor
27
28
from maasserver.utils import async
28
from provisioningserver.rpc.exceptions import NoConnectionsAvailable
29
from provisioningserver.rpc.exceptions import (
31
NoConnectionsAvailable,
29
33
from twisted.python.failure import Failure
52
56
client = getClientFor(ng.uuid)
53
57
except NoConnectionsAvailable:
55
"Unable to get RPC connection for cluster '%s'", ng.name)
59
"Unable to get RPC connection for cluster '%s' (%s)",
60
ng.cluster_name, ng.uuid)
56
61
if not ignore_errors:
57
62
raise ClusterUnavailable(
58
"Unable to get RPC connection for cluster '%s'" % ng.name)
63
"Unable to get RPC connection for cluster '%s' (%s)"
64
% (ng.cluster_name, ng.uuid))
60
66
call = partial(client, command)
70
76
"Failure while communicating with cluster.")
81
def get_error_message_for_exception(exception):
82
"""Return an error message for an exception.
84
If `exception` is a NoConnectionsAvailable error,
85
get_error_message_for_exception() will check to see if there's a
86
UUID listed. If so, this is an error referring to a cluster.
87
get_error_message_for_exception() will return an error message
88
containing the cluster's name (as opposed to its UUID), which is
91
If `exception` is an instance of `MultipleFailures` a single error
92
message will be returned, explaining where to look for more
95
Otherwise, if the exception has a message attached, return that.
96
If not, create meaningful error message for the exception and
99
# If we've gt a NoConnectionsAvailable error, check it for a UUID
100
# field. If it's got one, we can report the cluster details more
102
is_no_connections_error = isinstance(
103
exception, NoConnectionsAvailable)
104
has_uuid_field = getattr(exception, 'uuid', None) is not None
105
if (is_no_connections_error and has_uuid_field):
106
cluster = NodeGroup.objects.get_by_natural_key(
109
"Unable to connect to cluster '%s' (%s); no connections "
110
"available." % (cluster.cluster_name, cluster.uuid))
112
if isinstance(exception, MultipleFailures):
114
"Multiple failures encountered. See /var/log/maas/maas-django.log "
115
"on the region server for more information.")
117
error_message = unicode(exception)
118
if len(error_message) == 0:
120
"Unexpected exception: %s. See "
121
"/var/log/maas/maas-django.log "
122
"on the region server for more information." %
123
exception.__class__.__name__)