Exemplo n.º 1
0
def command(options):
    """Output status information about a deployment.

    This command will report on the runtime state of various system
    entities.

    $ juju status

    will return data on entire default deployment.

    $ juju status -e DEPLOYMENT2

    will return data on the DEPLOYMENT2 envionment.
    """
    environment = get_environment(options)
    renderer = renderers.get(options.format)
    if renderer is None:
        formats = sorted(renderers.keys())
        formats = ", ".join(formats)

        raise SystemExit(
            "Unsupported render format %s (valid formats: %s)." % (
                options.format, formats))

    return status(environment,
                  options.scope,
                  renderer,
                  options.output,
                  options.log)
Exemplo n.º 2
0
def command(options):
    """Set machine constraints for the environment, or for a named service.
    """
    environment = get_environment(options)
    env_config = options.environments
    return constraints_set(
        env_config, environment, options.service, options.constraints)
Exemplo n.º 3
0
def command(options):
    """Distributed juju debug log watching."""
    environment = get_environment(options)
    return debug_log(
        options.environments,
        environment,
        options.log,
        options)
Exemplo n.º 4
0
def command(options):
    """Remove a service unit."""
    environment = get_environment(options)
    return remove_unit(
        options.environments,
        environment,
        options.verbose,
        options.log,
        options.unit_names)
Exemplo n.º 5
0
def command(options):
    """Destroy a running service, its units, and break its relations."""
    environment = get_environment(options)
    return destroy_service(
        options.environments,
        environment,
        options.verbose,
        options.log,
        options.service_name)
Exemplo n.º 6
0
def command(options):
    """Add a relation between services in juju."""
    environment = get_environment(options)
    return add_relation(
        options.environments,
        environment,
        options.verbose,
        options.log,
        *options.descriptors)
Exemplo n.º 7
0
def command(options):
    """Remove internet access to a service."""
    environment = get_environment(options)
    return unexpose(
        options.environments,
        environment,
        options.verbose,
        options.log,
        options.service_name)
Exemplo n.º 8
0
def command(options):
    """
    Bootstrap machine providers in the specified environment.
    """
    environment = get_environment(options)
    provider = environment.get_machine_provider()
    options.log.info("Bootstrapping environment %r (type: %s)..." %
                     (environment.name, environment.type))
    yield provider.bootstrap()
Exemplo n.º 9
0
def command(options):
    """
    Bootstrap machine providers in the specified environment.
    """
    environment = get_environment(options)
    provider = environment.get_machine_provider()
    options.log.info("Bootstrapping environment %r (type: %s)..." % (
        environment.name, environment.type))
    yield provider.bootstrap()
Exemplo n.º 10
0
def command(options):
    """Terminate machines in an environment."""
    environment = get_environment(options)
    return terminate_machine(
        options.environments,
        environment,
        options.verbose,
        options.log,
        options.machine_ids)
Exemplo n.º 11
0
def command(options):
    """Add a new service unit."""
    environment = get_environment(options)
    return add_unit(
        options.environments,
        environment,
        options.verbose,
        options.log,
        options.service_name,
        options.num_units)
Exemplo n.º 12
0
def command(options):
    """Upgrade a service's charm."""
    environment = get_environment(options)
    return upgrade_charm(
        options.environments,
        environment,
        options.verbose,
        options.log,
        options.repository,
        options.service_name,
        options.dry_run)
Exemplo n.º 13
0
def command(options):
    """Mark an error as resolved in a unit or unit relation."""
    environment = get_environment(options)
    return resolved(
        options.environments,
        environment,
        options.verbose,
        options.log,
        options.service_unit_name,
        options.relation_name,
        options.retry)
Exemplo n.º 14
0
def command(options):
    """Establish a tunnel to the environment.
    """
    environment = get_environment(options)
    provider = environment.get_machine_provider()
    yield provider.connect(share=True)

    options.log.info("Tunnel to the environment is open. "
                     "Press CTRL-C to close it.")

    yield hanging_deferred()
Exemplo n.º 15
0
def command(options):
    """Interactively debug a hook remotely on a service unit.
    """
    environment = get_environment(options)
    provider = environment.get_machine_provider()
    client = yield provider.connect()

    # Verify unit and retrieve ip address
    options.log.debug("Retrieving unit and machine information.")
    ip_address, unit = yield get_ip_address_for_unit(
        client, provider, options.unit_name)

    # Verify hook name
    if options.hook_names != ["*"]:
        options.log.debug("Verifying hook names...")
        yield validate_hooks(client, unit, options.hook_names)

    # Enable debug log
    options.log.debug(
        "Enabling hook debug on unit (%r)..." % options.unit_name)
    yield unit.enable_hook_debug(options.hook_names)

    # If we don't have an ipaddress the unit isn't up yet, wait for it.
    if not ip_address:
        options.log.info("Waiting for unit")
        # Wait and verify the agent is running.
        while 1:
            exists_d, watch_d = unit.watch_agent()
            exists = yield exists_d
            if exists:
                options.log.info("Unit running")
                break
            yield watch_d

        # Refetch the unit address
        ip_address, unit = yield get_ip_address_for_unit(
            client, provider, options.unit_name)

    # Connect via ssh and start tmux.
    options.log.info("Connecting to remote machine %s...", ip_address)

    # Encode the script as base64 so that we can deliver it with a single
    # ssh command while still retaining standard input on the terminal fd.
    script = SCRIPT.replace("{unit_name}", options.unit_name)
    script_b64 = base64.encodestring(script).replace("\n", "").strip()
    cmd = '"F=`mktemp`; echo %s | base64 -d > \$F; . \$F"' % script_b64

    # Yield to facilitate testing.
    yield os.system(
        "ssh -t ubuntu@%s 'sudo /bin/bash -c %s'" % (ip_address, cmd))

    options.log.info("Debug session ended.")
    # Ends hook debugging.
    yield client.close()
Exemplo n.º 16
0
    def test_get_environment(self):
        config = {
            "environments": {"firstenv": {"type": "dummy"}}}
        self.write_config(dump(config))

        env_config = EnvironmentsConfig()
        env_config.load_or_write_sample()
        options = FakeOptions()
        options.environment = None
        options.environments = env_config

        environment = get_environment(options)
        self.assertEqual(environment.name, "firstenv")
Exemplo n.º 17
0
    def test_get_environment(self):
        config = {
            "environments": {"firstenv": {"type": "dummy"}}}
        self.write_config(dump(config))

        env_config = EnvironmentsConfig()
        env_config.load_or_write_sample()
        options = FakeOptions()
        options.environment = None
        options.environments = env_config

        environment = get_environment(options)
        self.assertEqual(environment.name, "firstenv")
Exemplo n.º 18
0
def command(options):
    """
    Deploy a charm to juju!
    """
    environment = get_environment(options)
    return deploy(
        options.environments,
        environment,
        options.repository,
        options.charm,
        options.service_name,
        options.log,
        options.config,
        num_units=options.num_units)
Exemplo n.º 19
0
def command(options):
    """Use scp to copy files to/from given unit or machine.
    """
    # Unlike juju ssh, no attempt to verify liveness of the agent,
    # instead it's just a matter of whether the underlying scp will work
    # or not.
    environment = get_environment(options)
    provider = environment.get_machine_provider()
    client = yield provider.connect()
    try:
        paths = [(yield _expand_unit_or_machine(client, provider, path))
                 for path in options.paths]
        open_scp(options.scp_flags, paths)
    finally:
        yield client.close()
Exemplo n.º 20
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)
Exemplo n.º 21
0
def command(options):
    """Use scp to copy files to/from given unit or machine.

    Unlike juju ssh, no attempt to verify liveness of the agent,
    instead it's just a matter of whether the underlying scp will work
    or not.
    """
    environment = get_environment(options)
    provider = environment.get_machine_provider()
    client = yield provider.connect()
    try:
        paths = [(yield _expand_unit_or_machine(client, provider, path))
                 for path in options.paths]
        open_scp(options.scp_flags, paths)
    finally:
        yield client.close()
Exemplo n.º 22
0
Arquivo: ssh.py Projeto: 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)
Exemplo n.º 23
0
def command(options):
    """
    Bootstrap machine providers in the specified environment.
    """
    environment = get_environment(options)
    provider = environment.get_machine_provider()
    legacy_keys = provider.get_legacy_config_keys()
    if legacy_keys:
        legacy.error(legacy_keys)

    constraint_set = yield provider.get_constraint_set()
    constraints = constraint_set.parse(options.constraints)
    constraints = constraints.with_series(environment.default_series)

    options.log.info(
        "Bootstrapping environment %r (origin: %s type: %s)..." % (
        environment.name, environment.origin, environment.type))
    yield provider.bootstrap(constraints)
Exemplo n.º 24
0
def command(options):
    """
    Terminate all machines and other associated resources for an environment.
    """
    environment = get_environment(options)
    provider = environment.get_machine_provider()

    value = raw_input(
        "WARNING: this command will destroy the %r environment (type: %s).\n"
        "This includes all machines, services, data, and other resources. "
        "Continue [y/N]" % (environment.name, environment.type))

    if value.strip().lower() not in ("y", "yes"):
        options.log.info("Environment destruction aborted")
        returnValue(None)
    options.log.info("Destroying environment %r (type: %s)..." %
                     (environment.name, environment.type))
    yield provider.destroy_environment()
Exemplo n.º 25
0
def command(options):
    """Set service options.

    Service charms may define dynamic options which may be tweaked
    at deployment time, or over the lifetime of the service.  This
    command allows changing these settings.

    $ juju set <service_name> option=value [option=value]

    or

    $ juju set <service_name> --filename local.yaml

    """
    environment = get_environment(options)

    return config_set(environment, options.service_name,
                      options.service_options)
Exemplo n.º 26
0
def command(options):
    """
    Terminate all machines and other associated resources for an environment.
    """
    environment = get_environment(options)
    provider = environment.get_machine_provider()

    value = raw_input(
        "WARNING: this command will destroy the %r environment (type: %s).\n"
        "This includes all machines, services, data, and other resources. "
        "Continue [y/N]" % (
            environment.name, environment.type))

    if value.strip().lower() not in ("y", "yes"):
        options.log.info("Environment destruction aborted")
        returnValue(None)
    options.log.info("Destroying environment %r (type: %s)..." % (
        environment.name, environment.type))
    yield provider.destroy_environment()
Exemplo n.º 27
0
def command(options):
    """Set service options.

    Service charms may define dynamic options which may be tweaked
    at deployment time, or over the lifetime of the service.  This
    command allows changing these settings.

    $ juju set <service_name> option=value [option=value]

    or

    $ juju set <service_name> --filename local.yaml

    """
    environment = get_environment(options)

    return config_set(environment,
                      options.service_name,
                      options.service_options)
Exemplo n.º 28
0
def command(options):
    """Set service options.

    Service charms may define dynamic options which may be tweaked
    at deployment time, or over the lifetime of the service.  This
    command allows changing these settings.

    $ juju set <service_name> option=value [option=value]

    or

    $ juju set <service_name> --config local.yaml

    """
    environment = get_environment(options)

    if options.config:
        if options.service_options:
            raise ServiceConfigValueError(
                "--config and command line options cannot "
                "be used in a single invocation")

        yaml_data = options.config.read()
        try:
            data = yaml.load(yaml_data)
        except yaml.YAMLError:
            raise ServiceConfigValueError(
                "Config file %r not valid YAML" % options.config.name)

        if not data or not isinstance(data, dict):
            raise ServiceConfigValueError(
                "Config file %r invalid" % options.config.name
            )
        data = data.get(options.service_name)

        if data:
            # set data directly
            options.service_options = data

    return config_set(environment,
                      options.service_name,
                      options.service_options)
Exemplo n.º 29
0
def command(options):
    """Get service config options.

    Charms may define dynamic options which may be tweaked at
    deployment time, or over the lifetime of the service.  This
    command allows display the current value of these settings
    in yaml format.

    $ juju get wordpress

    {'service': 'wordpress',
     'charm': 'local:series/wordpress-3',
     'settings': {'blog-title': {
                    'description': 'A descriptive title used for the blog.',
                    'type': 'string',
                    'value': 'Hello World'}}},
    """
    environment = get_environment(options)

    return config_get(environment, options.service_name, options.schema)
Exemplo n.º 30
0
def command(options):
    """Get service config options.

    Charms may define dynamic options which may be tweaked at
    deployment time, or over the lifetime of the service.  This
    command allows display the current value of these settings
    in yaml format.

    $ juju get wordpress

    {'service': 'wordpress',
     'charm': 'local:series/wordpress-3',
     'settings': {'blog-title': {
                    'description': 'A descriptive title used for the blog.',
                    'type': 'string',
                    'value': 'Hello World'}}},
    """
    environment = get_environment(options)

    return config_get(environment,
                      options.service_name,
                      options.schema)
Exemplo n.º 31
0
def command(options):
    """Show currently applicable constraints"""
    environment = get_environment(options)
    return constraints_get(
        options.environments, environment, options.entities, options.log)
Exemplo n.º 32
0
def command(options):
    """Expose a service to the internet."""
    environment = get_environment(options)
    return expose(options.environments, environment, options.verbose, options.log, options.service_name)
Exemplo n.º 33
0
def command(options):
    """Mark an error as resolved in a unit or unit relation."""
    environment = get_environment(options)
    return resolved(options.environments, environment, options.verbose,
                    options.log, options.service_unit_name,
                    options.relation_name, options.retry)
Exemplo n.º 34
0
def command(options):
    """Add a relation between services in juju."""
    environment = get_environment(options)
    return add_relation(options.environments, environment, options.verbose,
                        options.log, *options.descriptors)
Exemplo n.º 35
0
def command(options):
    """Expose a service to the internet."""
    environment = get_environment(options)
    return expose(options.environments, environment, options.verbose,
                  options.log, options.service_name)
Exemplo n.º 36
0
def command(options):
    """Remove a service unit."""
    environment = get_environment(options)
    return remove_unit(options.environments, environment, options.verbose,
                       options.log, options.unit_names)