~lutostag/ubuntu/trusty/maas/1.5.2+packagefix

« back to all changes in this revision

Viewing changes to src/maasserver/rpc/__init__.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2014-03-28 10:43:53 UTC
  • mto: This revision was merged to the branch mainline in revision 57.
  • Revision ID: package-import@ubuntu.com-20140328104353-ekpolg0pm5xnvq2s
Tags: upstream-1.5+bzr2204
ImportĀ upstreamĀ versionĀ 1.5+bzr2204

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2014 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Region Controller RPC."""
 
5
 
 
6
from __future__ import (
 
7
    absolute_import,
 
8
    print_function,
 
9
    unicode_literals,
 
10
    )
 
11
 
 
12
str = None
 
13
 
 
14
__metaclass__ = type
 
15
__all__ = [
 
16
    "getClientFor",
 
17
    "getAllClients",
 
18
]
 
19
 
 
20
from maasserver import eventloop
 
21
from provisioningserver.rpc import exceptions
 
22
from provisioningserver.utils import asynchronous
 
23
 
 
24
 
 
25
@asynchronous
 
26
def getClientFor(uuid):
 
27
    """getClientFor(uuid)
 
28
 
 
29
    Get a client with which to make RPCs to the specified cluster.
 
30
 
 
31
    :raises: :py:class:`~.exceptions.NoConnectionsAvailable` when there
 
32
        are no open connections to the specified cluster controller.
 
33
    """
 
34
    try:
 
35
        service = eventloop.services.getServiceNamed("rpc")
 
36
    except KeyError:
 
37
        raise exceptions.NoConnectionsAvailable()
 
38
    else:
 
39
        return service.getClientFor(uuid)
 
40
 
 
41
 
 
42
@asynchronous
 
43
def getAllClients():
 
44
    """getAllClients()
 
45
 
 
46
    Get all recorded clients ready to make RPCs to clusters.
 
47
    """
 
48
    try:
 
49
        service = eventloop.services.getServiceNamed("rpc")
 
50
    except KeyError:
 
51
        return []
 
52
    else:
 
53
        return service.getAllClients()