class RedHatClusterNode(ClusterNode): """ Extends the generall ClusterNode class by adding special queries for this cluster type. """ clustat_pathroot=xpathjoin(RedHatClusterRepository.getDefaultClustatXPath(), RedHatClusterRepository.element_clustat_nodes, RedHatClusterRepository.element_clustat_node+'[@'+RedHatClusterRepository.attribute_clustat_node_name+'="%s"]') def __init__(self, element, doc=None): super(RedHatClusterNode, self).__init__(element, doc) from helper import RedHatClusterHelper, HelperNotSupportedError try: self.helper=RedHatClusterHelper() except HelperNotSupportedError: self.helper=None self.addNonStatic("state") self.addNonStatic("local") self.addNonStatic("estranged") self.addNonStatic("rgmanager") self.addNonStatic("rgmanager_master") self.addNonStatic("qdisk") def query(self, param, *params, **keys): if self.non_statics.get(param, None) != None and self.helper: return self.helper.queryStatusElement(query=xpathjoin(self.xpath_clustat, self.element_nodes, self.element_node+'['+self.attribute_node_name+'="'+self.getName()+'"]', self.non_statics.get(param))) elif self.helper: return self.helper.queryStatusElement(query=os.path.join(self.clustat_pathroot %self.getName(), "@"+param)) else: return None def getName(self): """ @return: nodename @rtype: string """ return self.getAttribute(RedHatClusterRepository.attribute_clusternode_name) def getId(self): """ @return: nodeid @rtype: int """ return self.getAttribute(RedHatClusterRepository.attribute_clusternode_nodeid, "") def getVotes(self): """ @return: votes for quorum @rtype: int """ return self.getAttribute(RedHatClusterRepository.attribute_clusternode_votes, "1") def isActive(self): """ @return: True if clusternode is active """ return self.state==None or self.state=='1'
def __init__(self, element, doc=None): super(RedHatClusterNode, self).__init__(element, doc) from helper import RedHatClusterHelper, HelperNotSupportedError try: self.helper=RedHatClusterHelper() except HelperNotSupportedError: self.helper=None self.addNonStatic("state") self.addNonStatic("local") self.addNonStatic("estranged") self.addNonStatic("rgmanager") self.addNonStatic("rgmanager_master") self.addNonStatic("qdisk")
def __init__(self, clusterRepository): """ Set used clusterRepository @param clusterRepository: clusterRepository to use @type clusterRepository: L{RedhatClusterRepository} """ super(RedHatClusterInfo, self).__init__(clusterRepository) from helper import RedHatClusterHelper, HelperNotSupportedError try: self.helper = RedHatClusterHelper() except HelperNotSupportedError: self.helper = None self.addNonStatic( "name", xpathjoin( RedHatClusterRepository.getDefaultClustatXPath(), RedHatClusterRepository.element_clustat_cluster, "@" + RedHatClusterRepository.attribute_clustat_cluster_name)) # self.addNonStatic(RedhatClusterInfo, "id") self.addNonStatic( "generation", xpathjoin( RedHatClusterRepository.getDefaultClustatXPath(), RedHatClusterRepository.element_clustat_cluster, "@" + RedHatClusterRepository.attribute_clustat_cluster_generation)) self.addNonStatic( "quorum_quorate", xpathjoin(RedHatClusterRepository.getDefaultClustatXPath(), RedHatClusterRepository.element_quorum, "@" + RedHatClusterRepository.attribute_quorum_quorate)) self.addNonStatic( "quorum_groupmember", xpathjoin( RedHatClusterRepository.getDefaultClustatXPath(), RedHatClusterRepository.element_quorum, "@" + RedHatClusterRepository.attribute_quorum_groupmember))
def __init__(self, clusterRepository): """ Set used clusterRepository @param clusterRepository: clusterRepository to use @type clusterRepository: L{RedhatClusterRepository} """ super(RedHatClusterInfo, self).__init__(clusterRepository) from helper import RedHatClusterHelper, HelperNotSupportedError try: self.helper=RedHatClusterHelper() except HelperNotSupportedError: self.helper=None self.addNonStatic("name", xpathjoin(RedHatClusterRepository.getDefaultClustatXPath(), RedHatClusterRepository.element_clustat_cluster, "@"+RedHatClusterRepository.attribute_clustat_cluster_name)) # self.addNonStatic(RedhatClusterInfo, "id") self.addNonStatic("generation", xpathjoin(RedHatClusterRepository.getDefaultClustatXPath(), RedHatClusterRepository.element_clustat_cluster, "@"+RedHatClusterRepository.attribute_clustat_cluster_generation)) self.addNonStatic("quorum_quorate", xpathjoin(RedHatClusterRepository.getDefaultClustatXPath(), RedHatClusterRepository.element_quorum, "@"+RedHatClusterRepository.attribute_quorum_quorate)) self.addNonStatic("quorum_groupmember", xpathjoin(RedHatClusterRepository.getDefaultClustatXPath(), RedHatClusterRepository.element_quorum, "@"+RedHatClusterRepository.attribute_quorum_groupmember))
class RedHatClusterInfo(ClusterInfo): """ Extends L{ClusterInfo} to provides a set of special queries to use with a L{RedhatClusterRepository} to get information about the used redhat clusterconfiguration. """ def __init__(self, clusterRepository): """ Set used clusterRepository @param clusterRepository: clusterRepository to use @type clusterRepository: L{RedhatClusterRepository} """ super(RedHatClusterInfo, self).__init__(clusterRepository) from helper import RedHatClusterHelper, HelperNotSupportedError try: self.helper = RedHatClusterHelper() except HelperNotSupportedError: self.helper = None self.addNonStatic( "name", xpathjoin( RedHatClusterRepository.getDefaultClustatXPath(), RedHatClusterRepository.element_clustat_cluster, "@" + RedHatClusterRepository.attribute_clustat_cluster_name)) # self.addNonStatic(RedhatClusterInfo, "id") self.addNonStatic( "generation", xpathjoin( RedHatClusterRepository.getDefaultClustatXPath(), RedHatClusterRepository.element_clustat_cluster, "@" + RedHatClusterRepository.attribute_clustat_cluster_generation)) self.addNonStatic( "quorum_quorate", xpathjoin(RedHatClusterRepository.getDefaultClustatXPath(), RedHatClusterRepository.element_quorum, "@" + RedHatClusterRepository.attribute_quorum_quorate)) self.addNonStatic( "quorum_groupmember", xpathjoin( RedHatClusterRepository.getDefaultClustatXPath(), RedHatClusterRepository.element_quorum, "@" + RedHatClusterRepository.attribute_quorum_groupmember)) def query(self, param, *params, **keys): if keys and keys.has_key("pathroot"): _pathroot = keys["pathroot"] elif params and len(params) >= 1: _pathroot = params[0] else: _pathroot = RedHatClusterRepository.getDefaultClustatXPath() result = "" if xpathsplit(_pathroot)[ 0] == RedHatClusterRepository.element_clustat and self.helper: if self.non_statics.get(param, None) != None: result = self.helper.queryStatusElement( query=xpathjoin(_pathroot, self.non_statics.get(param))) else: result = self.helper.queryStatusElement( query=xpathjoin(_pathroot, "@" + param)) else: result = self.queryValue(param) if isinstance(result, basestring): return result else: ":".join(result) def queryValue(self, query): """ Provides the possibility to get specific values by execute queries which are not yet implemented as a direct function. @param query: xpath to query clusterinfo instance @type query: string @return: answer of proceeded query as list of strings @rtype: list """ self.log.debug("queryValue: %s" % (query)) _tmp1 = evaluateXPath(query, self.clusterRepository.getElement()) _tmp2 = [] for i in range(len(_tmp1)): _tmp2.append(_tmp1[i]) return _tmp2 def queryXml(self, query): """ Provides the possibility to execute queries which are not yet implemented as a direct function to get a part of the xml. @param query: xpath to query clusterinfo instance @type query: string @return: answer of proceeded query as xml @rtype: list(xml.dom.Node) """ self.log.debug("queryXml: %s" % (query)) _tmp1 = evaluateXPath(query, self.clusterRepository.getElement()) return _tmp1 def getNode(self, name): """ @param name: name or id of clusternode @type name: string @return: Clusternodeinstance belonging to given clusternodename @rtype: L{ClusterNode} """ self.log.debug("get node with given name from clusterrepository: %s" % (name)) if self.clusterRepository.nodeNameMap.has_key(name): return self.clusterRepository.nodeNameMap[name] else: return self.getNodeFromId(name) def getNodeFromId(self, _id): """ @param name: _id of clusternode @type name: int @return: Clusternodeinstance belonging to given nodeid @rtype: L{ClusterNode} """ self.log.debug("get node with given id from clusterrepository: %s" % (str(_id))) return self.clusterRepository.nodeIdMap[str(_id)] def getNodeName(self, mac): """ @param mac: mac-address @type mac: string @return: Clusternodename belonging to given mac-address @rtype: string """ self.log.debug( "get name of node with given mac from clusterrepository: %s" % (str(mac))) return self.clusterRepository.getNodeName(mac) def getNodeNameById(self, _id): """ @param _id: nodeid @type id: int @return: Clusternodename belonging to given nodeid @rtype: string """ self.log.debug( "get name of node with given nodid from clusterrepository: %s" % (str(_id))) return self.clusterRepository.getNodeNameById(_id) def getNodeId(self, mac): """ @param mac: mac-address @type mac: string @return: Clusternodeid belonging to given mac-address @rtype: string """ self.log.debug( "get id of node with given mac from clusterrepository: %s" % (str(mac))) return self.clusterRepository.getNodeId(mac) def getFailoverdomainNodes(self, failoverdomain): """ @param failoverdomain: failoverdomain @type failoverdomain: string @return: Names of nodes which belong to the given failoverdomain @rtype: string """ #no defaultvalue specified because every dailoverdomain needs to have one or more failoverdomainnodes _xpath = xpathjoin( RedHatClusterRepository.getDefaultClusterFailoverDomain( failoverdomain), RedHatClusterRepository.element_failoverdomainnode, "@" + RedHatClusterRepository.attribute_failoverdomainnode_name) self.log.debug("get failoverdomainnodes from failoverdomain %s: %s" % (failoverdomain, _xpath)) _tmp1 = self.queryValue(_xpath) return _tmp1 def getFailoverdomainPrefNode(self, failoverdomain): """ @param failoverdomain: failoverdomain @type failoverdomain: string @return: Name of node which is prefered in failovercase of given failoverdomain @rtype: string """ #no defaultvalue specified because every dailoverdomain needs to have one or more failoverdomainnodes and priority is a needed attribute _tmp1 = self.getFailoverdomainNodes(failoverdomain) #search for lowest priority minprio = "0" for i in range(len(_tmp1)): _xpath = xpathjoin( RedHatClusterRepository.getDefaultClusterFailoverDomain( failoverdomain), RedHatClusterRepository.element_failoverdomainnode + "[@" + RedHatClusterRepository.attribute_failoverdomainnode_name + "=\"" + _tmp1[i] + "\"]", "@" + RedHatClusterRepository.attribute_failoverdomainnode_priority) self.log.debug( "query lowest priority of failoverdomainnodes belonging to %s : %s" % (failoverdomain, _xpath)) _tmp2 = self.queryValue(_xpath)[0] if (minprio == "0") or (_tmp2 < minprio): minprio = _tmp2 #get node with lowest priority try: _xpath = xpathjoin( RedHatClusterRepository.getDefaultClusterFailoverDomain( failoverdomain), RedHatClusterRepository.element_failoverdomainnode + "[@" + RedHatClusterRepository.attribute_failoverdomainnode_priority + "=\"" + str(minprio) + "\"]", "@" + RedHatClusterRepository.attribute_failoverdomainnode_name) self.log.debug( "get failoverprefdomainnode from failoverdomain %s: %s" % (failoverdomain, _xpath)) return self.queryValue(_xpath)[0] except IndexError: raise NameError( "Cannot find prefered failoverdomainnode for domain %s." % failoverdomain) def getNodeIds(self): """ @return: List of clusternodeids @rtype: list """ self.log.debug("get list of nodeids from clusterrepository") return self.clusterRepository.nodeIdMap.keys() def getNextNodeID(self): """ @return: next not used nodeid @rtype: int """ idlist = self.getNodeIds() idlist.sort() return int(idlist[-1]) + 1
class RedHatClusterInfo(ClusterInfo): """ Extends L{ClusterInfo} to provides a set of special queries to use with a L{RedhatClusterRepository} to get information about the used redhat clusterconfiguration. """ def __init__(self, clusterRepository): """ Set used clusterRepository @param clusterRepository: clusterRepository to use @type clusterRepository: L{RedhatClusterRepository} """ super(RedHatClusterInfo, self).__init__(clusterRepository) from helper import RedHatClusterHelper, HelperNotSupportedError try: self.helper=RedHatClusterHelper() except HelperNotSupportedError: self.helper=None self.addNonStatic("name", xpathjoin(RedHatClusterRepository.getDefaultClustatXPath(), RedHatClusterRepository.element_clustat_cluster, "@"+RedHatClusterRepository.attribute_clustat_cluster_name)) # self.addNonStatic(RedhatClusterInfo, "id") self.addNonStatic("generation", xpathjoin(RedHatClusterRepository.getDefaultClustatXPath(), RedHatClusterRepository.element_clustat_cluster, "@"+RedHatClusterRepository.attribute_clustat_cluster_generation)) self.addNonStatic("quorum_quorate", xpathjoin(RedHatClusterRepository.getDefaultClustatXPath(), RedHatClusterRepository.element_quorum, "@"+RedHatClusterRepository.attribute_quorum_quorate)) self.addNonStatic("quorum_groupmember", xpathjoin(RedHatClusterRepository.getDefaultClustatXPath(), RedHatClusterRepository.element_quorum, "@"+RedHatClusterRepository.attribute_quorum_groupmember)) def query(self, param, *params, **keys): if keys and keys.has_key("pathroot"): _pathroot=keys["pathroot"] elif params and len(params)>=1: _pathroot=params[0] else: _pathroot=RedHatClusterRepository.getDefaultClustatXPath() result="" if xpathsplit(_pathroot)[0] == RedHatClusterRepository.element_clustat and self.helper: if self.non_statics.get(param, None) != None: result=self.helper.queryStatusElement(query= xpathjoin(_pathroot, self.non_statics.get(param))) else: result=self.helper.queryStatusElement(query= xpathjoin(_pathroot, "@"+param)) else: result=self.queryValue(param) if isinstance(result, basestring): return result else: ":".join(result) def queryValue(self, query): """ Provides the possibility to get specific values by execute queries which are not yet implemented as a direct function. @param query: xpath to query clusterinfo instance @type query: string @return: answer of proceeded query as list of strings @rtype: list """ self.log.debug("queryValue: %s" %(query)) _tmp1 = evaluateXPath(query, self.clusterRepository.getElement()) _tmp2 = [] for i in range(len(_tmp1)): _tmp2.append(_tmp1[i]) return _tmp2 def queryXml(self, query): """ Provides the possibility to execute queries which are not yet implemented as a direct function to get a part of the xml. @param query: xpath to query clusterinfo instance @type query: string @return: answer of proceeded query as xml @rtype: list(xml.dom.Node) """ self.log.debug("queryXml: %s" %(query)) _tmp1 = evaluateXPath(query, self.clusterRepository.getElement()) return _tmp1 def getNode(self, name): """ @param name: name or id of clusternode @type name: string @return: Clusternodeinstance belonging to given clusternodename @rtype: L{ClusterNode} """ self.log.debug("get node with given name from clusterrepository: %s" %(name)) if self.clusterRepository.nodeNameMap.has_key(name): return self.clusterRepository.nodeNameMap[name] else: return self.getNodeFromId(name) def getNodeFromId(self, _id): """ @param name: _id of clusternode @type name: int @return: Clusternodeinstance belonging to given nodeid @rtype: L{ClusterNode} """ self.log.debug("get node with given id from clusterrepository: %s" %(str(_id))) return self.clusterRepository.nodeIdMap[str(_id)] def getNodeName(self, mac): """ @param mac: mac-address @type mac: string @return: Clusternodename belonging to given mac-address @rtype: string """ self.log.debug("get name of node with given mac from clusterrepository: %s" %(str(mac))) return self.clusterRepository.getNodeName(mac) def getNodeNameById(self, _id): """ @param _id: nodeid @type id: int @return: Clusternodename belonging to given nodeid @rtype: string """ self.log.debug("get name of node with given nodid from clusterrepository: %s" %(str(_id))) return self.clusterRepository.getNodeNameById(_id) def getNodeId(self, mac): """ @param mac: mac-address @type mac: string @return: Clusternodeid belonging to given mac-address @rtype: string """ self.log.debug("get id of node with given mac from clusterrepository: %s" %(str(mac))) return self.clusterRepository.getNodeId(mac) def getFailoverdomainNodes(self, failoverdomain): """ @param failoverdomain: failoverdomain @type failoverdomain: string @return: Names of nodes which belong to the given failoverdomain @rtype: string """ #no defaultvalue specified because every dailoverdomain needs to have one or more failoverdomainnodes _xpath=xpathjoin(RedHatClusterRepository.getDefaultClusterFailoverDomain(failoverdomain), RedHatClusterRepository.element_failoverdomainnode, "@"+RedHatClusterRepository.attribute_failoverdomainnode_name) self.log.debug("get failoverdomainnodes from failoverdomain %s: %s" %(failoverdomain,_xpath)) _tmp1 = self.queryValue(_xpath) return _tmp1 def getFailoverdomainPrefNode(self, failoverdomain): """ @param failoverdomain: failoverdomain @type failoverdomain: string @return: Name of node which is prefered in failovercase of given failoverdomain @rtype: string """ #no defaultvalue specified because every dailoverdomain needs to have one or more failoverdomainnodes and priority is a needed attribute _tmp1 = self.getFailoverdomainNodes(failoverdomain) #search for lowest priority minprio = "0" for i in range(len(_tmp1)): _xpath=xpathjoin(RedHatClusterRepository.getDefaultClusterFailoverDomain(failoverdomain), RedHatClusterRepository.element_failoverdomainnode+"[@"+RedHatClusterRepository.attribute_failoverdomainnode_name+"=\""+_tmp1[i]+"\"]", "@"+RedHatClusterRepository.attribute_failoverdomainnode_priority) self.log.debug("query lowest priority of failoverdomainnodes belonging to %s : %s" %(failoverdomain,_xpath)) _tmp2 = self.queryValue(_xpath)[0] if (minprio == "0") or (_tmp2 < minprio): minprio = _tmp2 #get node with lowest priority try: _xpath=xpathjoin(RedHatClusterRepository.getDefaultClusterFailoverDomain(failoverdomain), RedHatClusterRepository.element_failoverdomainnode+"[@"+RedHatClusterRepository.attribute_failoverdomainnode_priority+"=\""+str(minprio)+"\"]", "@"+RedHatClusterRepository.attribute_failoverdomainnode_name) self.log.debug("get failoverprefdomainnode from failoverdomain %s: %s" %(failoverdomain, _xpath)) return self.queryValue(_xpath)[0] except IndexError: raise NameError("Cannot find prefered failoverdomainnode for domain %s." %failoverdomain) def getNodeIds(self): """ @return: List of clusternodeids @rtype: list """ self.log.debug("get list of nodeids from clusterrepository") return self.clusterRepository.nodeIdMap.keys() def getNextNodeID(self): """ @return: next not used nodeid @rtype: int """ idlist = self.getNodeIds() idlist.sort() return int(idlist[-1])+1