Exemple #1
0
def provision():
    """Create a new cloud server instance"""
    if "server" not in env:
        util.exit("Please specify a target server")
    conn = cloud_connect()
    image = choose_cloud_option(conn.list_images, IMAGE_RE, "image")
    size = choose_cloud_option(conn.list_sizes, SIZE_RE, "size")
    root_password = getpass.getpass(
        "Choose a root password for the new server: ")
    ssh_key = util.get_ssh_key()
    users = ScriptDeployment(debian.make_user_script(os.environ["USER"], ssh_key))

    # a task that first installs the ssh key, and then runs the script
    msd = MultiStepDeployment([SSHKeyDeployment(ssh_key), users])
    out("Creating %s (%s) on %s" % (image.name, size.name, image.driver.name))
    node = conn.deploy_node(name=env.server["name"], image=image, size=size,
        deploy=msd)
    out(node)
    while get_node(node.uuid).state != 0:
        dot()
    out("Node is up.")
    env.hosts[0] = env.host_string = node.public_ips[0]
    conf = server_conf.read(SERVER_CONF_PATH)
    conf[env.server["label"]]["hostname"] = node.public_ips[0]
    server_conf.write(conf, SERVER_CONF_PATH)
    set_root_password(node.uuid, root_password)
    #Make my shell zsh
    with settings(user="******"):
        packages.apt("zsh")
        login = os.environ["USER"]
        util.script("chsh --shell /bin/zsh " + login, name="Use zshell")
        out("Please set a password for %s on %s" % (login, env.host_string))
        run("passwd " + login)
    return node
Exemple #2
0
def cloud_connect():
    """Prompt for credentials if needed and return cloud driver"""
    global api_key
    global username
    cert_path = os.path.join(os.path.dirname(__file__), "python", "cacert.pem")
    if not os.path.exists(cert_path):
        out("Installing CA Certificates for Cloud APIs")
        request = requests.get("http://curl.haxx.se/ca/cacert.pem")
        if request.status_code > 299:
            exit("Could not download CA Certs from %s", EC_NETWORK)
        with open(cert_path, "wb") as cert_file:
            cert_file.write(request.content)
    libcloud.security.VERIFY_SSL_CERT = True
    libcloud.security.CA_CERTS_PATH.append(cert_path)
    if not username:
        username = raw_input("RackSpace Username: "******"RackSpace API Key: ")
    Driver = get_driver(Provider.RACKSPACE)
    return Driver(username, api_key)
Exemple #3
0
def destroy(uuid):
    """Permanently delete a cloud server instance by UUID"""
    get_node(uuid).destroy()
    out("Node %s destroyed" % uuid)
Exemple #4
0
def status(conn=None):
    """Show status of cloud servers"""
    if not conn:
        conn = cloud_connect()
    [out(n) for n in conn.list_nodes()]