def envLoadCurrent(self): cmds = CommandList(["subenv current"]) return self.readLink() \ .bind(Link.runCommand, cmds.logicAnd(), stream=False, sudo=False, capture=True) \ .map(self.__cacheCurrentEnv) \ .catch(lambda err: Fail(EnvNotDefinedError("No current subenv is set. Check 'switch' for detais."))) \ .then(lambda: self)
def envStatus(self, full=False): if full: cmds = CommandList([self.orchestrate('status')]) return self.readLink() \ .bind(Link.runCommand, cmds.logicAnd(), stream=False, sudo=False, capture=True) \ .map(self.__envStatus) else: return OK(self.__envStatus())
def envRun(self, task, args): cmd = CommandList(self.orchestrate('run', task, args)) return self.readLink().bind(Link.runCommand, cmd=cmd.logicAnd(), interactive=True, stream=True, shell=False, capture=False)
def envExec(self, container, cmd, cwd=None, user=None): cmd = CommandList(self.orchestrate('exec', container, cmd, cwd, user)) return self.readLink().bind(Link.runCommand, cmd=cmd.logicAnd(), interactive=True, stream=True, shell=False, capture=False)
def envListLogs(self, parts=[], pattern=None): if not pattern: pattern = "%s*.log" % ('-'.join(parts)) cmds = CommandList() cmd = "ls -1 \"logs/%s\" | xargs -n1 basename" % pattern cmds.append('subenv run %s' % cmd) return self.readLink() \ .bind(Link.runCommand, cmds.logicAnd(), stream=True, capture=False, sudo=False)
def envLogs(self, parts=[], pattern=None, follow=True, lines=None): if not pattern: pattern = "%s*.log" % ('-'.join(parts)) cmds = CommandList() cmd = "tail" if follow: cmd += " -f" if lines: cmd += " -n %s" % int(lines) cmd += " \"logs/%s\"" % pattern cmds.append('subenv run %s' % cmd) return self.readLink() \ .bind(Link.runCommand, cmds.logicAnd(), stream=True, capture=False, sudo=False)
def exec(self, container, cmd, cwd=None, user=None): opts = [] cmdline = ' '.join(cmd) initCommands = CommandList(['export TERM=xterm', cmdline]) if user: opts.append('--user %s' % user) if cwd: initCommands.insert(0, 'cd %s' % cwd) tpl = { 'opts': ' '.join(opts), 'container': container, 'initCommands': initCommands.logicAnd() } return [ "dockwrkr exec -t -i %(opts)s %(container)s '/bin/sh -c \"%(initCommands)s\"'" % tpl ]
def envStart(self, reset=False, containers=[]): cmds = CommandList() if reset: cmds.append(self.getOrchestratorCommand('resetAll')) if len(containers) > 0: self.logAdapter.info("Starting %s container(s)" % (' '.join(containers))) cmds.append(self.orchestrate('start', containers)) else: self.logAdapter.info("Starting all containers...") cmds.append(self.orchestrate('startAll')) return self.readLink() \ .bind(Link.runCommand, cmds.logicAnd(), stream=True, sudo=False)
def envRecreate(self, time=10, containers=[]): cmds = CommandList() if len(containers) > 0: self.logAdapter.info("Recreating %s containers" % (' '.join(containers))) cmds.append(self.orchestrate('recreate', containers, time)) else: self.logAdapter.info("Recreating all containers...") cmds.append(self.orchestrate('recreateAll', time)) return self.readLink() \ .bind(Link.runCommand, cmds.logicAnd(), stream=True, sudo=False)
def envSwitch(self, subenvName, restart=False): self.logAdapter.info("Switch engine '%s' to subenv '%s'" % (self.name, subenvName)) self.currentEnv = subenvName self.loadSubenvConfigFile() cmds = CommandList([ "subenv init '/substance/devroot/%s'" % (subenvName), "subenv use '%s'" % (subenvName), ]) if restart: cmds.append(self.orchestrate('resetAll')) cmds.append(self.orchestrate('login')) cmds.append(self.orchestrate('startAll')) return self.readLink() \ .bind(Link.runCommand, cmds.logicAnd(), stream=True, sudo=False) \ .then(self.envRegister)
def envCleanup(self): cmds = CommandList() cmds.append('docker system prune -a') return self.readLink() \ .bind(Link.runCommand, cmds.logicAnd(), interactive=True, stream=True, shell=False, capture=False)