Ejemplo n.º 1
0
    def _display_out(self, method, out, format='xml'):
        """
        General display method. Searches for certain display method and calls it
        with `out` or prints out in table form or raw. Custom display methods
        should be named by next pattern '_display_<method_name>' where
        <method_name> is queryenv method name with hyphens replaced with
        underscores.
        """
        all_display_methods = [m for m in dir(self) if m.startswith('_display')]
        display_method = None
        if method:
            for m in all_display_methods:
                if method.replace('-', '_') in m:
                    display_method = getattr(self, m)
                    break

        if display_method:
            display_kwds = {}
            argspec = inspect.getargspec(display_method)
            argnames = argspec.args
            if 'format' in argnames:
                display_kwds['format'] = format
            display_method(out, **display_kwds)
        elif isinstance(out, list) and isinstance(out[0], list) and method != 'fetch':
            print make_table(out)
        else:
            print out
Ejemplo n.º 2
0
    def _display_out(self, method, out, format='xml'):
        """
        General display method. Searches for certain display method and calls it
        with `out` or prints out in table form or raw. Custom display methods
        should be named by next pattern '_display_<method_name>' where
        <method_name> is queryenv method name with hyphens replaced with
        underscores.
        """
        all_display_methods = [
            m for m in dir(self) if m.startswith('_display')
        ]
        display_method = None
        if method:
            for m in all_display_methods:
                if method.replace('-', '_') in m:
                    display_method = getattr(self, m)
                    break

        if display_method:
            display_kwds = {}
            argspec = inspect.getargspec(display_method)
            argnames = argspec.args
            if 'format' in argnames:
                display_kwds['format'] = format
            display_method(out, **display_kwds)
        elif isinstance(out, list) and isinstance(out[0],
                                                  list) and method != 'fetch':
            print make_table(out)
        else:
            print out
Ejemplo n.º 3
0
 def _display_list_ebs_mountpoints(self, out):
     headers = ['name', 'dir', 'createfs', 'isarray', 'volume-id', 'device']
     table_data = []
     for d in out:
         volume_params = [(v.volume_id, v.device) for v in d.volumes]
         volumes, devices = transpose(volume_params)
         table_data.append([d.name, d.dir, d.create_fs, d.is_array, volumes, devices])
     print make_table(table_data, headers)
Ejemplo n.º 4
0
 def _display_list_ebs_mountpoints(self, out):
     headers = ['name', 'dir', 'createfs', 'isarray', 'volume-id', 'device']
     table_data = []
     for d in out:
         volume_params = [(v.volume_id, v.device) for v in d.volumes]
         volumes, devices = transpose(volume_params)
         table_data.append(
             [d.name, d.dir, d.create_fs, d.is_array, volumes, devices])
     print make_table(table_data, headers)
Ejemplo n.º 5
0
 def _display_list_roles(self, out):
     headers = [
         'behaviour', 'name', 'farm-role-id', 'index', 'internal-ip',
         'external-ip', 'replication-master'
     ]
     table_data = []
     for d in out:
         behaviour = ', '.join(d.behaviour)
         for host in d.hosts:
             table_data.append([
                 behaviour, d.name, d.farm_role_id,
                 str(host.index), host.internal_ip, host.external_ip,
                 str(host.replication_master)
             ])
     print make_table(table_data, headers)
Ejemplo n.º 6
0
    def display(self, data):
        for row in data:
            row[3] = 'in' if row[3] else 'out'
            row[4] = 'yes' if row[4] else 'no'

        header_fields = ['id', 'name', 'date', 'direction', 'handled?']
        table = make_table(data, header_fields)
        print table
Ejemplo n.º 7
0
    def display(self, data):
        for row in data:
            row[3] = 'in' if row[3] else 'out'
            row[4] = 'yes' if row[4] else 'no'

        header_fields = ['id', 'name', 'date', 'direction', 'handled?']
        table = make_table(data, header_fields)
        print table
Ejemplo n.º 8
0
 def _display_list_roles(self, out):
     headers = ['behaviour',
        'name',
        'farm-role-id',
        'index',
        'internal-ip',
        'external-ip',
        'replication-master']
     table_data = []
     for d in out:
         behaviour = ', '.join(d.behaviour)
         for host in d.hosts:
             table_data.append([behaviour, 
                                d.name,
                                d.farm_role_id,
                                str(host.index),
                                host.internal_ip,
                                host.external_ip,
                                str(host.replication_master)])
     print make_table(table_data, headers)
Ejemplo n.º 9
0
 def _display_get_latest_version(self, out):
     print(make_table([[out]], ['version']))
Ejemplo n.º 10
0
 def _display_get_https_certificate(self, out):
     headers = ['cert', 'pkey', 'cacert']
     print(make_table(out, headers))
Ejemplo n.º 11
0
 def _display_list_global_variables(self, out):
     headers = ['key', 'value']
     table_data = list(out['public'].items())
     print(make_table(table_data, headers))
Ejemplo n.º 12
0
 def _display_list_virtual_hosts(self, out):
     headers = ['hostname', 'https', 'type', 'raw']
     table_data = [[d.hostname, d.https, d.type, d.raw] for d in out]
     print(make_table(table_data, headers))
Ejemplo n.º 13
0
 def _display_list_global_variables(self, out):
     headers = ['key', 'value']
     table_data = out['public'].items()
     print make_table(table_data, headers)
Ejemplo n.º 14
0
 def _display_list_virtual_hosts(self, out):
     headers = ['hostname', 'https', 'type', 'raw']
     table_data = [[d.hostname, d.https, d.type, d.raw] for d in out]
     print make_table(table_data, headers)
Ejemplo n.º 15
0
 def _display_get_latest_version(self, out):
     print make_table([[out]], ['version'])
Ejemplo n.º 16
0
 def _display_get_https_certificate(self, out):
     headers = ['cert', 'pkey', 'cacert']
     print make_table(out, headers)