def add_repository(self, module_slug, repo_slug, login=None, passwd=None): """ add repository of a module """ repositories = self.modules[module_slug].repositories for repository in repositories: if repository.slug == repo_slug: if repository.clean: p = ProcessManager().launch("repository", _("Removing medias", "agent"), remove_medias_cmd()) p.join() logger.info("Add repository: %s" % repository.name) ProcessManager().add_repository(repository.get_command(login, passwd))
def add_repository(self, module_slug, repo_slug, login=None, passwd=None): """ add repository of a module """ repositories = self.modules[module_slug].repositories for repository in repositories: if repository.slug == repo_slug: if repository.clean: p = ProcessManager().launch("repository", _("Removing medias", "agent"), remove_medias_cmd()) p.join() logger.info("Add repository: %s" % repository.name) ProcessManager().add_repository( repository.get_command(login, passwd))
def get_status(self): """ return current agent status """ status = [] statuses = ProcessManager().pm_state() for sts in statuses: status.append(_(sts, "agent")) return ', '.join(status)
def get_state(self, type, module="agent"): """ return execution output """ code, output = ProcessManager().p_state(type, module) # format output tmp = output.splitlines() if not tmp: output = [{'code': 0, 'text': u''}] else: output = [] for line in tmp: try: if int(line[0]) in range(9): text_code = line[0] text = line[1:] else: text_code = 0 text = line output.append({'code': text_code, 'text': self.clean_output(text)}) # no code at line start except ValueError: text_code = 0 text = line output.append({'code': text_code, 'text': self.clean_output(text)}) # no char in line except IndexError: pass logger.debug("Get state: %s - %s" % (code, output)) return (code, output)
def run_config(self, module): """ run configuration for module """ logger.debug("Run configuration for %s" % str(module)) path, script, args = self.modules[module].info_config() logger.debug("Run script: %s, args: %s" % (str(script), str(args))) logger.debug("Path is: %s" % path) return ProcessManager().run_script(script, args, path, module, self.end_config)
def add_repository(self, module_slug, repo_slug, login=None, passwd=None): """ add repository of a module """ repositories = self.modules[module_slug].repositories for repository in repositories: if repository.slug == repo_slug: logger.info("Add repository: %s" % repository.name) ProcessManager().add_repository(repository.get_command(login, passwd))
def download(self): """ Download module if not present on disk """ if not self.downloaded: assert self._desc['module']['file'] logger.info("Download module: %s" % self.slug) if ModuleManager()._token: headers = [('Authorization', 'Token ' + ModuleManager()._token)] url = self._desc['module']['file'] ProcessManager().download_module(url, headers=headers, callback=self.end_download)
def install_modules(self, modules): """ install modules packages """ logger.info("Install modules: %s" % str(modules)) packages = [] for module in modules: packages += self.modules[module].packages if packages: logger.debug("Install packages: %s" % str(packages)) ProcessManager().install_packages(packages) return True else: logger.info("No packages to install") return False
def reboot(self): ProcessManager().reboot()
def update_medias(self): ProcessManager().update_medias()
def check_net(self): ProcessManager().check_net()
def load_packages(self): logger.info("Load packages...") ProcessManager().load_packages(self.set_packages)
def unmount_medias(self): ProcessManager().unmount_medias()