Ejemplo n.º 1
0
 def summary(self, *argv, **kwarg):
     fmt = kwarg.pop('fmt', 'native')
     if fmt == 'native':
         return Report(self._summary(*argv, **kwarg))
     elif fmt == 'csv':
         return Report(self._csv(dump=self._summary(*argv, **kwarg)))
     else:
         raise ValueError('format not supported')
Ejemplo n.º 2
0
 def details(self, *argv, **kwarg):
     fmt = kwarg.pop(
         'format',
         kwarg.pop('fmt', self.ndb.config.get('show_format', 'native')))
     if fmt == 'native':
         return Report(self._details(*argv, **kwarg))
     elif fmt == 'json':
         kwarg['format'] = 'json'
         return Report(self._details(*argv, **kwarg), ellipsis=False)
     else:
         raise ValueError('format not supported')
Ejemplo n.º 3
0
 def summary(self, *argv, **kwarg):
     fmt = kwarg.pop(
         'format',
         kwarg.pop('fmt', self.ndb.config.get('show_format', 'native')))
     if fmt == 'native':
         return Report(self._native(dump=self._summary(*argv, **kwarg)))
     elif fmt == 'csv':
         return Report(self._csv(dump=self._summary(*argv, **kwarg)),
                       ellipsis=False)
     elif fmt == 'json':
         return Report(self._json(dump=self._summary(*argv, **kwarg)),
                       ellipsis=False)
     else:
         raise ValueError('format not supported')
    def l3_edges(self, fmt=None):
        '''
        Report l3 edges. For every address on every node look
        if it is used as a gateway on remote nodes. Such cases
        are reported as l3 edges.

        Issues: does not report routes (edges) via point to point
        connections like GRE where local addresses are used as
        gateways. To be fixed.
        '''
        header = ('source_node', 'gateway_node', 'gateway_address', 'dst',
                  'dst_len')
        return Report(
            self._formatter(
                self._schema.fetch('''
            SELECT DISTINCT
                r.f_target, a.f_target, a.f_IFA_ADDRESS,
                r.f_RTA_DST, r.f_dst_len
            FROM
                addresses AS a
            INNER JOIN
                routes AS r
            ON
                r.f_target != a.f_target
                AND r.f_RTA_GATEWAY = a.f_IFA_ADDRESS
                AND r.f_RTA_GATEWAY NOT IN
            (SELECT
                f_IFA_ADDRESS
             FROM
                addresses
             WHERE
                f_target = r.f_target)
        '''), fmt, header))
Ejemplo n.º 5
0
 def nodes(self, fmt=None):
     '''
     Report all the nodes within the cluster.
     '''
     return Report(self._formatter(self._schema.fetch('''
         SELECT DISTINCT f_target
         FROM interfaces
     '''), fmt, transform=lambda x: x[0]))
 def nodes(self, fmt=None):
     '''
     Report all the nodes within the cluster.
     '''
     header = ('nodename', )
     return Report(
         self._formatter(
             self._schema.fetch('''
         SELECT DISTINCT f_target
         FROM interfaces
     '''), fmt, header))
Ejemplo n.º 7
0
 def p2p_edges(self, fmt=None):
     '''
     Report point to point edges within the cluster, like
     GRE or PPP interfaces.
     '''
     header = ('left_node',
               'right_node')
     return Report(self._formatter(self._schema.fetch('''
         SELECT DISTINCT
             l.f_target, r.f_target
         FROM p2p AS l
         INNER JOIN p2p AS r
         ON
             l.f_p2p_local = r.f_p2p_remote
             AND l.f_target != r.f_target
     '''), fmt, header))
Ejemplo n.º 8
0
    def l2_edges(self, fmt=None):
        '''
        Report l2 links within the cluster, reconstructed
        from the ARP caches on the nodes. Works as follows:

        1. for every node take the ARP cache
        2. for every record in the cache reconstruct two triplets:

        * the interface index -> the local interface name
        * the neighbour lladdr -> the remote node and interface name

        Issues: does not filter out fake lladdr, so CARP interfaces
        produce fake l2 edges within the cluster.
        '''
        header = ('left_node',
                  'left_ifname',
                  'left_lladdr',
                  'right_node',
                  'right_ifname',
                  'right_lladdr')
        return Report(self._formatter(self._schema.fetch('''
        SELECT DISTINCT
            j.f_target, j.f_IFLA_IFNAME, j.f_IFLA_ADDRESS,
            d.f_target, d.f_IFLA_IFNAME, j.f_NDA_LLADDR
        FROM
            (SELECT
                n.f_target, i.f_IFLA_IFNAME,
                i.f_IFLA_ADDRESS, n.f_NDA_LLADDR
             FROM
                neighbours AS n
             INNER JOIN
                interfaces AS i
             ON
                n.f_target = i.f_target
                AND i.f_IFLA_ADDRESS != '00:00:00:00:00:00'
                AND n.f_ifindex = i.f_index) AS j
        INNER JOIN
            interfaces AS d
        ON
            j.f_NDA_LLADDR = d.f_IFLA_ADDRESS
            AND j.f_target != d.f_target
        '''), fmt, header))
Ejemplo n.º 9
0
 def summary(self, *argv, **kwarg):
     return Report(self._summary(*argv, **kwarg))
Ejemplo n.º 10
0
 def dump(self, *argv, **kwarg):
     return Report(self._dump(*argv, **kwarg))
Ejemplo n.º 11
0
 def csv(self, *argv, **kwarg):
     return Report(self._csv(*argv, **kwarg))
Ejemplo n.º 12
0
 def summary(self):
     iclass = self.classes[self.table]
     return Report(self._native(iclass.summary(self)))
Ejemplo n.º 13
0
 def dump(self):
     iclass = self.classes[self.table]
     return Report(self._native(iclass.dump(self)))