Revision 77fccdd4 snf-cyclades-app/synnefo/api/management/commands/server-show.py

b/snf-cyclades-app/synnefo/api/management/commands/server-show.py
42 42
class Command(BaseCommand):
43 43
    args = "<server ID>"
44 44
    help = "Show server info"
45
    
45

  
46 46
    def handle(self, *args, **options):
47 47
        if len(args) != 1:
48 48
            raise CommandError("Please provide a server ID")
49
        
49

  
50 50
        try:
51 51
            server_id = int(args[0])
52 52
            server = VirtualMachine.objects.get(id=server_id)
53 53
        except (ValueError, VirtualMachine.DoesNotExist):
54 54
            raise CommandError("Invalid server ID")
55
        
55

  
56 56
        flavor = '%s (%s)' % (server.flavor.id, server.flavor.name)
57
        image = '%s (%s)' % (server.imageid,
58
                        get_image(server.imageid, server.userid).get('name'))
59
        
57
        userid = server.userid
58

  
59
        imageid = server.imageid
60
        try:
61
            image_name = get_image(imageid, userid).get('name')
62
        except:
63
            image_name = "None"
64
        image = '%s (%s)' % (imageid, image_name)
65

  
60 66
        kv = {
61 67
            'id': server_id,
62 68
            'name': server.name,
63
            'owner': server.userid,
69
            'owner': userid,
64 70
            'created': format_date(server.created),
65 71
            'updated': format_date(server.updated),
66 72
            'image': image,
......
70 76
            'suspended': format_bool(server.suspended),
71 77
            'state': server.operstate
72 78
        }
73
        
79

  
74 80
        for key, val in sorted(kv.items()):
75 81
            line = '%s: %s\n' % (key.rjust(16), val)
76 82
            self.stdout.write(line.encode('utf8'))

Also available in: Unified diff