~ubuntu-branches/ubuntu/trusty/juju/trusty

« back to all changes in this revision

Viewing changes to juju/providers/orchestra/launch.py

  • Committer: Clint Byrum
  • Date: 2012-01-23 18:16:35 UTC
  • mfrom: (1.1.4)
  • Revision ID: clint@ubuntu.com-20120123181635-epogr1dvjmk53l0h
* New upstream snapshot.
  - Fixed regression with twisted 11.1 (LP: #917954)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import logging
 
2
import sys
 
3
 
1
4
from twisted.internet.defer import inlineCallbacks, returnValue
2
5
 
3
6
from juju.providers.common.launch import LaunchMachine
4
7
 
5
8
from .machine import machine_from_dict
6
9
 
 
10
log = logging.getLogger("juju.orchestra")
 
11
 
7
12
 
8
13
class OrchestraLaunchMachine(LaunchMachine):
9
14
    """Orchestra operation for launching an instance"""
26
31
        """
27
32
        cobbler = self._provider.cobbler
28
33
        instance_id = yield cobbler.acquire_system()
29
 
 
30
 
        cloud_init = self._create_cloud_init(machine_id, zookeepers)
31
 
        cloud_init.set_provider_type("orchestra")
32
 
        cloud_init.set_instance_id_accessor(instance_id)
33
 
 
34
 
        info = yield cobbler.start_system(
35
 
            instance_id, machine_id, cloud_init.render())
36
 
        returnValue([machine_from_dict(info)])
 
34
        # If anything goes wrong after the acquire and before the launch
 
35
        # actually happens, we attempt to roll back by calling shutdown_system.
 
36
        # This is not guaranteed to work, ofc, but it's the best effort we can
 
37
        # make towards avoiding lp:894362, in which a machine gets stuck in an
 
38
        # 'acquired' state and cannot be reused without manual intervention.
 
39
        try:
 
40
            cloud_init = self._create_cloud_init(machine_id, zookeepers)
 
41
            cloud_init.set_provider_type("orchestra")
 
42
            cloud_init.set_instance_id_accessor(instance_id)
 
43
 
 
44
            info = yield cobbler.start_system(
 
45
                instance_id, machine_id, cloud_init.render())
 
46
            returnValue([machine_from_dict(info)])
 
47
        except Exception:
 
48
            log.exception(
 
49
                "Failed to launch machine %s; attempting to revert.",
 
50
                instance_id)
 
51
            exc_info = sys.exc_info()
 
52
            yield cobbler.shutdown_system(instance_id)
 
53
            raise exc_info