def machines_teardown(arg_vars, project_root): cluster_id = arg_vars['cluster_id'] profile_id = arg_vars['profile_id'] f = util.machine_profile_file(project_root, cluster_id, profile_id) print_ok_pending("Removing machines provisioned with profile id " + profile_id) if verify_profile_exists(arg_vars, project_root): with open(f, "r") as stream: content = yaml.load(stream) content['n_machine_instances'] = 0 with open(f, "w") as stream: stream.write(yaml.dump(content)) tpl = util.machines_remove_template() with open(util.machines_remove_file(project_root), "w") as handle: handle.write(tpl.render(profile=profile_id)) print_ok_pending("Scaling down instances. Streaming Ansible output") invoke_ansible(arg_vars, project_root, "machines_remove.yml") call(["rm", f]) print(bcolors.OKBLUE + bcolors.BOLD + "> Finished scale down." + bcolors.ENDC)
def cluster_teardown(arg_vars, project_root): print_ok_pending("Tearing down all machine profiles") print("") cluster_id = arg_vars['cluster_id'] path = util.machine_profiles_path(project_root, cluster_id) files = [f for f in listdir(path) if isfile(join(path, f))] for f in files: with open(path + "/" + f, 'r') as stream: content = yaml.load(stream) arg_vars['profile_id'] = content['profile_id'] machines_teardown(arg_vars, project_root) print_ok_pending("Tearign down the VPC") tpl = util.cluster_remove_template() with open(util.cluster_remove_file(project_root), "w") as text_file: path = project_root + "/ansible/roles" services = next(walk(path))[1] text_file.write(tpl.render(services=services)) invoke_ansible(arg_vars, project_root, util.cluster_remove_playbook()) call(["rm", util.cluster_file(project_root, cluster_id)]) call(["rm", "-r", util.cluster_path(project_root, cluster_id)]) print_done("Finished running Ansible.")
def deploy(arg_vars, project_root): organization = arg_vars['dockerhub_username'] version = check_output(["lein", "project-version"]).strip() project_name = os.path.relpath(project_root, "..") image = organization + "/" + project_name + ":" + version if not arg_vars.get('skip_uberjar'): print_ok_pending("Creating an uberjar for your project. Streaming Leiningen output") call(["lein", "uberjar"]) print_done("Finished creating the uberjar.") print("") print_ok_pending("Creating a container. Streaming Docker output") call(["docker", "build", "-t", image, project_root]) print_done("Finished building container image " + image + ".") print("") print_ok_pending("Uploading image to DockerHub") call(["docker", "push", image]) print_done("Finished pushing image.") print("") print_ok_pending("Updating Ansible deployment playbook") refresh_deployment_playbook(arg_vars, project_root) print_done("Ansible playbook update complete.") print("") print_ok_pending("Running Ansible deployment playbook. Streaming Ansible output") invoke_ansible(arg_vars, project_root, "deploy.yml", {"onyx_docker_image": image, "onyx_tenancy_id": arg_vars['tenancy_id'], "onyx_n_peers": arg_vars['n_peers']}) print_done("Finished running Ansible. Onyx has been successfully deployed.")
def job_submit(arg_vars, project_root): print_ok_pending("Invoking Ansible and streaming its output") refresh_submit_playbook(arg_vars, project_root) invoke_ansible(arg_vars, project_root, util.job_submit_playbook(), {"onyx_job_name": arg_vars['job_name']}) print_done("Finished running Ansible.")
def cluster_provision(arg_vars, project_root): print_ok_pending("Invoking Ansible and streaming its output") cluster_id = arg_vars['cluster_id'] refresh_provisioning_playbook(arg_vars, project_root) invoke_ansible(arg_vars, project_root, util.provisioning_playbook(cluster_id)) invoke_ansible(arg_vars, project_root, util.post_provisioning_playbook(cluster_id)) print_done("Finished running Ansible.")
def machines_cache(arg_vars, project_root): print_ok_pending("Updating local cache of cluster machines. Streaming Ansible output") config = ConfigParser.ConfigParser() engraver_profile = expanduser("~") + "/.engraver" config.read(engraver_profile) aws_key_name = config.get('aws', 'aws_key_name', 0) pem_file_path = config.get('aws', 'pem_file_name', 0) if(verify_cluster_exists(arg_vars, project_root)): invoke_ansible(arg_vars, project_root, util.refresh_cache_playbook()) print_done("Finished updating local cache. Displaying cluster: ") machines_list(arg_vars, project_root, hint=False)
def machines_cache(arg_vars, project_root): print_ok_pending( "Updating local cache of cluster machines. Streaming Ansible output") config = ConfigParser.ConfigParser() engraver_profile = expanduser("~") + "/.engraver" config.read(engraver_profile) aws_key_name = config.get('aws', 'aws_key_name', 0) pem_file_path = config.get('aws', 'pem_file_name', 0) if (verify_cluster_exists(arg_vars, project_root)): invoke_ansible(arg_vars, project_root, util.refresh_cache_playbook()) print_done("Finished updating local cache. Displaying cluster: ") machines_list(arg_vars, project_root, hint=False)
def deploy(arg_vars, project_root): organization = arg_vars['dockerhub_username'] version = check_output(["lein", "project-version"]).strip() project_name = os.path.relpath(project_root, "..") image = organization + "/" + project_name + ":" + version if not arg_vars.get('skip_uberjar'): print_ok_pending( "Creating an uberjar for your project. Streaming Leiningen output") call(["lein", "uberjar"]) print_done("Finished creating the uberjar.") print("") print_ok_pending("Creating a container. Streaming Docker output") call(["docker", "build", "-t", image, project_root]) print_done("Finished building container image " + image + ".") print("") print_ok_pending("Uploading image to DockerHub") call(["docker", "push", image]) print_done("Finished pushing image.") print("") print_ok_pending("Updating Ansible deployment playbook") refresh_deployment_playbook(arg_vars, project_root) print_done("Ansible playbook update complete.") print("") print_ok_pending( "Running Ansible deployment playbook. Streaming Ansible output") invoke_ansible( arg_vars, project_root, "deploy.yml", { "onyx_docker_image": image, "onyx_tenancy_id": arg_vars['tenancy_id'], "onyx_n_peers": arg_vars['n_peers'] }) print_done( "Finished running Ansible. Onyx has been successfully deployed.")
def machines_teardown(arg_vars, project_root): cluster_id = arg_vars['cluster_id'] profile_id = arg_vars['profile_id'] f = util.machine_profile_file(project_root, cluster_id, profile_id) print_ok_pending("Removing machines provisioned with profile id " + profile_id) if verify_profile_exists(arg_vars, project_root): with open(f, "r") as stream: content = yaml.load(stream) content['n_machine_instances'] = 0 with open(f, "w") as stream: stream.write(yaml.dump(content)) tpl = util.machines_remove_template() with open(util.machines_remove_file(project_root), "w") as handle: handle.write(tpl.render(profile = profile_id)) print_ok_pending("Scaling down instances. Streaming Ansible output") invoke_ansible(arg_vars, project_root, "machines_remove.yml") call(["rm", f]) print(bcolors.OKBLUE + bcolors.BOLD + "> Finished scale down." + bcolors.ENDC)