def startElement(self, tag, attrs): ''' This methods creates an element based on XML tags and inserts it into the data store. ''' ds = DataStore() # Create a new node based on the XML attributes. e = Element(tag, attrs) # If this is the head tag for the XML dump, initialize the data store if 'GANGLIA_XML' == tag: ds.acquireLock(self) self._elemStack.append(ds.getNode( )) # Fetch the root node. It has already been set into the tree. self._elemStackLen += 1 cfg = getConfig() # We'll go ahead and update any existing GRID tag with a new one (new time) even if one already exists. e = Element( 'GRID', { 'NAME': cfg[GmetadConfig.GRIDNAME], 'AUTHORITY': cfg[GmetadConfig.AUTHORITY], 'LOCALTIME': '%d' % time.time() }) self._ancestry.append('GANGLIA_XML') # Insert the new node into the data store at the appropriate location self._elemStack.append( ds.setNode(e, self._elemStack[self._elemStackLen - 1])) # If this is a cluster or nested grid node, then keep track of the data store path to this node. if (len(self._ancestry) < 2 or (len(self._ancestry) == 2 and e.id in ['GRID', 'CLUSTER'])): self._ancestry.append('%s:%s' % (e.id, e.getAttr('name'))) self._elemStackLen += 1
def startElement(self, tag, attrs): ''' This methods creates an element based on XML tags and inserts it into the data store. ''' ds = DataStore() # Create a new node based on the XML attributes. e = Element(tag, attrs) # If this is the head tag for the XML dump, initialize the data store if 'GANGLIA_XML' == tag: ds.acquireLock(self) self._elemStack.append(ds.getNode()) # Fetch the root node. It has already been set into the tree. self._elemStackLen += 1 cfg = getConfig() # We'll go ahead and update any existing GRID tag with a new one (new time) even if one already exists. e = Element('GRID', {'NAME':cfg[GmetadConfig.GRIDNAME], 'AUTHORITY':cfg[GmetadConfig.AUTHORITY], 'LOCALTIME':'%d' % time.time()}) self._ancestry.append('GANGLIA_XML') # Insert the cpu_usage when cpu_idle is exsists if 'METRIC' == tag and 'cpu_idle' == e.attrs['name']: self.insert_cpu_usage_metric(e, ds) # Insert the mem_usage when mem_free and mem_total are exsists(mem_usage is exsist in vmware instances) temp_metric = self._elemStack[self._elemStackLen-1] if isinstance(temp_metric.children, dict) and not temp_metric.children.has_key('METRIC:mem_usage') and temp_metric.children.has_key('METRIC:mem_free') and temp_metric.children.has_key('METRIC:mem_total'): self.insert_mem_usage_metric(temp_metric, ds) # Insert the new node into the data store at the appropriate location self._elemStack.append(ds.setNode(e, self._elemStack[self._elemStackLen-1])) # If this is a cluster or nested grid node, then keep track of the data store path to this node. if (len(self._ancestry) < 2 or (len(self._ancestry) == 2 and e.id in ['GRID', 'CLUSTER'])): self._ancestry.append('%s:%s'%(e.id,e.getAttr('name'))) self._elemStackLen += 1
def getXml(self, filter=None, queryargs=None): """ This method generates the output XML for either the entire data store or specified portions based on the filter and query args.""" if filter is None: filterList = None elif not len(filter.strip()): filterList = None else: filterList = filter.split("/") rbuf = "%s\n%s\n" % (self._xml_starttag, self._xml_dtd) ds = DataStore() if ds.rootElement is not None: ds.acquireLock(self) rbuf += self._getXmlImpl(ds.rootElement, filterList, queryargs) ds.releaseLock(self) return rbuf
def getXml(self, filter=None, queryargs=None): ''' This method generates the output XML for either the entire data store or specified portions based on the filter and query args.''' if filter is None: filterList = None elif not len(filter.strip()): filterList = None else: filterList = filter.split('/') rbuf = '%s\n%s\n' % (self._xml_starttag, self._xml_dtd) ds = DataStore() if ds.rootElement is not None: ds.acquireLock(self) rbuf += self._getXmlImpl(ds.rootElement, filterList, queryargs) ds.releaseLock(self) return rbuf
def startElement(self, tag, attrs): ''' This methods creates an element based on XML tags and inserts it into the data store. ''' ds = DataStore() # Create a new node based on the XML attributes. e = Element(tag, attrs) # If this is the head tag for the XML dump, initialize the data store if 'GANGLIA_XML' == tag: ds.acquireLock(self) self._elemStack.append(ds.getNode()) # Fetch the root node. It has already been set into the tree. self._elemStackLen += 1 cfg = getConfig() # We'll go ahead and update any existing GRID tag with a new one (new time) even if one already exists. e = Element('GRID', {'NAME':cfg[GmetadConfig.GRIDNAME], 'AUTHORITY':cfg[GmetadConfig.AUTHORITY], 'LOCALTIME':'%d' % time.time()}) self._ancestry.append('GANGLIA_XML') # Insert the new node into the data store at the appropriate location self._elemStack.append(ds.setNode(e, self._elemStack[self._elemStackLen-1])) # If this is a cluster node, then keep track of the data store path to this node. if (self._ancestry[len(self._ancestry)-1].startswith('CLUSTER') == False): self._ancestry.append('%s:%s'%(e.id,e.getAttr('name'))) self._elemStackLen += 1