Ejemplo n.º 1
0
    def test_get_ip_address_for_machine(self):
        """Verify can retrieve dns name, machine state with machine id."""
        machine_state = yield self.add_machine_state()
        provider_machine, = yield self.provider.start_machine(
            {"machine-id": machine_state.id, "dns-name": "steamcloud-1.com"})
        yield machine_state.set_instance_id(provider_machine.instance_id)

        dns_name, lookedup_machine_state = yield get_ip_address_for_machine(
            self.client, self.provider, machine_state.id)
        self.assertEqual(dns_name, "steamcloud-1.com")
        self.assertEqual(lookedup_machine_state.id, machine_state.id)
Ejemplo n.º 2
0
    def test_get_ip_address_for_machine(self):
        """Verify can retrieve dns name, machine state with machine id."""
        machine_state = yield self.machine_state_manager.add_machine_state()
        provider_machine, = yield self.provider.start_machine(
            {"machine-id": machine_state.id, "dns-name": "steamcloud-1.com"})
        yield machine_state.set_instance_id(provider_machine.instance_id)

        dns_name, lookedup_machine_state = yield get_ip_address_for_machine(
            self.client, self.provider, machine_state.id)
        self.assertEqual(dns_name, "steamcloud-1.com")
        self.assertEqual(lookedup_machine_state.id, machine_state.id)
Ejemplo n.º 3
0
def command(options):
    """Launch an ssh shell on the given unit or machine.
    """
    environment = get_environment(options)
    provider = environment.get_machine_provider()
    client = yield provider.connect()
    label = machine = unit = None

    # First check if it's a juju machine id
    if options.unit_or_machine.isdigit():
        options.log.debug(
            "Fetching machine address using juju machine id.")
        ip_address, machine = yield get_ip_address_for_machine(
            client, provider, options.unit_or_machine)
        machine.get_ip_address = get_ip_address_for_machine
        label = "machine"
    # Next check if it's a unit
    elif "/" in options.unit_or_machine:
        options.log.debug(
            "Fetching machine address using unit name.")
        ip_address, unit = yield get_ip_address_for_unit(
            client, provider, options.unit_or_machine)
        unit.get_ip_address = get_ip_address_for_unit
        label = "unit"
    else:
        raise MachineStateNotFound(options.unit_or_machine)

    agent_state = machine or unit

    # Now verify the relevant agent is operational via its agent.
    exists_d, watch_d = agent_state.watch_agent()
    exists = yield exists_d

    if not exists:
        # If not wait on it.
        options.log.info("Waiting for %s to come up." % label)
        yield watch_d

    # Double check the address we have is valid, else refetch.
    if ip_address is None:
        ip_address, machine = yield agent_state.get_ip_address(
            client, provider, options.unit_or_machine)

    yield client.close()

    options.log.info("Connecting to %s %s at %s",
                     label, options.unit_or_machine, ip_address)
    open_ssh(options.ssh_flags, ip_address, options.ssh_command)
Ejemplo n.º 4
0
def _expand_unit_or_machine(client, provider, path):
    """Expands service unit or machine ID into DNS name"""
    parts = path.split(":")
    if len(parts) > 1:
        remote_system = parts[0]
        ip_address = None
        if remote_system.isdigit():
            # machine id, will not pick up dotted IP addresses
            ip_address, _ = yield get_ip_address_for_machine(
                client, provider, remote_system)
        elif "/" in remote_system:
            # service unit
            ip_address, _ = yield get_ip_address_for_unit(
                client, provider, remote_system)
        if ip_address:
            returnValue("ubuntu@%s:%s" % (ip_address, ":".join(parts[1:])))
    returnValue(path)  # no need to expand
Ejemplo n.º 5
0
def _expand_unit_or_machine(client, provider, path):
    """Expands service unit or machine ID into DNS name"""
    parts = path.split(":")
    if len(parts) > 1:
        remote_system = parts[0]
        ip_address = None
        if remote_system.isdigit():
            # machine id, will not pick up dotted IP addresses
            ip_address, _ = yield get_ip_address_for_machine(
                client, provider, remote_system)
        elif "/" in remote_system:
            # service unit
            ip_address, _ = yield get_ip_address_for_unit(
                client, provider, remote_system)
        if ip_address:
            returnValue("ubuntu@%s:%s" % (ip_address, ":".join(parts[1:])))
    returnValue(path)  # no need to expand
Ejemplo n.º 6
0
Archivo: ssh.py Proyecto: mcclurmc/juju
def command(options):
    """Launch an ssh shell on the given unit or machine.
    """
    environment = get_environment(options)
    provider = environment.get_machine_provider()
    client = yield provider.connect()
    label = machine = unit = None

    # First check if it's a juju machine id
    if options.unit_or_machine.isdigit():
        options.log.debug("Fetching machine address using juju machine id.")
        ip_address, machine = yield get_ip_address_for_machine(
            client, provider, options.unit_or_machine)
        machine.get_ip_address = get_ip_address_for_machine
        label = "machine"
    # Next check if it's a unit
    elif "/" in options.unit_or_machine:
        options.log.debug("Fetching machine address using unit name.")
        ip_address, unit = yield get_ip_address_for_unit(
            client, provider, options.unit_or_machine)
        unit.get_ip_address = get_ip_address_for_unit
        label = "unit"
    else:
        raise MachineStateNotFound(options.unit_or_machine)

    agent_state = machine or unit

    # Now verify the relevant agent is operational via its agent.
    exists_d, watch_d = agent_state.watch_agent()
    exists = yield exists_d

    if not exists:
        # If not wait on it.
        options.log.info("Waiting for %s to come up." % label)
        yield watch_d

    # Double check the address we have is valid, else refetch.
    if ip_address is None:
        ip_address, machine = yield agent_state.get_ip_address(
            client, provider, options.unit_or_machine)

    yield client.close()

    options.log.info("Connecting to %s %s at %s", label,
                     options.unit_or_machine, ip_address)
    open_ssh(options.ssh_flags, ip_address, options.ssh_command)