def dep_installed(command): try: nullf = open(os.devnull, 'w') spcall([command], stdout=nullf) nullf.close() return True except: return False
def write_report(plot_paths): report_path = tex_report(plot_paths) r = report_path.split('/') report_folder = '/'.join(r[:-1]) report_name = '.'.join(r[-1].split('.')[:-1]) spcall(['cd {0};pdflatex {1};mv {2} ..;cd ..;rm -r tmp/'.format(report_folder,report_name+'.tex',report_name+'.pdf')],shell=True)
def call(cmdline, cwd=None): from subprocess import call as spcall try: return spcall(cmdline, cwd=cwd) except OSError as e: raise ExecError("error invoking '%s': %s" % (" ".join(cmdline), e))
def call_or_exit(*args, **kwargs): ret = spcall(*args, **kwargs) if ret != 0: print("Error when calling {} with additional options {}".format(args, kwargs)) print("\nPlease visit us in #linode on the Kubernetes Slack and let us know about " "this error! http://slack.k8s.io/") sys.exit(ret)
def DownloadForge(mcVersion, forgeVersion): filename = FORGE_INSTALLER_TEMPLATE.format(mcVersion, forgeVersion) with open(filename, "wb") as f: if mcVersion in FORGE_DOUBLE_VERSIONS: f.write( Request( FORGE_URL_TEMPLATE_DOUBLE.format(mcVersion, forgeVersion)).content) else: f.write( Request(FORGE_URL_TEMPLATE.format(mcVersion, forgeVersion)).content) print("> Installing Forge", end=" ") sys.stdout.flush() with open(os.devnull, "w") as fnull: spcall([JAVA_PATH + "java", "-jar", filename, "--installServer"], stdout=fnull) os.remove(filename) print("[OK]")
def cls(): from subprocess import call as spcall spcall(["cls"], shell=True)
with BytesIO() as buffer: buffer.write(mods.content) UpdateFromZip(buffer) # --- # [Run updater] if PROFILE.startswith("http://") or PROFILE.startswith( "https://") or PROFILE.startswith("ftp://"): UpdateFromURL(PROFILE) else: UpdateFromZip(PROFILE) # --- # [MC EULA] if MC_EULA == True: if os.path.isfile("eula.txt"): os.remove("eula.txt") with open("eula.txt", "w") as f: f.write("eula=true") # --- # [Run server] spcall([ JAVA_PATH + "java", "-Xms" + str(MEMORY_MIN) + "M", "-Xmx" + str(MEMORY_MAX) + "M", "-jar", FORGE_SERVER_JAR, "nogui" ]) # ---
def create(args, context): # Check if deps are installed needed_deps = check_deps('terraform', 'kubectl') if needed_deps: print('To create a cluster, this command requires {}'.format( ' and '.join(needed_deps))) if 'terraform' in needed_deps: print_terraform_install_help() if 'kubectl' in needed_deps: print_kubectl_install_help() sys.exit(1) tf_var_map = create_varmap(context) parser = argparse.ArgumentParser("{} create".format(plugin_name), add_help=True) parser.add_argument('name', metavar='NAME', type=str, help="A name for the cluster.") # High availability master nodes coming soon. # parser.add_argument('--ha', metavar="MASTERS", type=int, required=False, # choices=[3, 5], # help="Make the cluster highly-available with MASTERS " # "number of masters (3 or 5)") parser.add_argument( '--node-type', metavar="TYPE", type=str, required=False, default=tf_var_map['node_type']['default'], help='The Linode Type ID for cluster Nodes as retrieved with ' '`linode-cli linodes types`. (default "{}")'.format( tf_var_map['node_type']['default'])) parser.add_argument( '--nodes', metavar="COUNT", type=int, required=False, default=tf_var_map['nodes']['default'], help='The number of Linodes to deploy as Nodes in the cluster. ' '(default {})'.format(tf_var_map['nodes']['default'])) parser.add_argument( '--master-type', metavar="TYPE", type=str, required=False, default=tf_var_map['master_type']['default'], help='The Linode Type ID for cluster Master Nodes as retrieved with ' '`linode-cli linodes types`. (default "{}")'.format( tf_var_map['master_type']['default'])) parser.add_argument( '--region', metavar="REGION", type=str, required=False, default=tf_var_map['region']['default'], help= 'The Linode Region ID in which to deploy the cluster as retrieved with ' '`linode-cli regions list`. (default "{}")'.format( tf_var_map['region']['default'])) parser.add_argument( '--ssh-public-key', metavar="KEYPATH", type=str, required=False, default=tf_var_map['ssh_public_key']['default'], help= 'The path to your public key file which will be used to access Nodes ' 'during initial provisioning only! The keypair _must_ be added to an ' 'ssh-agent (default {})'.format( tf_var_map['ssh_public_key']['default'])) parsed, remaining_args = parser.parse_known_args(args) # make sure that the ssh public key exists check_for_pubkey(parsed) # make sure that an ssh-agent is running check_for_ssh_agent(parsed) if not parsed.region: print('You must either configure your default region with ' '`linode-cli configure` or pass --region') sys.exit(1) prefix = get_prefix(parsed.name) # MAJOR @TODO: check here if this prefix already appears as a prefix on any # Volumes, Linodes, or NodeBalancers. If it does, bail with an error message, # because we don't want to later delete resources from an existing cluster! # # Luckily, for now, Terraform will refuse to create the Linodes for the new # cluster with the same names, stopping the cluster from being created (only in # the case where Linodes still exist for an existing cluster). There is still # the issue of zombie NodeBalancers to address. # Make application directory if it doesn't exist appdir = safe_make_appdir("k8s-alpha-linode") # Make the terraform project directory if it doesn't exist terrapath = os.path.join(appdir, parsed.name) safe_mkdir(terrapath) # Move to the directory os.chdir(terrapath) # Generate the terraform file terrafile = open('cluster.tf', 'w') terrafile.write( gen_terraform_file(context, tf_var_map, parsed.name, prefix)) terrafile.close() # Generate terraform args terraform_args = gen_terraform_args(parsed, tf_var_map) # Run the Terraform commands spcall(['terraform', 'workspace', 'new', parsed.name]) call_or_exit(['terraform', 'init']) # TODO: Before running the apply delete any existing Linodes that would # cause the apply to fail. terraform_apply_command = ['terraform', 'apply' ] + terraform_args + remaining_args call_or_exit(terraform_apply_command) # Merge and/or create kubeconfig for the new cluster. # Also, activate the kubeconfig context. safe_mkdir(os.path.expanduser("~/.kube")) # We expect this to be the path to the generated kubeconfig file kubeconfig_new = replace_kubeconfig_user(terrapath, parsed.name, prefix) kubeconfig_existing = os.path.expanduser("~/.kube/config") # Create a merged kubeconfig file and set the context # First set up the KUBECONFIG env var so that `kubectl config view --flatten` # gives us a new merged config os.environ["KUBECONFIG"] = "{}:{}".format(kubeconfig_existing, kubeconfig_new) tempfilepath = 'tempkubeconfig' tempf = open(tempfilepath, 'w') call_or_exit(['kubectl', 'config', 'view', '--flatten'], stdout=tempf) tempf.close() shutil.move(tempfilepath, kubeconfig_existing) # Set the kubeconfig context to the new cluster call_or_exit([ 'kubectl', 'config', 'use-context', '{}@{}'.format(get_kubeconfig_user(prefix, parsed.name), parsed.name) ]) print( "Your cluster has been created and your kubectl context updated.\n\n" "Try the following command: \n" "kubectl get pods --all-namespaces\n\n" "Come hang out with us in #linode on the Kubernetes Slack! http://slack.k8s.io/" )
else: p.append( Popen(shlex.split(cmd_part), stdin=None, stdout=PIPE, stderr=PIPE)) (output, err) = p[-1].communicate() exit_code = p[0].wait() return str(output).strip(), str(err), exit_code """""" """""" """"" Main program starts here """ """""" """""" "" system = platform.system() if (system == "Windows"): statementStatus = spcall("cls", shell=True) else: statementStatus = spcall("reset", shell=True) import os hostname = os.uname()[1] tutorialFile = "hello-world" tutorialName = "Hello World" gitRepo = "Predix-HelloWorld-WebApp" print("$ Welcome to Predix") """""" """""" """"" Dropbox """ """""" """""" "" if hostname == "predix-devbox": print("$ Would you to like save your work in your Dropbox account?") print("1. Yes") print("2. No thanks")