Revision d8ff7b56

b/kamaki/cli/commands/cyclades.py
175 175
        enum=FlagArgument('Enumerate results', '--enumerate'),
176 176
        flavor_id=ValueArgument('filter by flavor id', ('--flavor-id')),
177 177
        image_id=ValueArgument('filter by image id', ('--image-id')),
178
        user_id=ValueArgument('filter by user id', ('--user-id')),
179
        user_name=ValueArgument('filter by user name', ('--user-name')),
180
        status=ValueArgument(
181
            'filter by status (ACTIVE, STOPPED, REBOOT, ERROR, etc.)',
182
            ('--status')),
178 183
        meta=KeyValueArgument('filter by metadata key=values', ('--metadata')),
179 184
        meta_like=KeyValueArgument(
180 185
            'print only if in key=value, the value is part of actual value',
......
190 195
            srv['tenant_id'] += ' (%s)' % uuids[srv['tenant_id']]
191 196
        return servers
192 197

  
198
    def _apply_common_filters(self, servers):
199
        common_filters = dict()
200
        if self['status']:
201
            common_filters['status'] = self['status']
202
        if self['user_id'] or self['user_name']:
203
            uuid = self['user_id'] or self._username2uuid(self['user_name'])
204
            common_filters['user_id'] = uuid
205
        return filter_dicts_by_dict(servers, common_filters)
206

  
193 207
    def _filter_by_image(self, servers):
194 208
        iid = self['image_id']
195 209
        new_servers = []
......
228 242
        withimage = bool(self['image_id'])
229 243
        withflavor = bool(self['flavor_id'])
230 244
        withmeta = bool(self['meta'] or self['meta_like'])
231
        detail = self['detail'] or withimage or withflavor or withmeta
245
        withcommons = bool(
246
            self['status'] or self['user_id'] or self['user_name'])
247
        detail = self['detail'] or (
248
            withimage or withflavor or withmeta or withcommons)
232 249
        servers = self.client.list_servers(detail, self['since'])
233 250

  
234 251
        servers = self._filter_by_name(servers)
235 252
        servers = self._filter_by_id(servers)
253
        servers = self._apply_common_filters(servers)
236 254
        if withimage:
237 255
            servers = self._filter_by_image(servers)
238 256
        if withflavor:
......
688 706
class flavor_list(_init_cyclades, _optional_json, _name_filter, _id_filter):
689 707
    """List available hardware flavors"""
690 708

  
709
    PERMANENTS = ('id', 'name')
710

  
691 711
    arguments = dict(
692 712
        detail=FlagArgument('show detailed output', ('-l', '--details')),
693 713
        limit=IntArgument('limit # of listed flavors', ('-n', '--number')),
694 714
        more=FlagArgument(
695 715
            'output results in pages (-n to set items per page, default 10)',
696 716
            '--more'),
697
        enum=FlagArgument('Enumerate results', '--enumerate')
717
        enum=FlagArgument('Enumerate results', '--enumerate'),
718
        ram=ValueArgument('filter by ram', ('--ram')),
719
        vcpus=ValueArgument('filter by number of VCPUs', ('--vcpus')),
720
        disk=ValueArgument('filter by disk size in GB', ('--disk')),
721
        disk_template=ValueArgument(
722
            'filter by disk_templace', ('--disk-template'))
698 723
    )
699 724

  
725
    def _apply_common_filters(self, flavors):
726
        common_filters = dict()
727
        if self['ram']:
728
            common_filters['ram'] = self['ram']
729
        if self['vcpus']:
730
            common_filters['vcpus'] = self['vcpus']
731
        if self['disk']:
732
            common_filters['disk'] = self['disk']
733
        if self['disk_template']:
734
            common_filters['SNF:disk_template'] = self['disk_template']
735
        return filter_dicts_by_dict(flavors, common_filters)
736

  
700 737
    @errors.generic.all
701 738
    @errors.cyclades.connection
702 739
    def _run(self):
703
        flavors = self.client.list_flavors(self['detail'])
740
        withcommons = self['ram'] or self['vcpus'] or (
741
            self['disk'] or self['disk_template'])
742
        detail = self['detail'] or withcommons
743
        flavors = self.client.list_flavors(detail)
704 744
        flavors = self._filter_by_name(flavors)
705 745
        flavors = self._filter_by_id(flavors)
746
        if withcommons:
747
            flavors = self._apply_common_filters(flavors)
706 748
        if not (self['detail'] or self['json_output']):
707 749
            remove_from_items(flavors, 'links')
750
        if detail and not self['detail']:
751
            for flv in flavors:
752
                for key in set(flv).difference(self.PERMANENTS):
753
                    flv.pop(key)
708 754
        pg_size = 10 if self['more'] and not self['limit'] else self['limit']
709 755
        self._print(
710 756
            flavors,
b/kamaki/cli/commands/pithos.py
340 340
        detail=FlagArgument('detailed output', ('-l', '--list')),
341 341
        limit=IntArgument('limit number of listed items', ('-n', '--number')),
342 342
        marker=ValueArgument('output greater that marker', '--marker'),
343
        prefix=ValueArgument('output starting with prefix', '--prefix'),
344 343
        delimiter=ValueArgument('show output up to delimiter', '--delimiter'),
345 344
        path=ValueArgument(
346 345
            'show output starting with prefix up to /', '--path'),
......
443 442
            files = self._filter_by_name(r.json)
444 443
            self._print(files, self.print_containers)
445 444
        else:
446
            prefix = self.path or self['prefix'] or self['name_prefix']
445
            prefix = (self.path and not self['name']) or self['name_pref']
447 446
            r = self.client.container_get(
448 447
                limit=False if self['more'] else self['limit'],
449 448
                marker=self['marker'],

Also available in: Unified diff