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
def set_root_password(uuid, rootPassword=None, node=None): """Change the root password on a cloud server by UUID""" if not node: node = get_node(uuid) if not rootPassword: rootPassword = getpass.getpass( "Choose a root password for the new server: ") conn = cloud_connect() conn.ex_set_password(node, rootPassword) while get_node(uuid).state != 0: util.dot()