Exemplo n.º 1
0
  def subtree_query(self, root, query_parts):
    if query_parts:
      my_query = query_parts[0]
      if is_pattern(my_query):
        matches = [root[1][node] for node in match_entries(root[1], my_query)]
      elif my_query in root[1]:
        matches = [ root[1][my_query] ]
      else:
        matches = []

    else:
      matches = root[1].values()

    for child_node in matches:
      result = {
        'path' : child_node[0],
        'is_leaf' : bool(child_node[0]),
      }
      if result['path'] is not None and not result['is_leaf']:
        result['path'] += '.'
      yield result

      if query_parts:
        for result in self.subtree_query(child_node, query_parts[1:]):
          yield result
Exemplo n.º 2
0
    def subtree_query(self, root, query_parts):
        if query_parts:
            my_query = query_parts[0]
            if is_pattern(my_query):
                matches = [
                    root[1][node] for node in match_entries(root[1], my_query)
                ]
            elif my_query in root[1]:
                matches = [root[1][my_query]]
            else:
                matches = []

        else:
            matches = root[1].values()

        for child_node in matches:
            result = {
                'path': child_node[0],
                'is_leaf': bool(child_node[0]),
            }
            if result['path'] is not None and not result['is_leaf']:
                result['path'] += '.'
            yield result

            if query_parts:
                for result in self.subtree_query(child_node, query_parts[1:]):
                    yield result
Exemplo n.º 3
0
    def find(self, query, request):
        # XXX --- revisit this code
        query = remove_metachars(query)
        parts = query.split('.')
        if is_pattern(parts[-1]):
            path = '/'.join([p.replace('@', '.') for p in parts[:-1]])
            metric_path = '.'.join(parts[:-1])
            pattern = parts[-1]
        else:
            path = '/'.join([p.replace('@', '.') for p in parts])
            metric_path = '.'.join(parts)
            pattern = None


        if request and request.user and request.user.is_authenticated():
            client = self.auth_client
        else:
            client = self.client

        r = client.get(path)

        if type(r) == list:
            # XXX hack -- if we get multiple results use the most recent
            r = r[-1]

        if r.has_key('children'):
            for child in r['children']:
                if path != '':
                    cpath = metric_path + '.'
                else:
                    cpath = ''

                label = None
                if child.has_key('name'):
                    if path.endswith('interface') and \
                            (not child.has_key('descr')
                                    or child['descr'] == ''):
                        if not 'dev-alu' in path:
                            continue
                    name = child['name']
                    if child.has_key('descr'):
                        label = "%s %s" % (name, child['descr'])
                        label = label.replace('"','')
                else:
                    name = parts[-1]

                cpath += name.replace('.','@')
                # XXX KLUDGE! need to revist various path translation crap
                if 'error/' in cpath:
                    cpath = cpath.replace('error/', 'error.')
                if 'discard/' in cpath:
                    cpath = cpath.replace('discard/', 'discard.')

                if child['leaf']:
                    yield ESxSNMPLeaf(cpath, cpath, client=client,
                            name=name, label=label)
                else:
                    yield ESxSNMPBranch(cpath, cpath, name=name, label=label)
        else:
            yield ESxSNMPLeaf(path, path, client=client)
Exemplo n.º 4
0
    def find(self, query, request):
        # XXX --- revisit this code
        query = remove_metachars(query)
        parts = query.split('.')
        if is_pattern(parts[-1]):
            path = '/'.join([p.replace('@', '.') for p in parts[:-1]])
            metric_path = '.'.join(parts[:-1])
            pattern = parts[-1]
        else:
            path = '/'.join([p.replace('@', '.') for p in parts])
            metric_path = '.'.join(parts)
            pattern = None

        if request and request.user and request.user.is_authenticated():
            client = self.auth_client
        else:
            client = self.client

        r = client.get(path)

        if type(r) == list:
            # XXX hack -- if we get multiple results use the most recent
            r = r[-1]

        if r.has_key('children'):
            for child in r['children']:
                if path != '':
                    cpath = metric_path + '.'
                else:
                    cpath = ''

                label = None
                if child.has_key('name'):
                    if path.endswith('interface') and \
                            (not child.has_key('descr')
                                    or child['descr'] == ''):
                        if not 'dev-alu' in path:
                            continue
                    name = child['name']
                    if child.has_key('descr'):
                        label = "%s %s" % (name, child['descr'])
                        label = label.replace('"', '')
                else:
                    name = parts[-1]

                cpath += name.replace('.', '@')
                # XXX KLUDGE! need to revist various path translation crap
                if 'error/' in cpath:
                    cpath = cpath.replace('error/', 'error.')
                if 'discard/' in cpath:
                    cpath = cpath.replace('discard/', 'discard.')

                if child['leaf']:
                    yield ESxSNMPLeaf(cpath,
                                      cpath,
                                      client=client,
                                      name=name,
                                      label=label)
                else:
                    yield ESxSNMPBranch(cpath, cpath, name=name, label=label)
        else:
            yield ESxSNMPLeaf(path, path, client=client)
Exemplo n.º 5
0
 def _split(self, key):
   parts = key.split('.')
   for i in range (0, len(parts)):
     if is_pattern(parts[i]):
       parts[i] = self._variants(parts[i])
   return parts