def create_session(self, session_type='bash', docker_image=None, rm=None, loglevel='INFO'): assert isinstance(session_type, str) new_shutit = ShutIt() self.add_shutit_session(new_shutit) # TODO: only makes sense in session that's already bash - check this if session_type == 'bash': shutit_util.parse_args(new_shutit) shutit_util.load_configs(shutit=new_shutit) shutit_setup.setup_host_child_environment(new_shutit) return new_shutit elif session_type == 'docker': shutit_util.parse_args(new_shutit, set_loglevel=loglevel) # Set the configuration up appropriately using overrides. if docker_image: new_shutit.build['config_overrides'].append( ['build', 'base_image', docker_image]) if rm: new_shutit.target['rm'] = True # Now 'load' the configs shutit_util.load_configs(new_shutit) target_child = shutit_setup.conn_docker_start_container( new_shutit, 'target_child') shutit_setup.setup_host_child_environment(new_shutit) shutit_setup.setup_target_child_environment( new_shutit, target_child) return new_shutit else: new_shutit.fail('unhandled session type: ' + session_type)
def create_session_vagrant(self, session_name, num_machines, vagrant_image, vagrant_provider, gui, memory, swapsize, echo, walkthrough, walkthrough_wait, nocolor, vagrant_version, virt_method, root_folder, cpu, loglevel): new_shutit = ShutIt(standalone=True, session_type='vagrant') self.shutit_objects.append(new_shutit) # Vagrant is: delivery over bash, but running the vagrant scripts first. new_shutit.process_args( ShutItInit('build', delivery='bash', echo=echo, walkthrough=walkthrough, walkthrough_wait=walkthrough_wait, nocolor=nocolor, loglevel=loglevel)) new_shutit.load_configs() new_shutit.setup_host_child_environment() # Run vagrant setup now vagrant.pre_build(shutit=new_shutit, vagrant_version=vagrant_version, virt_method=virt_method) machines = vagrant.setup_machines(new_shutit, vagrant_image, virt_method, gui, memory, root_folder, session_name, swapsize, num_machines, cpu) new_shutit.vagrant_machines = machines return new_shutit
def create_session_vagrant(self, session_name, num_machines, vagrant_image, vagrant_provider, gui, memory, swapsize, echo, walkthrough, walkthrough_wait, nocolor, vagrant_version, virt_method, root_folder, cpu, loglevel): new_shutit = ShutIt(standalone=True, session_type='vagrant') self.shutit_objects.append(new_shutit) # Vagrant is: delivery over bash, but running the vagrant scripts first. new_shutit.process_args(ShutItInit('build', delivery='bash', echo=echo, walkthrough=walkthrough, walkthrough_wait=walkthrough_wait, nocolor=nocolor, loglevel=loglevel)) new_shutit.load_configs() new_shutit.setup_host_child_environment() # Run vagrant setup now vagrant.pre_build(shutit=new_shutit, vagrant_version=vagrant_version, virt_method=virt_method) machines = vagrant.setup_machines(new_shutit, vagrant_image, virt_method, gui, memory, root_folder, session_name, swapsize, num_machines, cpu) new_shutit.vagrant_machines = machines return new_shutit
def create_session(self, session_type='bash', docker_image=None, rm=None): assert isinstance(session_type, str) new_shutit = ShutIt(standalone=True) self.add_shutit_session(new_shutit) if session_type == 'bash': new_shutit.process_args(ShutItInit('build', delivery='bash')) # TODO: can we get rid of/rationalise load_configs? new_shutit.load_configs() new_shutit.setup_host_child_environment() return new_shutit elif session_type == 'docker': new_shutit.process_args(ShutItInit('build', delivery='docker', base_image=docker_image)) new_shutit.target['rm'] = rm # TODO: can we get rid of/rationalise load_configs? new_shutit.load_configs() target_child = new_shutit.conn_docker_start_container('target_child') new_shutit.setup_host_child_environment() new_shutit.setup_target_child_environment(target_child) return new_shutit else: new_shutit.fail('unhandled session type: ' + session_type)
elif self.loglevel == 'ERROR': logging.basicConfig(format=logformat,filename=self.logfile,level=logging.ERROR) elif self.loglevel in ('WARN','WARNING'): logging.basicConfig(format=logformat,filename=self.logfile,level=logging.WARNING) elif self.loglevel == 'CRITICAL': logging.basicConfig(format=logformat,filename=self.logfile,level=logging.CRITICAL) elif self.loglevel == 'INFO': logging.basicConfig(format=logformat,filename=self.logfile,level=logging.INFO) else: logging.basicConfig(format=logformat,filename=self.logfile,level=logging.DEBUG) self.loglevel = logging.getLogger().getEffectiveLevel() def handle_exit(self,exit_code=0,loglevel=logging.DEBUG,msg=None): if not msg: msg = '\nExiting with error code: ' + str(exit_code) if exit_code != 0: self.log('Exiting with error code: ' + str(exit_code),level=loglevel) self.log('Resetting terminal',level=loglevel) shutit_util.sanitize_terminal() sys.exit(exit_code) def setup_signals(): signal.signal(signal.SIGINT, shutit_util.ctrl_c_signal_handler) signal.signal(signal.SIGQUIT, shutit_util.ctrl_quit_signal_handler) shutit_global_object = ShutItGlobal() shutit_global_object.add_shutit_session(ShutIt(standalone=False))
def create_session(self, session_type='bash', docker_image=None, rm=None, echo=False, walkthrough=False, walkthrough_wait=-1, nocolor=False, loglevel=''): assert isinstance(session_type, str), shutit_util.print_debug() new_shutit = ShutIt(standalone=True, session_type=session_type) self.shutit_objects.append(new_shutit) if session_type == 'bash': new_shutit.process_args( ShutItInit('build', delivery='bash', echo=echo, walkthrough=walkthrough, walkthrough_wait=walkthrough_wait, loglevel=loglevel)) new_shutit.load_configs() new_shutit.setup_host_child_environment() return new_shutit elif session_type == 'docker': new_shutit.process_args( ShutItInit('build', delivery='docker', base_image=docker_image, echo=echo, walkthrough=walkthrough, walkthrough_wait=walkthrough_wait, loglevel=loglevel)) new_shutit.target['rm'] = rm target_child = new_shutit.conn_docker_start_container( 'target_child') new_shutit.setup_host_child_environment() new_shutit.setup_target_child_environment(target_child) return new_shutit new_shutit.fail('unhandled session type: ' + session_type) return new_shutit
def __str__(self): return self.line_str def setup_signals(): """Set up the signal handlers. """ signal.signal(signal.SIGINT, shutit_util.ctrl_c_signal_handler) signal.signal(signal.SIGQUIT, shutit_util.ctrl_quit_signal_handler) def get_shutit_pexpect_sessions(): """Returns all the shutit_pexpect_sessions in existence. """ sessions = [] for shutit_object in shutit_global_object.shutit_objects: for key in shutit_object.shutit_pexpect_sessions: sessions.append(shutit_object.shutit_pexpect_sessions[key]) return sessions shutit_global_object = ShutItGlobal() # Only at this point can we import other modules, otherwise we get race failures. from shutit_class import ShutIt, ShutItInit import shutit_util # Create default shutit object. TODO: do we need this? shutit_global_object.shutit_objects.append( ShutIt(standalone=False, session_type='bash'))
transient=False, newline=True, mask_password=True): """Logging function. @param add_final_message: Add this log line to the final message output to the user @param level: Python log level @param transient: Just write to terminal, no new line. If not a terminal, write nothing. """ if mask_password: for password in shutit_global_object.secret_words_set: if password in msg: msg.replace(password, 'REDACTED') if transient: if sys.stdout.isatty(): if newline: msg += '\r\n' sys.stdout.write(msg) else: return True else: logging.log(level, msg) if add_final_message: self.report_final_messages = self.report_final_messages + '\r\n' + msg + '\r\n' return True shutit_global_object = ShutItGlobal() shutit_global_object.add_shutit_session(ShutIt())
def create_session(self, session_type='bash', docker_image=None, rm=None, echo=False, walkthrough=False, walkthrough_wait=-1, nocolor=False, loglevel='WARNING'): assert isinstance(session_type, str), shutit_util.print_debug() new_shutit = ShutIt(standalone=True, session_type=session_type) self.shutit_objects.append(new_shutit) if session_type == 'bash': new_shutit.process_args(ShutItInit('build', delivery='bash', echo=echo, walkthrough=walkthrough, walkthrough_wait=walkthrough_wait, loglevel=loglevel)) new_shutit.load_configs() new_shutit.setup_host_child_environment() return new_shutit elif session_type == 'docker': new_shutit.process_args(ShutItInit('build', delivery='docker', base_image=docker_image, echo=echo, walkthrough=walkthrough, walkthrough_wait=walkthrough_wait, loglevel=loglevel)) new_shutit.target['rm'] = rm target_child = new_shutit.conn_docker_start_container('target_child') new_shutit.setup_host_child_environment() new_shutit.setup_target_child_environment(target_child) return new_shutit new_shutit.fail('unhandled session type: ' + session_type) return new_shutit
self.time_seen = time_seen def __str__(self): return self.line_str def setup_signals(): """Set up the signal handlers. """ signal.signal(signal.SIGINT, shutit_util.ctrl_c_signal_handler) signal.signal(signal.SIGQUIT, shutit_util.ctrl_quit_signal_handler) def get_shutit_pexpect_sessions(): """Returns all the shutit_pexpect_sessions in existence. """ sessions = [] for shutit_object in shutit_global_object.shutit_objects: for key in shutit_object.shutit_pexpect_sessions: sessions.append(shutit_object.shutit_pexpect_sessions[key]) return sessions shutit_global_object = ShutItGlobal() # Only at this point can we import other modules, otherwise we get race failures. from shutit_class import ShutIt, ShutItInit import shutit_util # Create default shutit object. TODO: do we need this? shutit_global_object.shutit_objects.append(ShutIt(standalone=False, session_type='bash'))
def create_session(self, session_type='bash', docker_image=None, rm=None, echo=False, walkthrough=False, walkthrough_wait=-1, nocolor=False, loglevel='WARNING'): assert isinstance(session_type, str) new_shutit = ShutIt(standalone=True) self.add_shutit_session(new_shutit) self.nocolor = nocolor if session_type == 'bash': new_shutit.process_args( ShutItInit('build', delivery='bash', echo=echo, walkthrough=walkthrough, walkthrough_wait=walkthrough_wait, log=loglevel)) # TODO: can we get rid of/rationalise load_configs? new_shutit.load_configs() new_shutit.setup_host_child_environment() return new_shutit elif session_type == 'docker': new_shutit.process_args( ShutItInit('build', delivery='docker', base_image=docker_image, echo=echo, walkthrough=walkthrough, walkthrough_wait=walkthrough_wait, log=loglevel)) new_shutit.target['rm'] = rm # TODO: can we get rid of/rationalise load_configs? new_shutit.load_configs() target_child = new_shutit.conn_docker_start_container( 'target_child') new_shutit.setup_host_child_environment() new_shutit.setup_target_child_environment(target_child) return new_shutit new_shutit.fail('unhandled session type: ' + session_type) return new_shutit