Beispiel #1
0
 def _list_pools(self):
     resource_writer = ConsoleResourceWriter(GlobalIPManager.find_pools())
     resource_writer.print_table(fields=[
         'id', 'parent', 'self', 'status', 'used_addresses',
         'total_addresses', 'usage'
     ],
                                 sort_by='parent')
Beispiel #2
0
    def _handle_switch(self, *args, **options):
        device_id = options['switch-id']
        switch = Resource.objects.get(pk=device_id)

        query = dict(parent=switch)

        if options['port'] and len(options['port']) > 0:
            query['number__in'] = options['port']

        port_link_data = []
        for switch_port in SwitchPort.active.filter(**query).order_by('-name'):
            for port_connection in PortConnection.active.filter(parent=switch_port):
                linked_server_port = port_connection.linked_port

                if linked_server_port:
                    if isinstance(linked_server_port, ServerPort):
                        port_link_data.append([
                            switch_port.number,
                            port_connection.link_speed_mbit,
                            linked_server_port.parent.name,
                            linked_server_port.typed_parent.label,
                            port_connection.last_seen
                        ])
                else:
                    logger.warning("PortConnection %s linked to missing ServerPort %s" % (
                        port_connection, linked_server_port.id))
                    continue

        if port_link_data:
            writer = ConsoleResourceWriter(port_link_data)
            writer.print_table(fields=['port_number', 'link_speed_mbit', 'server_name', 'label', 'last_seen'],
                               sort_by='port_number')
        else:
            logger.info("not connected")
Beispiel #3
0
    def _handle_command_search(self, *args, **options):
        query = self._parse_reminder_arguments(options['filter'])

        if options['index']:
            updated = 0
            for resource in Resource.active.all():
                resource.name = unicode(resource)
                resource.save()

            logger.debug("Updated resources: %s" % updated)
            return

        # apply status
        if not options['status']:
            resource_set = Resource.active.filter(**query)
        else:
            query['status__in'] = options['status'].split(',')
            resource_set = Resource.objects.filter(**query)

        # order by
        table_sort_by_field = None
        if options['order']:
            fields = options['order'].split(',')
            for field_name in fields:
                if not ModelFieldChecker.is_model_field(Resource, field_name):
                    table_sort_by_field = field_name
                    break

            if not table_sort_by_field:
                resource_set = resource_set.order_by(*fields)

        # apply limits
        limit = options['limit']
        offset = (options['page'] - 1) * limit
        if limit > 0:
            resource_set = resource_set[offset:limit]

        # tabular output with column align
        show_fields = options['show_fields'].split(',')

        console_writer = ConsoleResourceWriter(resource_set)
        console_writer.print_table(show_fields, sort_by=table_sort_by_field)
Beispiel #4
0
    def _handle_command_search(self, *args, **options):
        query = self._parse_reminder_arguments(options['filter'])

        if options['index']:
            updated = 0
            for resource in Resource.active.all():
                resource.name = unicode(resource)
                resource.save()

            logger.debug("Updated resources: %s" % updated)
            return

        # apply status
        if not options['status']:
            resource_set = Resource.active.filter(**query)
        else:
            query['status__in'] = options['status'].split(',')
            resource_set = Resource.objects.filter(**query)

        # order by
        table_sort_by_field = None
        if options['order']:
            fields = options['order'].split(',')
            for field_name in fields:
                if not ModelFieldChecker.is_model_field(Resource, field_name):
                    table_sort_by_field = field_name
                    break

            if not table_sort_by_field:
                resource_set = resource_set.order_by(*fields)

        # apply limits
        limit = options['limit']
        offset = (options['page'] - 1) * limit
        if limit > 0:
            resource_set = resource_set[offset:limit]

        # tabular output with column align
        show_fields = options['show_fields'].split(',')

        console_writer = ConsoleResourceWriter(resource_set)
        console_writer.print_table(show_fields, sort_by=table_sort_by_field)
Beispiel #5
0
    def _handle_switch(self, *args, **options):
        device_id = options['switch-id']
        switch = Resource.objects.get(pk=device_id)

        query = dict(parent=switch)

        if options['port'] and len(options['port']) > 0:
            query['number__in'] = options['port']

        port_link_data = []
        for switch_port in SwitchPort.active.filter(**query).order_by('-name'):
            for port_connection in PortConnection.active.filter(
                    parent=switch_port):
                linked_server_port = port_connection.linked_port

                if linked_server_port:
                    if isinstance(linked_server_port, ServerPort):
                        port_link_data.append([
                            switch_port.number,
                            port_connection.link_speed_mbit,
                            linked_server_port.parent.name,
                            linked_server_port.typed_parent.label,
                            port_connection.last_seen
                        ])
                else:
                    logger.warning(
                        "PortConnection %s linked to missing ServerPort %s" %
                        (port_connection, linked_server_port.id))
                    continue

        if port_link_data:
            writer = ConsoleResourceWriter(port_link_data)
            writer.print_table(fields=[
                'port_number', 'link_speed_mbit', 'server_name', 'label',
                'last_seen'
            ],
                               sort_by='port_number')
        else:
            logger.info("not connected")
Beispiel #6
0
 def _list_pools(self):
     resource_writer = ConsoleResourceWriter(IPAddressPool.get_all_pools())
     resource_writer.print_table(fields=['id', 'parent', 'self', 'type', 'status', 'usage'], sort_by='parent')