~blake-rouse/maas/fix-1353597-1.6

« back to all changes in this revision

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

  • Committer: Blake Rouse
  • Date: 2014-06-24 18:28:28 UTC
  • mfrom: (2464 maas)
  • mto: This revision was merged to the branch mainline in revision 2473.
  • Revision ID: blake.rouse@canonical.com-20140624182828-g6meiaajbtrugxgj
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
from collections import defaultdict
21
21
from contextlib import closing
22
 
from functools import wraps
23
22
import random
24
23
from textwrap import dedent
25
24
import threading
26
25
 
27
26
from crochet import reactor
28
 
from django.db import (
29
 
    close_old_connections,
30
 
    connection,
31
 
    transaction,
32
 
    )
 
27
from django.db import connection
33
28
from maasserver import (
34
29
    eventloop,
35
30
    locks,
36
31
    )
 
32
from maasserver.rpc import bootsources
37
33
from maasserver.utils import synchronised
 
34
from maasserver.utils.async import transactional
38
35
from provisioningserver.rpc import (
39
36
    cluster,
40
37
    common,
109
106
            "tls_verifyAuthorities": tls_verifyAuthorities,
110
107
        }
111
108
 
 
109
    @region.GetBootSources.responder
 
110
    def get_boot_sources(self, uuid):
 
111
        """get_boot_sources()
 
112
 
 
113
        Implementation of
 
114
        :py:class:`~provisioningserver.rpc.region.GetBootSources`.
 
115
        """
 
116
        d = deferToThread(bootsources.get_boot_sources, uuid)
 
117
        d.addCallback(lambda sources: {b"sources": sources})
 
118
        return d
 
119
 
112
120
 
113
121
@implementer(IConnection)
114
122
class RegionServer(Region):
250
258
        ]
251
259
 
252
260
 
253
 
def transactional(func):
254
 
    """Decorator that wraps calls to `func` in a Django-managed transaction.
255
 
 
256
 
    It also ensures that connections are closed if necessary. This keeps
257
 
    Django happy, especially in the test suite.
258
 
    """
259
 
    @wraps(func)
260
 
    def call_within_transaction(*args, **kwargs):
261
 
        try:
262
 
            with transaction.atomic():
263
 
                return func(*args, **kwargs)
264
 
        finally:
265
 
            close_old_connections()
266
 
    return call_within_transaction
267
 
 
268
 
 
269
261
class RegionAdvertisingService(TimerService, object):
270
262
    """Advertise the local event-loop to all other event-loops.
271
263