Revision 44f510e1 snf-astakos-app/astakos/im/management/commands/resource-list.py

b/snf-astakos-app/astakos/im/management/commands/resource-list.py
31 31
# interpreted as representing official policies, either expressed
32 32
# or implied, of GRNET S.A.
33 33

  
34
from optparse import make_option
34 35
from astakos.im.models import Resource
35 36
from synnefo.webproject.management.commands import ListCommand
37
from ._common import show_resource_value, style_options, check_style
36 38

  
37 39

  
38 40
class Command(ListCommand):
39 41
    help = "List resources"
40 42
    object_class = Resource
41 43

  
44
    option_list = ListCommand.option_list + (
45
        make_option('--unit-style',
46
                    default='mb',
47
                    help=("Specify display unit for resource values "
48
                          "(one of %s); defaults to mb") % style_options),
49
    )
50

  
42 51
    FIELDS = {
43 52
        "id": ("id", "ID"),
44 53
        "name": ("name", "Resource Name"),
45 54
        "service": ("service", "Service"),
46
        "unit": ("unit", "Unit"),
47
        "limit": ("uplimit", "Base Quota"),
55
        "limit": ("limit_with_unit", "Base Quota"),
48 56
        "description": ("desc", "Description"),
49 57
        "allow_in_projects": ("allow_in_projects",
50 58
                              "Make resource available in projects"),
51 59
    }
52 60

  
53
    fields = ["id", "name", "service", "unit", "limit", "allow_in_projects",
61
    fields = ["id", "name", "service", "limit", "allow_in_projects",
54 62
              "description"]
63

  
64
    def show_limit(self, resource):
65
        limit = resource.uplimit
66
        return show_resource_value(limit, resource.name, self.unit_style)
67

  
68
    def handle_args(self, *args, **options):
69
        self.unit_style = options['unit_style']
70
        check_style(self.unit_style)
71

  
72
    def handle_db_objects(self, rows, *args, **kwargs):
73
        for resource in rows:
74
            resource.limit_with_unit = self.show_limit(resource)

Also available in: Unified diff