Beispiel #1
0
 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))
Beispiel #2
0
 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))
Beispiel #3
0
 def get_status(self):
     """ return current agent status """
     status = []
     statuses = ProcessManager().pm_state()
     for sts in statuses:
         status.append(_(sts, "agent"))
     return ', '.join(status)
Beispiel #4
0
    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)
Beispiel #5
0
 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)
Beispiel #6
0
 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))
Beispiel #7
0
 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)
Beispiel #8
0
 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
Beispiel #9
0
 def reboot(self):
     ProcessManager().reboot()
Beispiel #10
0
 def update_medias(self):
     ProcessManager().update_medias()
Beispiel #11
0
 def check_net(self):
     ProcessManager().check_net()
Beispiel #12
0
 def load_packages(self):
     logger.info("Load packages...")
     ProcessManager().load_packages(self.set_packages)
Beispiel #13
0
 def unmount_medias(self):
     ProcessManager().unmount_medias()