def checkout_branch(git_branch, install_dir): cmd = "cd {} && git checkout {}".format(install_dir, git_branch) sys.stdout.write("cmd={}".format(cmd)) exit_status, stdout = ssh_utils.run_cmd(cmd) current_branch = get_express_branch(git_branch, install_dir) if current_branch != git_branch: return(False) return(True)
def get_express_cli_branch(): if not os.path.isdir(globals.EXPRESS_CLI_INSTALL_DIR): return(None) cmd = "cd {} && git symbolic-ref --short -q HEAD".format(globals.EXPRESS_CLI_INSTALL_DIR) exit_status, stdout = ssh_utils.run_cmd(cmd) if exit_status != 0: return(None) return(stdout[0].strip())
def get_express_branch(git_branch, repo_basedir): if not os.path.isdir(repo_basedir): return(None) cmd = "cd {} && git symbolic-ref --short -q HEAD".format(repo_basedir) exit_status, stdout = ssh_utils.run_cmd(cmd) if exit_status != 0: return(None) return(stdout[0].strip())
def checkout_branch(git_branch): cmd = "cd {} && git checkout {}".format(globals.EXPRESS_INSTALL_DIR, git_branch) exit_status, stdout = ssh_utils.run_cmd(cmd) current_branch = get_express_branch(git_branch) if current_branch != git_branch: return (False) return (True)
def install_express(du): sys.stdout.write("\nInstalling PF9-Express (branch = {})\n".format( du['git_branch'])) if not os.path.isdir(globals.EXPRESS_INSTALL_DIR): cmd = "git clone {} {}".format(globals.EXPRESS_REPO, globals.EXPRESS_INSTALL_DIR) sys.stdout.write("--> cloning repository ({})\n".format(cmd)) exit_status, stdout = ssh_utils.run_cmd(cmd) if not os.path.isdir(globals.EXPRESS_INSTALL_DIR): sys.stdout.write("ERROR: failed to clone PF9-Express Repository\n") return (False) sys.stdout.write("--> refreshing repository (git fetch -a)\n") cmd = "cd {}; git fetch -a".format(globals.EXPRESS_INSTALL_DIR) exit_status, stdout = ssh_utils.run_cmd(cmd) if exit_status != 0: sys.stdout.write("ERROR: failed to fetch branches (git fetch -)\n") return (False) current_branch = get_express_branch(du['git_branch']) sys.stdout.write("--> current branch: {}\n".format(current_branch)) if current_branch != du['git_branch']: sys.stdout.write("--> switching branches: {}\n".format( du['git_branch'])) if (checkout_branch(du['git_branch'])) == False: sys.stdout.write( "ERROR: failed to checkout git branch: {}\n".format( du['git_branch'])) return (False) cmd = "cd {}; git pull origin {}".format(globals.EXPRESS_INSTALL_DIR, du['git_branch']) sys.stdout.write("--> pulling latest code (git pull origin {})\n".format( du['git_branch'])) exit_status, stdout = ssh_utils.run_cmd(cmd) if exit_status != 0: sys.stdout.write( "ERROR: failed to pull latest code (git pull origin {})\n".format( du['git_branch'])) return (False) return (True)
def activate_config(url): sys.stdout.write("--> Activating configuration file: {}\n".format(url)) cmd = "express config activate {}".format(url) exit_status, stdout = ssh_utils.run_cmd(cmd) if exit_status != 0: for l in stdout: sys.stdout.write(l) return(False) return(True)
def install_express_cli(): if not os.path.isdir(globals.EXPRESS_CLI_INSTALL_DIR): cmd = "git clone {} {}".format(globals.EXPRESS_CLI_URL, globals.EXPRESS_CLI_INSTALL_DIR) sys.stdout.write("--> cloning repository ({})\n".format(cmd)) exit_status, stdout = ssh_utils.run_cmd(cmd) if not os.path.isdir(globals.EXPRESS_CLI_INSTALL_DIR): sys.stdout.write("ERROR: failed to clone Express-CLI Repository\n") return(False) sys.stdout.write("--> refreshing repository (git fetch -a)\n") cmd = "cd {}; git fetch -a".format(globals.EXPRESS_CLI_INSTALL_DIR) exit_status, stdout = ssh_utils.run_cmd(cmd) if exit_status != 0: sys.stdout.write("ERROR: failed to fetch branches (git fetch -)\n") return(False) current_branch = get_express_cli_branch() sys.stdout.write("--> current branch: {}\n".format(current_branch)) sys.stdout.write("--> target branch: {}\n".format(globals.ctx['platform9']['express_cli_branch'])) if current_branch != globals.ctx['platform9']['express_cli_branch']: sys.stdout.write("--> switching branches: {}\n".format(globals.ctx['platform9']['express_cli_branch'])) if (checkout_branch(globals.ctx['platform9']['express_cli_branch'],globals.EXPRESS_CLI_INSTALL_DIR)) == False: sys.stdout.write("ERROR: failed to checkout git branch: {}\n".format(globals.EXPRESS_CLI_BRANCH)) return(False) cmd = "cd {}; git pull origin {}".format(globals.EXPRESS_CLI_INSTALL_DIR,globals.ctx['platform9']['express_cli_branch']) sys.stdout.write("--> pulling latest code (git pull origin {})\n".format(globals.ctx['platform9']['express_cli_branch'])) exit_status, stdout = ssh_utils.run_cmd(cmd) if exit_status != 0: sys.stdout.write("ERROR: failed to pull latest code (git pull origin {})\n".format(globals.ctx['platform9']['express_cli_branch'])) return(False) sys.stdout.write("--> pip installing express-cli\n") cmd = "cd {}; pip install -e .".format(globals.EXPRESS_CLI_INSTALL_DIR) exit_status, stdout = ssh_utils.run_cmd(cmd) if exit_status != 0: for line in stdout: sys.stdout.write("{}\n".format(line)) sys.stdout.write("ERROR: initialization failed\n") return(False) return(True)
def build_config(url, username, password, tenant, region): sys.stdout.write("--> building configuration file\n") cmd = "express config create --du_url {} --os_username {} --os_password '{}' --os_region {} --os_tenant {}".format( url.replace('https://',''), username, password, region, tenant ) exit_status, stdout = ssh_utils.run_cmd(cmd) if exit_status != 0: for l in stdout: sys.stdout.write(l) return(False) return(True)
def validate_installation(): exit_status, stdout = ssh_utils.run_cmd("express --version") if exit_status == 0: return(True) return(False)