def test_simple_filter_attr_value(self):
        output = api_utils.simple_filter(copy.deepcopy(self.input_list), attr="status", value="")
        self.assertEqual([], output)

        output = api_utils.simple_filter(copy.deepcopy(self.input_list), attr="status", value="UP")
        self.assertEqual([api_fakes.RESP_ITEM_1, api_fakes.RESP_ITEM_3], output)

        output = api_utils.simple_filter(copy.deepcopy(self.input_list), attr="fred", value="UP")
        self.assertEqual([], output)
    def test_simple_filter_prop_attr_only(self):
        output = api_utils.simple_filter(
            copy.deepcopy(self.input_list),
            attr='b',
            property_field='props',
        )
        self.assertEqual(self.input_list, output)

        output = api_utils.simple_filter(
            copy.deepcopy(self.input_list),
            attr='status',
            property_field='props',
        )
        self.assertEqual(self.input_list, output)
    def test_simple_filter_prop_attr_only(self):
        output = api_utils.simple_filter(
            copy.deepcopy(self.input_list),
            attr='b',
            property_field='props',
        )
        self.assertEqual(self.input_list, output)

        output = api_utils.simple_filter(
            copy.deepcopy(self.input_list),
            attr='status',
            property_field='props',
        )
        self.assertEqual(self.input_list, output)
    def test_simple_filter_prop_attr_value(self):
        output = api_utils.simple_filter(
            copy.deepcopy(self.input_list),
            attr='b',
            value=2,
            property_field='props',
        )
        self.assertEqual(
            [api_fakes.RESP_ITEM_1, api_fakes.RESP_ITEM_2],
            output,
        )

        output = api_utils.simple_filter(
            copy.deepcopy(self.input_list),
            attr='b',
            value=9,
            property_field='props',
        )
        self.assertEqual([], output)
    def test_simple_filter_prop_attr_value(self):
        output = api_utils.simple_filter(
            copy.deepcopy(self.input_list),
            attr='b',
            value=2,
            property_field='props',
        )
        self.assertEqual(
            [api_fakes.RESP_ITEM_1, api_fakes.RESP_ITEM_2],
            output,
        )

        output = api_utils.simple_filter(
            copy.deepcopy(self.input_list),
            attr='b',
            value=9,
            property_field='props',
        )
        self.assertEqual([], output)
    def test_simple_filter_attr_value(self):
        output = api_utils.simple_filter(
            copy.deepcopy(self.input_list),
            attr='status',
            value='',
        )
        self.assertEqual([], output)

        output = api_utils.simple_filter(
            copy.deepcopy(self.input_list),
            attr='status',
            value='UP',
        )
        self.assertEqual(
            [api_fakes.RESP_ITEM_1, api_fakes.RESP_ITEM_3],
            output,
        )

        output = api_utils.simple_filter(
            copy.deepcopy(self.input_list),
            attr='fred',
            value='UP',
        )
        self.assertEqual([], output)
    def test_simple_filter_attr_value(self):
        output = api_utils.simple_filter(
            copy.deepcopy(self.input_list),
            attr='status',
            value='',
        )
        self.assertEqual([], output)

        output = api_utils.simple_filter(
            copy.deepcopy(self.input_list),
            attr='status',
            value='UP',
        )
        self.assertEqual(
            [api_fakes.RESP_ITEM_1, api_fakes.RESP_ITEM_3],
            output,
        )

        output = api_utils.simple_filter(
            copy.deepcopy(self.input_list),
            attr='fred',
            value='UP',
        )
        self.assertEqual([], output)
Example #8
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)

        image_client = self.app.client_manager.image

        kwargs = {}
        if parsed_args.public:
            kwargs['public'] = True
        if parsed_args.private:
            kwargs['private'] = True
        kwargs['detailed'] = bool(parsed_args.property or parsed_args.long)

        if parsed_args.long:
            columns = (
                'ID',
                'Name',
                'Disk Format',
                'Container Format',
                'Size',
                'Status',
                'is_public',
                'protected',
                'owner',
                'properties',
            )
            column_headers = (
                'ID',
                'Name',
                'Disk Format',
                'Container Format',
                'Size',
                'Status',
                'Visibility',
                'Protected',
                'Owner',
                'Properties',
            )
        else:
            columns = ("ID", "Name")
            column_headers = columns

        data = image_client.api.image_list(**kwargs)

        if parsed_args.property:
            # NOTE(dtroyer): coerce to a list to subscript it in py3
            attr, value = list(parsed_args.property.items())[0]
            api_utils.simple_filter(
                data,
                attr=attr,
                value=value,
                property_field='properties',
            )

        data = utils.sort_items(data, parsed_args.sort)

        return (
            column_headers,
            (utils.get_dict_properties(
                s,
                columns,
                formatters={
                    'is_public': _format_visibility,
                    'properties': utils.format_dict,
                },
            ) for s in data)
        )
 def test_simple_filter_attr_only(self):
     output = api_utils.simple_filter(
         copy.deepcopy(self.input_list),
         attr='status',
     )
     self.assertEqual(self.input_list, output)
 def test_simple_filter_no_attr(self):
     output = api_utils.simple_filter(copy.deepcopy(self.input_list), )
     self.assertEqual(self.input_list, output)
 def test_simple_filter_none(self):
     output = api_utils.simple_filter()
     self.assertIsNone(output)
Example #12
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)

        image_client = self.app.client_manager.image

        kwargs = {}
        if parsed_args.public:
            kwargs['public'] = True
        if parsed_args.private:
            kwargs['private'] = True
        if parsed_args.shared:
            kwargs['shared'] = True

        if parsed_args.long:
            columns = (
                'ID',
                'Name',
                'Disk Format',
                'Container Format',
                'Size',
                'Status',
                'visibility',
                'protected',
                'owner',
                'tags',
            )
            column_headers = (
                'ID',
                'Name',
                'Disk Format',
                'Container Format',
                'Size',
                'Status',
                'Visibility',
                'Protected',
                'Owner',
                'Tags',
            )
        else:
            columns = ("ID", "Name")
            column_headers = columns

        # List of image data received
        data = []
        # No pages received yet, so start the page marker at None.
        marker = None
        while True:
            page = image_client.api.image_list(marker=marker, **kwargs)
            if not page:
                break
            data.extend(page)
            # Set the marker to the id of the last item we received
            marker = page[-1]['id']

        if parsed_args.property:
            # NOTE(dtroyer): coerce to a list to subscript it in py3
            attr, value = list(parsed_args.property.items())[0]
            api_utils.simple_filter(
                data,
                attr=attr,
                value=value,
                property_field='properties',
            )

        data = utils.sort_items(data, parsed_args.sort)

        return (column_headers, (utils.get_dict_properties(
            s,
            columns,
            formatters={
                'tags': utils.format_dict,
            },
        ) for s in data))
Example #13
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)

        image_client = self.app.client_manager.image

        kwargs = {}
        if parsed_args.public:
            kwargs['public'] = True
        if parsed_args.private:
            kwargs['private'] = True
        kwargs['detailed'] = bool(parsed_args.property or parsed_args.long)

        if parsed_args.long:
            columns = (
                'ID',
                'Name',
                'Disk Format',
                'Container Format',
                'Size',
                'Status',
                'is_public',
                'protected',
                'owner',
                'properties',
            )
            column_headers = (
                'ID',
                'Name',
                'Disk Format',
                'Container Format',
                'Size',
                'Status',
                'Visibility',
                'Protected',
                'Owner',
                'Properties',
            )
        else:
            columns = ("ID", "Name")
            column_headers = columns

        data = image_client.api.image_list(**kwargs)

        if parsed_args.property:
            # NOTE(dtroyer): coerce to a list to subscript it in py3
            attr, value = list(parsed_args.property.items())[0]
            api_utils.simple_filter(
                data,
                attr=attr,
                value=value,
                property_field='properties',
            )

        data = utils.sort_items(data, parsed_args.sort)

        return (column_headers, (utils.get_dict_properties(
            s,
            columns,
            formatters={
                'is_public': _format_visibility,
                'properties': utils.format_dict,
            },
        ) for s in data))
Example #14
0
    def take_action(self, parsed_args):
        image_client = self.app.client_manager.image

        kwargs = {}
        if parsed_args.public:
            kwargs['public'] = True
        if parsed_args.private:
            kwargs['private'] = True
        if parsed_args.community:
            kwargs['community'] = True
        if parsed_args.shared:
            kwargs['shared'] = True
        if parsed_args.limit:
            kwargs['limit'] = parsed_args.limit
        if parsed_args.marker:
            kwargs['marker'] = utils.find_resource(image_client.images,
                                                   parsed_args.marker).id
        if parsed_args.name:
            kwargs['name'] = parsed_args.name
        if parsed_args.status:
            kwargs['status'] = parsed_args.status
        if parsed_args.member_status:
            kwargs['member_status'] = parsed_args.member_status
        if parsed_args.tag:
            kwargs['tag'] = parsed_args.tag
        if parsed_args.long:
            columns = (
                'ID',
                'Name',
                'Disk Format',
                'Container Format',
                'Size',
                'Checksum',
                'Status',
                'visibility',
                'protected',
                'owner',
                'tags',
            )
            column_headers = (
                'ID',
                'Name',
                'Disk Format',
                'Container Format',
                'Size',
                'Checksum',
                'Status',
                'Visibility',
                'Protected',
                'Project',
                'Tags',
            )
        else:
            columns = ("ID", "Name", "Status")
            column_headers = columns

        # List of image data received
        data = []
        limit = None
        if 'limit' in kwargs:
            limit = kwargs['limit']
        if 'marker' in kwargs:
            data = image_client.api.image_list(**kwargs)
        else:
            # No pages received yet, so start the page marker at None.
            marker = None
            while True:
                page = image_client.api.image_list(marker=marker, **kwargs)
                if not page:
                    break
                data.extend(page)
                # Set the marker to the id of the last item we received
                marker = page[-1]['id']
                if limit:
                    break

        if parsed_args.property:
            for attr, value in parsed_args.property.items():
                api_utils.simple_filter(
                    data,
                    attr=attr,
                    value=value,
                    property_field='properties',
                )

        data = utils.sort_items(data, parsed_args.sort, str)

        return (column_headers, (utils.get_dict_properties(
            s,
            columns,
            formatters={
                'tags': utils.format_list,
            },
        ) for s in data))
Example #15
0
    def take_action(self, parsed_args):
        image_client = self.app.client_manager.image

        kwargs = {}
        if parsed_args.public:
            kwargs['public'] = True
        if parsed_args.private:
            kwargs['private'] = True
        if parsed_args.community:
            kwargs['community'] = True
        if parsed_args.shared:
            kwargs['shared'] = True
        if parsed_args.limit:
            kwargs['limit'] = parsed_args.limit
        if parsed_args.marker:
            kwargs['marker'] = utils.find_resource(image_client.images,
                                                   parsed_args.marker).id
        if parsed_args.name:
            kwargs['name'] = parsed_args.name
        if parsed_args.status:
            kwargs['status'] = parsed_args.status
        if parsed_args.member_status:
            kwargs['member_status'] = parsed_args.member_status
        if parsed_args.tag:
            kwargs['tag'] = parsed_args.tag
        if parsed_args.long:
            columns = (
                'ID',
                'Name',
                'Disk Format',
                'Container Format',
                'Size',
                'Checksum',
                'Status',
                'visibility',
                'protected',
                'owner',
                'tags',
            )
            column_headers = (
                'ID',
                'Name',
                'Disk Format',
                'Container Format',
                'Size',
                'Checksum',
                'Status',
                'Visibility',
                'Protected',
                'Project',
                'Tags',
            )
        else:
            columns = ("ID", "Name", "Status")
            column_headers = columns

        # List of image data received
        data = []
        limit = None
        if 'limit' in kwargs:
            limit = kwargs['limit']
        if 'marker' in kwargs:
            data = image_client.api.image_list(**kwargs)
        else:
            # No pages received yet, so start the page marker at None.
            marker = None
            while True:
                page = image_client.api.image_list(marker=marker, **kwargs)
                if not page:
                    break
                data.extend(page)
                # Set the marker to the id of the last item we received
                marker = page[-1]['id']
                if limit:
                    break

        if parsed_args.property:
            for attr, value in parsed_args.property.items():
                api_utils.simple_filter(
                    data,
                    attr=attr,
                    value=value,
                    property_field='properties',
                )

        data = utils.sort_items(data, parsed_args.sort, str)

        return (
            column_headers,
            (utils.get_dict_properties(
                s,
                columns,
                formatters={
                    'tags': utils.format_list,
                },
            ) for s in data)
        )
 def test_simple_filter_attr_only(self):
     output = api_utils.simple_filter(
         copy.deepcopy(self.input_list),
         attr='status',
     )
     self.assertEqual(self.input_list, output)
 def test_simple_filter_no_attr(self):
     output = api_utils.simple_filter(
         copy.deepcopy(self.input_list),
     )
     self.assertEqual(self.input_list, output)
 def test_simple_filter_none(self):
     output = api_utils.simple_filter(
     )
     self.assertIsNone(output)
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)

        image_client = self.app.client_manager.image

        kwargs = {}
        if parsed_args.public:
            kwargs['public'] = True
        if parsed_args.private:
            kwargs['private'] = True
        # Note: We specifically need to do that below to get the 'status'
        #       column.
        #
        # Always set kwargs['detailed'] to True, and then filter the columns
        # according to whether the --long option is specified or not.
        kwargs['detailed'] = True

        if parsed_args.long:
            columns = (
                'ID',
                'Name',
                'Disk Format',
                'Container Format',
                'Size',
                'Status',
                'is_public',
                'protected',
                'owner',
                'properties',
            )
            column_headers = (
                'ID',
                'Name',
                'Disk Format',
                'Container Format',
                'Size',
                'Status',
                'Visibility',
                'Protected',
                'Owner',
                'Properties',
            )
        else:
            columns = ("ID", "Name", "Status")
            column_headers = columns

        # List of image data received
        data = []
        # No pages received yet, so start the page marker at None.
        marker = None
        while True:
            page = image_client.api.image_list(marker=marker, **kwargs)
            if not page:
                break
            data.extend(page)
            # Set the marker to the id of the last item we received
            marker = page[-1]['id']

        if parsed_args.property:
            # NOTE(dtroyer): coerce to a list to subscript it in py3
            attr, value = list(parsed_args.property.items())[0]
            api_utils.simple_filter(
                data,
                attr=attr,
                value=value,
                property_field='properties',
            )

        data = utils.sort_items(data, parsed_args.sort)

        return (
            column_headers,
            (utils.get_dict_properties(
                s,
                columns,
                formatters={
                    'is_public': _format_visibility,
                    'properties': utils.format_dict,
                },
            ) for s in data)
        )
Example #20
0
    def take_action(self, parsed_args):
        image_client = self.app.client_manager.image

        kwargs = {}
        if parsed_args.public:
            kwargs['public'] = True
        if parsed_args.private:
            kwargs['private'] = True
        if parsed_args.shared:
            kwargs['shared'] = True
        if parsed_args.limit:
            kwargs['limit'] = parsed_args.limit
        if parsed_args.marker:
            kwargs['marker'] = utils.find_resource(image_client.images,
                                                   parsed_args.marker).id

        if parsed_args.long:
            columns = (
                'ID',
                'Name',
                'Disk Format',
                'Container Format',
                'Size',
                'Status',
                'visibility',
                'protected',
                'owner',
                'tags',
            )
            column_headers = (
                'ID',
                'Name',
                'Disk Format',
                'Container Format',
                'Size',
                'Status',
                'Visibility',
                'Protected',
                'Project',
                'Tags',
            )
        else:
            columns = ("ID", "Name", "Status")
            column_headers = columns

        # List of image data received
        data = image_client.api.image_list(**kwargs)

        if parsed_args.property:
            # NOTE(dtroyer): coerce to a list to subscript it in py3
            attr, value = list(parsed_args.property.items())[0]
            api_utils.simple_filter(
                data,
                attr=attr,
                value=value,
                property_field='properties',
            )

        data = utils.sort_items(data, parsed_args.sort)

        return (
            column_headers,
            (utils.get_dict_properties(
                s,
                columns,
                formatters={
                    'tags': utils.format_list,
                },
            ) for s in data)
        )
Example #21
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)

        image_client = self.app.client_manager.image

        kwargs = {}
        if parsed_args.public:
            kwargs['public'] = True
        if parsed_args.private:
            kwargs['private'] = True
        if parsed_args.shared:
            kwargs['shared'] = True

        if parsed_args.long:
            columns = (
                'ID',
                'Name',
                'Disk Format',
                'Container Format',
                'Size',
                'Status',
                'visibility',
                'protected',
                'owner',
                'tags',
            )
            column_headers = (
                'ID',
                'Name',
                'Disk Format',
                'Container Format',
                'Size',
                'Status',
                'Visibility',
                'Protected',
                'Owner',
                'Tags',
            )
        else:
            columns = ("ID", "Name")
            column_headers = columns

        # List of image data received
        data = []
        # No pages received yet, so start the page marker at None.
        marker = None
        while True:
            page = image_client.api.image_list(marker=marker, **kwargs)
            if not page:
                break
            data.extend(page)
            # Set the marker to the id of the last item we received
            marker = page[-1]['id']

        if parsed_args.property:
            # NOTE(dtroyer): coerce to a list to subscript it in py3
            attr, value = list(parsed_args.property.items())[0]
            api_utils.simple_filter(
                data,
                attr=attr,
                value=value,
                property_field='properties',
            )

        data = utils.sort_items(data, parsed_args.sort)

        return (
            column_headers,
            (utils.get_dict_properties(
                s,
                columns,
                formatters={
                    'tags': utils.format_list,
                },
            ) for s in data)
        )
Example #22
0
    def take_action(self, parsed_args):
        self.log.debug("take_action(%s)", parsed_args)

        image_client = self.app.client_manager.image

        kwargs = {}
        if parsed_args.public:
            kwargs["public"] = True
        if parsed_args.private:
            kwargs["private"] = True
        kwargs["detailed"] = bool(parsed_args.property or parsed_args.long)

        if parsed_args.long:
            columns = (
                "ID",
                "Name",
                "Disk Format",
                "Container Format",
                "Size",
                "Status",
                "is_public",
                "protected",
                "owner",
                "properties",
            )
            column_headers = (
                "ID",
                "Name",
                "Disk Format",
                "Container Format",
                "Size",
                "Status",
                "Visibility",
                "Protected",
                "Owner",
                "Properties",
            )
        else:
            columns = ("ID", "Name")
            column_headers = columns

        # List of image data received
        data = []
        # No pages received yet, so start the page marker at None.
        marker = None
        while True:
            page = image_client.api.image_list(marker=marker, **kwargs)
            if not page:
                break
            data.extend(page)
            # Set the marker to the id of the last item we received
            marker = page[-1]["id"]

        if parsed_args.property:
            # NOTE(dtroyer): coerce to a list to subscript it in py3
            attr, value = list(parsed_args.property.items())[0]
            api_utils.simple_filter(data, attr=attr, value=value, property_field="properties")

        data = utils.sort_items(data, parsed_args.sort)

        return (
            column_headers,
            (
                utils.get_dict_properties(
                    s, columns, formatters={"is_public": _format_visibility, "properties": utils.format_dict}
                )
                for s in data
            ),
        )