def run(root, *args, **kwargs): name = args[0].strip() if args else None if name: args = list(args) args.pop(0) mounting = root.project['mounting'].get(name) if mounting: logger.success(u'Prepare mounting <b>%s</b> to be created.' % mounting.name) else: logger.error(u'Mounting <b>%s</b> unknow.' % name) exit(1) else: mounting = root.mounting if not mounting.is_localhost: logger.cmd('Create machine <b>%s</b>' % (mounting.docker_machine_name, )) logger.cmd('With driver <b>%s</b>' % (mounting.get_machine_driver(), )) cmd = root.bash( mounting.docker_machine_bin, 'rm', mounting.docker_machine_name, #root.compose.name, *args, is_system=True) else: logger.warning(mounting.LOCAL_MACHINE_WARNING)
def run_command(self, name, *args): commands = self['commands'] commands < self.mounting['commands'] if name in commands: command = commands[name] logger.cmd('Run custom command <b>%s</b>' % (command.name, )) for line in command.commands: if line == name: logger.error('Comand loop error: <b>%s</b>' % (line, )) else: # TODO: Improve with @mounting detection and Split by | and < or > if self.root.current_mounting and line.split( )[-1][0] != '@': local_args = tuple(args) + ( '@%s' % self.root.current_mounting, ) else: local_args = tuple(args) for name, value in self.compose.environment: line = line.replace('${%s}' % (name), value) logger.cmd('Run %s %s' % (line, " ".join(local_args))) cmd_args = tuple(line.split()) + local_args cmd = self.root.bash('docker-emperor', *cmd_args, compose=self.compose, is_system=True) if not cmd.is_success: break return True return False
def run(root, *args, **kwargs): name = args[0].strip() if args else None if name: if name in root.project['mounting']: root.project.config['mounting'] = name logger.success(u'Mounting <b>%s</b> selected.' % root.mounting.name) else: logger.error(u'Mounting <b>%s</b> unknow.' % name) exit(1) else: def select_mounting_name(): # logger.ask('0) no mounting (localhost)') logger.ask( u'Please select the <b>{}</b> mounting to work on'.format( root.project.name)) for i, m in enumerate(root.project['mounting']): logger.choice(u'<b>{}</b>] {}'.format(i + 1, m.name)) mi = six.moves.input(': ') try: if mi == '0': raise Exception return root.project['mounting'][int(mi) - 1].name except Exception as e: logger.error(u'<b>%s</b> is not a valid choice' % mi) return select_mounting_name() root.project.config['mounting'] = select_mounting_name() logger.success(u'Mounting <b>%s</b> selected.' % root.mounting.name)
def run(self, log=False): if not self.env: self.env = [] if not isinstance(self.env, list): raise Exception( "Env arguments are invalid: {} is not list types".format( self.env)) if isinstance(self.compose, Command.Compose): self.env += self.compose.mounting.docker_env self.cmd_line = " ".join(self.env + self.args) if '--verbose' in self.args: self.cmd_line = self.cmd_line.replace('--verbose', '') # logger.comment(self.cmd_line) # if kwargs.get('log', True): # logger.comment("Env.\n" + "\n".join(self.env)) if isinstance(self.compose, Command.Compose): for name, value in self.compose.environment: self.cmd_line = self.cmd_line.replace('${%s}' % (name), value) if self.is_system: self.out = os.system(self.cmd_line) # if self.out.startswith('ERROR:'): # self.error = self.out else: self.lines = [] self.process = subprocess.Popen(self.cmd_line, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) self.out = '' for line in iter(self.process.stdout.readline, ''): # replace '' with b'' for Python 3 self.out += line self.lines.append(line.strip()) self.last_line = line self.out = self.out.strip() stdout, stderr = self.process.communicate() self.error_code = self.process.returncode self.error = stderr.decode('utf-8').strip() if self.error: # self.error = self.error.replace('docker-machine ls', 'de ls') if not self.silently_fail: logger.error(self.error) exit(0) return self
def select_machine_name(): # logger.ask('0) no machine (localhost)') logger.ask(u'Please select the <b>{}</b> machine to work on'.format(root.project.name)) for i, m in enumerate(root.project['machines']): logger.choice(u'<b>{}</b>] {}'.format(i+1, m.name)) mi = six.moves.input(': ') try: if mi == '0': raise Exception return root.project['machines'][int(mi)-1].name except Exception as e: logger.error(u'<b>%s</b> is not a valid choice' % mi) return select_machine_name()
def select_project(): # logger.ask('0) no machine (localhost)') logger.ask('Select the project to work on') for i, p in enumerate(root.projects.items()): key, value = p logger.choice('<b>{}]</b> {}'.format(i + 1, key)) pi = six.moves.input(': ') try: if pi == '0': raise Exception return root.projects.items()[int(pi) - 1] except Exception as e: logger.error('{} is not a valid choice'.format(pi)) return select_project()
def select_context_name(contexts): logger.ask( u'Please select the <b>{}</b> context to work on'.format( root.project.name)) for i, c in enumerate(contexts): logger.choice(u'<b>%s</b>] %s' % (i + 1, c.name)) ci = six.moves.input(': ') try: if ci == '0': raise Exception return contexts[int(ci) - 1].name except Exception as e: logger.error(u'<b>%s/b> is not a valid choice' % ci) return select_context_name(contexts)
def run(root, *args, **kwargs): name = args[0].strip() if args else None if name: if name in root.project['contexts']: root.project.config['context'] = name logger.success(u'Context <b>%s</b> selected.' % root.context.name) else: logger.error(u'Context <b>%s</b> unknow.' % name) exit(0) else: contexts = root.project['contexts'] if not contexts: contexts['default'] = Context('default') root.project.config['context'] = 'default' logger.warning(u'No context defines, use <b>%s</b>.' % root.context.name) else: def select_context_name(contexts): logger.ask( u'Please select the <b>{}</b> context to work on'.format( root.project.name)) for i, c in enumerate(contexts): logger.choice(u'<b>%s</b>] %s' % (i + 1, c.name)) ci = six.moves.input(': ') try: if ci == '0': raise Exception return contexts[int(ci) - 1].name except Exception as e: logger.error(u'<b>%s/b> is not a valid choice' % ci) return select_context_name(contexts) root.project.config['context'] = select_context_name(contexts) logger.success(u'Context <b>%s</b> selected.' % root.context.name)