Пример #1
0
    def loadNodes(self, webdis=False, pprint=False):
        """
        load nodes from config files
        """

        webdis = self.getWebDis(webdis)

        for configpath in j.system.fs.listFilesInDir("%s/apps/admin/cfg" %
                                                     j.dirs.baseDir,
                                                     filter="*.cfg"):

            gridname = j.system.fs.getBaseName(configpath).lower().strip()
            if gridname == "active.cfg":
                continue
            gridname = gridname[:-4]

            if webdis <> None:
                key = "%s:admin:nodes:%s" % (
                    j.application.config.get("grid_watchdog_secret"), gridname)
                webdis.delete(key)

            nodes = list()
            config = j.config.getConfig(configpath[:-4])

            self.gridNameAliases[gridname.lower()] = []
            if config.has_key("main"):
                for alias in config["main"].get("alias", "").split(","):
                    if alias.lower() not in self.gridNameAliases[
                            gridname.lower()]:
                        self.gridNameAliases[gridname.lower()].append(
                            alias.lower())

            for name, host in config.iteritems():
                node = JNode()
                node.gridname = gridname
                node.name = name
                node.remark = host.get('remark')
                node.ip = host.get('ip')
                node.host = host.get('host')
                node.roles = host.get('roles', '').split(',')
                node.enabled = False if host.get('enabled',
                                                 '1') == '1' else True
                self.setNode(node)
                nodes.append(node)
                if webdis <> None:
                    webdis.hset(key, node.name, json.dumps(node.__dict__))

            if pprint:
                line = "Grid %s" % gridname
                print line
                print "=" * len(line)
                print ""
                for node in sorted(nodes, key=lambda x: x.name):
                    print node
                print ''
Пример #2
0
    def loadNodes(self,webdis=False,pprint =False):
        """
        load nodes from config files
        """

        webdis=self.getWebDis(webdis)

        for configpath in j.system.fs.listFilesInDir("%s/apps/admin/cfg"%j.dirs.baseDir,filter="*.cfg"):

            gridname=j.system.fs.getBaseName(configpath).lower().strip()
            if gridname =="active.cfg":
                continue
            gridname=gridname[:-4]
            
            if webdis<>None:  
                key="%s:admin:nodes:%s"%(j.application.config.get("grid_watchdog_secret"),gridname)
                webdis.delete(key)

            nodes = list()
            config = j.config.getConfig(configpath[:-4])

            self.gridNameAliases[gridname.lower()]=[]
            if config.has_key("main"):
                for alias in config["main"].get("alias","").split(","):
                    if alias.lower() not in self.gridNameAliases[gridname.lower()]:
                        self.gridNameAliases[gridname.lower()].append(alias.lower())

            for name, host in config.iteritems():
                node=JNode()
                node.gridname=gridname
                node.name = name
                node.remark = host.get('remark')
                node.ip = host.get('ip')
                node.host = host.get('host')
                node.roles = host.get('roles', '').split(',')
                node.enabled = False if host.get('enabled', '1')  == '1' else True
                self.setNode(node)
                nodes.append(node)
                if webdis<>None:
                    webdis.hset(key,node.name,json.dumps(node.__dict__))

            if pprint:
                line = "Grid %s" % gridname
                print line
                print "=" * len(line)
                print ""
                for node in sorted(nodes, key=lambda x: x.name):
                    print node
                print ''
Пример #3
0
    def config2gridmaster(self):
        webdis = self.getWebDis()
        if webdis == None:
            raise RuntimeError(
                "cannot connect to webdis, is gridmaster running webdis?")
        self.loadNodes(webdis=True, pprint=False)
        sys.path.append(self._getPath("jumpscripts"))
        cmds = j.system.fs.listFilesInDir(self._getPath("jumpscripts"),
                                          recursive=True,
                                          filter="*.py")
        cmds.sort()

        def getcode(path):
            state = "start"
            code = ""
            for line in j.system.fs.fileGetContents(path).split("\n"):
                if line.find("def action(") <> -1:
                    state = "found"
                if state == "found":
                    code += "%s\n" % line
            return code

        key = "%s:admin:jscripts" % (
            j.application.config.get("grid_watchdog_secret"))
        webdis.delete(key)

        for item in cmds:
            name = j.system.fs.getBaseName(item).replace(".py", "")
            if name[0] <> "_":
                obj = {}
                name = name.lower()
                # print "load:%s"%name
                module = imp.load_source('jscript_%s' % name, item)
                obj["descr"] = getattr(module, "descr", "")
                obj["version"] = getattr(module, "version", "")
                obj["organization"] = getattr(module, "organization",
                                              "unknown")
                obj["version"] = getattr(module, "version", "1.0")
                obj["code"] = getcode(item)

                webdis.hset(key, name, json.dumps(obj))
Пример #4
0
    def config2gridmaster(self):
        webdis=self.getWebDis()
        if webdis==None:
            raise RuntimeError("cannot connect to webdis, is gridmaster running webdis?")
        self.loadNodes(webdis=True,pprint=False)
        sys.path.append(self._getPath("jumpscripts"))        
        cmds=j.system.fs.listFilesInDir(self._getPath("jumpscripts"), recursive=True, filter="*.py")
        cmds.sort()

        def getcode(path):
            state="start"
            code=""
            for line in j.system.fs.fileGetContents(path).split("\n"):
                if line.find("def action(")<>-1:
                    state="found"
                if state=="found":
                    code+="%s\n"%line
            return code

        key="%s:admin:jscripts"%(j.application.config.get("grid_watchdog_secret"))
        webdis.delete(key)

        for item in cmds:
            name=j.system.fs.getBaseName(item).replace(".py","")
            if name[0]<>"_":
                obj={}
                name=name.lower()
                # print "load:%s"%name
                module=imp.load_source('jscript_%s' % name, item)
                obj["descr"]= getattr(module, "descr","")
                obj["version"]= getattr(module, "version","")
                obj["organization"]= getattr(module, "organization","unknown")
                obj["version"]= getattr(module, "version","1.0")
                obj["code"]=getcode(item)
                
                webdis.hset(key,name,json.dumps(obj))