Example #1
0
def provision_nodes(num, next_id):
    info("Provisioning %d new node(s)" % (num))
    nodes = env.provider_provision_function(num, next_id)
    use_only(*nodes)
    wait_for_ssh_access()
    if "provider_post_provision_hook" in env:
        env.provider_post_provision_hook()
Example #2
0
def scale_down():
    """Removes excess nodes from the load balancer (thus extra nodes are made into inactive nodes)."""
    use_only(*classify_nodes()[EXTRA])
    if len(env.nodes) == 0:
        info("There are no extra nodes to scale down.")
    else:
        lb_remove_nodes()
Example #3
0
def install_datadog_agent(datadog_api_key = None):
    """
    Installs the Datadog agent.
    :param datadog_api_key: interpreted via get_datadog_api_key
    """
    info("Installing Datadog agent.")
    # Per https://app.datadoghq.com/account/settings#agent/ubuntu
    sudo('DD_API_KEY=%s bash -c "$(wget -qO- http://dtdg.co/agent-install-ubuntu)"' % get_datadog_api_key(datadog_api_key))
Example #4
0
def decommission_unused():
    """De-provisions inactive and orphan nodes."""
    configure()
    nodes = classify_nodes()
    use_only(*nodes[INACTIVE] + nodes[ORPHAN])
    if len(env.nodes) == 0:
        info("There are no inactive or orphan nodes to decommission.")
    else:
        decommission_nodes()
Example #5
0
def decommission_all():
    """De-provisions all nodes."""
    configure()
    use_only(*instances_with_platform_and_role(env.platform, env.role))
    if len(env.nodes) == 0:
        info("There are no nodes to decommission.")
    else:
        show()
        if confirm("Are you sure you want to decommission ALL %d nodes?" % len(env.nodes), default=False):
            decommission_nodes()
Example #6
0
def add_datadog_agent_tags(dd_hostname = None, datadog_tags = None):
    """
    Applies node-specific information to the Datadog agent configuration.
    :param hostname: ideally the node ID
    :param datadog_tags: interpreted via get_datadog_tags
    """
    dd_hostname = dd_hostname or current_node().tags.get("Name")
    tags = ','.join(get_datadog_tags(datadog_tags))
    info("Updating Datadog configuration with tag(s): %s." % tags)
    # Force the hostname to what we want
    sed('/etc/dd-agent/datadog.conf', '^[# ]?hostname:.*', 'hostname: %s' % dd_hostname, use_sudo=True)
    # Apply some tags
    sed('/etc/dd-agent/datadog.conf', '^[# ]?tags:.*', 'tags: %s' % tags, use_sudo=True)
    # Let the agent vacuum up EC2 tags
    # # collect_ec2_tags: no
    sed('/etc/dd-agent/datadog.conf', '^[# ]?collect_ec2_tags:.*', 'collect_ec2_tags: yes', use_sudo=True)
    sudo('service datadog-agent restart')
Example #7
0
def decommission_nodes():
    "Stop instances"
    info("Decommissioning node(s) %s." % pretty_instances(env.nodes))
    env.provider_decommission_function()
Example #8
0
def wait_for_ssh_access():
    execute(connect)
    info("All nodes are now online. %s (%s)" % (env.hosts, env.nodes))