Revision 4500650c snf-cyclades-app/synnefo/api/management/commands/server-inspect.py

b/snf-cyclades-app/synnefo/api/management/commands/server-inspect.py
37 37

  
38 38
from synnefo.lib.utils import merge_time
39 39
from synnefo.logic.rapi import GanetiApiError
40
from synnefo.management.common import Omit
40 41
from synnefo.management import common
41 42

  
42 43

  
......
61 62
            dest='jobs',
62 63
            default=False,
63 64
            help="Show non-archived jobs concerning server."),
64
        make_option('--uuids',
65
        make_option('--displayname',
65 66
            action='store_true',
66
            dest='use_uuids',
67
            dest='displayname',
67 68
            default=False,
68
            help="Display UUIDs instead of user emails"),
69
            help="Display both uuid and display name"),
69 70
    )
70 71

  
71 72
    def handle(self, *args, **options):
......
74 75

  
75 76
        vm = common.get_vm(args[0])
76 77

  
78
        displayname = options['displayname']
79

  
80
        ucache = common.UUIDCache()
81

  
77 82
        try:
78 83
            image = common.get_image(vm.imageid, vm.userid)['name']
79 84
        except:
80 85
            image = vm.imageid
81 86

  
82 87
        sep = '-' * 80 + '\n'
83
        labels = ('name', 'owner', 'flavor', 'image', 'state', 'backend',
84
                  'deleted', 'action', 'backendjobid', 'backendopcode',
85
                  'backendjobstatus', 'backend_time')
86

  
87
        user = vm.userid
88
        if options['use_uuids'] is False:
89
            ucache = common.UUIDCache()
90
            user = ucache.get_user(vm.userid)
91

  
92
        fields = (vm.name, user, vm.flavor.name, image,
93
                  common.format_vm_state(vm), str(vm.backend),
94
                  str(vm.deleted), str(vm.action), str(vm.backendjobid),
95
                  str(vm.backendopcode), str(vm.backendjobstatus),
96
                  str(vm.backendtime))
88
        labels = filter(lambda x: x is not Omit,
89
                        ['name', 'owner_uuid',
90
                         'owner_name' if displayname else Omit,
91
                         'flavor', 'image', 'state', 'backend', 'deleted',
92
                         'action', 'backendjobid', 'backendopcode',
93
                         'backendjobstatus', 'backend_time'])
94

  
95
        uuid = vm.userid
96
        if displayname:
97
            dname = ucache.get_user(uuid)
98

  
99
        fields = filter(lambda x: x is not Omit,
100
                        [vm.name, uuid, dname if displayname else Omit,
101
                         vm.flavor.name, image, common.format_vm_state(vm),
102
                         str(vm.backend), str(vm.deleted), str(vm.action),
103
                         str(vm.backendjobid), str(vm.backendopcode),
104
                         str(vm.backendjobstatus), str(vm.backendtime)])
97 105

  
98 106
        self.stdout.write(sep)
99 107
        self.stdout.write('State of Server in DB\n')

Also available in: Unified diff