def destroy(self): Static.figletcyber("DESTROY CLUSTER") if self.settings.provision.cloud == "aws": self.kops.destroy_cluster() elif self.settings.provision.cloud == "minikube": self.minikube.delete() else: Static.msg_bold("No such provisioner specified in config", self.settings.provision.cloud) raise SystemExit(32)
def check_alive(self): Static.figletcyber("STATUS") # not implemented if self.settings.provision.cloud == "aws": pass elif self.settings.provision.cloud == "minikube": pass else: Static.msg_bold("No such provisioner specified in config", self.settings.provision.cloud) raise SystemExit(32)
def start(self): Static.figletcyber("PROVISIONING") if self.settings.provision.cloud == "aws": self.kops.create_cluster() self.kops.update_settings() self.kops.provision_cluster() elif self.settings.provision.cloud == "minikube": self.minikube.config_vm_virtualbox() self.minikube.start() self.minikube.confirm_started() else: Static.msg_bold("No such provisioner specified in config", self.settings.provision.cloud) raise SystemExit(32)
def local_run_get_out_raw(name, cmd): proc1 = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, preexec_fn=os.setsid) out = proc1.communicate() if proc1.returncode != 0: Static.msg_bold("FAIL", name.upper()) sys.stdout.write(out[1]) raise SystemExit(32) return out[0]
def local_run_long(name, cmd): proc1 = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, preexec_fn=os.setsid) while proc1.returncode is None: for line in proc1.stdout: sys.stdout.write(line) proc1.poll() if proc1.returncode != 0: Static.msg_bold("FAIL", name.upper()) for line in iter(proc1.stderr.readline, ''): sys.stdout.write(line) raise SystemExit(32)
def local_run_realtime_continue_on_fail(name, cmd): proc1 = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) # Poll process for new output until finished while True: nextline = proc1.stdout.readline() if nextline == '' and proc1.poll() is not None: break sys.stdout.write(nextline) sys.stdout.flush() output = proc1.communicate() if proc1.returncode != 0: Static.msg_bold("FAIL {0}".format(name.upper()), output[1])
def load_clusterfile(self): clusterfile_data = None if os.path.isfile(self.settings.clusterfile): clusterfile_data = yaml.load(open(self.settings.clusterfile), Loader=yamlordereddictloader.Loader) else: Static.msg_bold("Clusterfile not found", self.settings.clusterfile) #if os.path.isfile(clusterfile_config_path): # clusterfile_data = yaml.load(open(self.settings.clusterfile), Loader=yamlordereddictloader.Loader) #else: # clusterfile_data = yaml.load(open(clusterfile_app_path), Loader=yamlordereddictloader.Loader) clusterfile_struct = Struct(**clusterfile_data) self.cluster = Struct(**clusterfile_struct.cluster) self.provision = Struct(**clusterfile_struct.provision) self.elements = clusterfile_data['elements'] '''
def switch_check(in_passed): # check if different different = False if in_passed != self.settings.clusterfile: different = True else: return False if different: if os.path.isfile( os.path.join( os.path.join( os.path.dirname(os.path.realpath(__file__)), "clusters/"), in_passed)): return True else: Static.msg_bold( "Error", "Clusterfile file {0} does not exist. Cannot continue." .format(in_passed)) raise SystemExit(99)
def local_sudo_prompt_run(name, cmd): password = None if not os.geteuid() == 0: print print "You must be root to run this command." print password = getpass.getpass() print #proc1 = subprocess.Popen(['sudo', '-p', '-k', '-S', cmd], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) proc1 = subprocess.Popen('/usr/bin/sudo -p -k -S {0}'.format(cmd), shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out = proc1.communicate(input='{0}\n'.format(password)) if proc1.returncode != 0: Static.msg_bold( "Password failed most likely. Possibly some other error. Inspect below.", name.upper()) print out raise SystemExit(32)
def set_clusterfile(self): # name is file without extension # save name and filename # init has to replace internal name #is in args # is in app or user space #is same as settings #pass def switch_check(in_passed): # check if different different = False if in_passed != self.settings.clusterfile: different = True else: return False if different: if os.path.isfile( os.path.join( os.path.join( os.path.dirname(os.path.realpath(__file__)), "clusters/"), in_passed)): return True else: Static.msg_bold( "Error", "Clusterfile file {0} does not exist. Cannot continue." .format(in_passed)) raise SystemExit(99) filepath_app_settings_clusterfile = os.path.join( self.folder_app_clusters, self.settings.clusterfile) filepath_user_settings_clusterfile = os.path.join( self.folder_user_clusters, self.settings.clusterfile) args_clusterfile = None if self.args.provision: args_clusterfile = self.args.provision elif self.args.clusterfile: args_clusterfile = self.args.clusterfile filepath_app_args_clusterfile = None filepath_user_args_clusterfile = None if args_clusterfile: # args present - settings UPDATE will happen filepath_app_args_clusterfile = os.path.join( self.folder_app_clusters, args_clusterfile) filepath_user_args_clusterfile = os.path.join( self.folder_user_clusters, args_clusterfile) # check which one exist # put that one in settings if os.path.isfile(filepath_app_args_clusterfile): self.settings.clusterfile = filepath_app_args_clusterfile elif os.path.isfile(filepath_user_args_clusterfile): self.settings.clusterfile = filepath_user_args_clusterfile else: Static.msg_bold( "Clusterfile Not Found. Cannot Continue. Run madcore with -c flag", filepath_app_args_clusterfile) raise SystemExit(98) else: # using from settings, check if exists if os.path.isfile(self.settings.clusterfile): Static.msg("Default clusterfile remains as", self.settings.clusterfile) else: Static.msg_bold( "Clusterfile Not Found. Cannot Continue. Run madcore with -c flag to specify new.", self.settings.clusterfile) raise SystemExit(99) '''