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

« back to all changes in this revision

Viewing changes to juju/control/utils.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
1
import os
2
2
from itertools import tee
3
3
 
 
4
from twisted.internet.defer import inlineCallbacks, returnValue
 
5
 
4
6
from juju.environment.errors import EnvironmentsConfigError
 
7
from juju.state.errors import ServiceUnitStateMachineNotAssigned
 
8
from juju.state.machine import MachineStateManager
 
9
from juju.state.service import ServiceStateManager
5
10
 
6
11
 
7
12
def get_environment(options):
14
19
    return environment
15
20
 
16
21
 
 
22
@inlineCallbacks
 
23
def get_ip_address_for_machine(client, provider, machine_id):
 
24
    """Returns public DNS name and machine state for the machine id.
 
25
 
 
26
    :param client: a connected zookeeper client.
 
27
    :param provider: the `MachineProvider` in charge of the juju.
 
28
    :param machine_id: machine ID of the desired machine to connect to.
 
29
    :return: tuple of the DNS name and a `MachineState`.
 
30
    """
 
31
    manager = MachineStateManager(client)
 
32
    machine_state = yield manager.get_machine_state(machine_id)
 
33
    instance_id = yield machine_state.get_instance_id()
 
34
    provider_machine = yield provider.get_machine(instance_id)
 
35
    returnValue((provider_machine.dns_name, machine_state))
 
36
 
 
37
 
 
38
@inlineCallbacks
 
39
def get_ip_address_for_unit(client, provider, unit_name):
 
40
    """Returns public DNS name and unit state for the service unit.
 
41
 
 
42
    :param client: a connected zookeeper client.
 
43
    :param provider: the `MachineProvider` in charge of the juju.
 
44
    :param unit_name: service unit running on a machine to connect to.
 
45
    :return: tuple of the DNS name and a `MachineState`.
 
46
    :raises: :class:`juju.state.errors.ServiceUnitStateMachineNotAssigned`
 
47
    """
 
48
    manager = ServiceStateManager(client)
 
49
    service_unit = yield manager.get_unit_state(unit_name)
 
50
    machine_id = yield service_unit.get_assigned_machine_id()
 
51
    if machine_id is None:
 
52
        raise ServiceUnitStateMachineNotAssigned(unit_name)
 
53
    returnValue(
 
54
        ((yield service_unit.get_public_address()), service_unit))
 
55
 
 
56
 
17
57
def expand_path(p):
18
58
    return os.path.abspath(os.path.expanduser(p))
19
59