~ubuntu-branches/ubuntu/natty/euca2ools/natty-201106142030

« back to all changes in this revision

Viewing changes to debian/patches/print-instances-cleanup.patch

  • Committer: Scott Moser
  • Date: 2010-11-17 21:23:16 UTC
  • Revision ID: smoser@ubuntu.com-20101117212316-is94e55u3jv46y9l
move to quilt 3.0 source format, re-apply all relevant delta

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Description: combine duplicate print-instaces code
 
2
 The code had 2 locations where it prints instances,
 
3
 describe-instances and run-instances.  The implementations are different
 
4
 when they should be the same.
 
5
 .
 
6
 The bug that is fixed here is that in describe-instances, there is a
 
7
 trailing space on each field ("running ", not "running").
 
8
 But overall, this patch reduces code.
 
9
 .
 
10
 Originally from 1.2-0ubuntu8 package version
 
11
Author: Scott Moser <scott.moser@canonical.com>
 
12
Last-Update: 2010-11-17
 
13
Bug: https://launchpad.net/bugs/531453
 
14
Forwarded: no
 
15
--- a/bin/euca-describe-instances
 
16
+++ b/bin/euca-describe-instances
 
17
@@ -37,7 +37,7 @@
 
18
 import sys
 
19
 import os
 
20
 from euca2ools import Euca2ool, InstanceValidationError, Util, \
 
21
-    ConnectionFailed
 
22
+    ConnectionFailed, print_instances
 
23
 
 
24
 usage_string = \
 
25
     """
 
26
@@ -85,36 +85,7 @@
 
27
             reservation_string += '%s%s' % (group_delim, group.id)
 
28
             group_delim = ', '
 
29
         print 'RESERVATION\t%s' % reservation_string
 
30
-        for instance in instances:
 
31
-            if instance:
 
32
-                instance_string = '%s\t%s\t%s\t%s\t%s' % (instance.id,
 
33
-                        instance.image_id, instance.public_dns_name,
 
34
-                        instance.private_dns_name, instance.state)
 
35
-                if instance.key_name:
 
36
-                    instance_string += ' \t%s' % instance.key_name
 
37
-                if instance.ami_launch_index:
 
38
-                    instance_string += ' \t%s' \
 
39
-                        % instance.ami_launch_index
 
40
-                if instance.product_codes:
 
41
-                    first = True
 
42
-                    for p in instance.product_codes:
 
43
-                        if first:
 
44
-                            instance_string += ' \t%s' % p
 
45
-                            first = False
 
46
-                        else:
 
47
-                            instance_string += ',%s' % p
 
48
-                if instance.instance_type:
 
49
-                    instance_string += ' \t%s' % instance.instance_type
 
50
-                if instance.launch_time:
 
51
-                    instance_string += ' \t%s' % instance.launch_time
 
52
-                if instance.placement:
 
53
-                    instance_string += ' \t%s' % instance.placement
 
54
-                if instance.kernel:
 
55
-                    instance_string += ' \t%s' % instance.kernel
 
56
-                if instance.ramdisk:
 
57
-                    instance_string += ' \t%s' % instance.ramdisk
 
58
-                print 'INSTANCE\t%s' % instance_string
 
59
-
 
60
+        print_instances(instances)
 
61
 
 
62
 def main():
 
63
     euca = None
 
64
--- a/euca2ools/euca2ools/__init__.py
 
65
+++ b/euca2ools/euca2ools/__init__.py
 
66
@@ -1456,3 +1456,23 @@
 
67
             dict[keylist[i]] = values[i]
 
68
 
 
69
 
 
70
+def print_instances(instances, nil=""):
 
71
+    members=( "id", "image_id", "public_dns_name", "private_dns_name",
 
72
+        "state", "key_name", "ami_launch_index", "product_codes",
 
73
+        "instance_type", "launch_time", "placement", "kernel",
 
74
+        "ramdisk" )
 
75
+
 
76
+    for instance in instances:
 
77
+        # in old describe-instances, there was a check for 'if instance:'
 
78
+        # I (smoser) have carried this over, but dont know how instance
 
79
+        # could be false
 
80
+        if not instance: continue
 
81
+        items=[ ]
 
82
+        for member in members:
 
83
+            val = getattr(instance,member,nil)
 
84
+            # product_codes is a list
 
85
+            if val is None: val = nil
 
86
+            if hasattr(val,'__iter__'):
 
87
+                val = ','.join(val)
 
88
+            items.append(val)
 
89
+        print "INSTANCE\t%s" % '\t'.join(items)
 
90
--- a/bin/euca-run-instances
 
91
+++ b/bin/euca-run-instances
 
92
@@ -36,7 +36,7 @@
 
93
 import getopt
 
94
 import sys
 
95
 import os
 
96
-from euca2ools import Euca2ool, Util, ConnectionFailed
 
97
+from euca2ools import Euca2ool, Util, ConnectionFailed, print_instances
 
98
 
 
99
 usage_string = \
 
100
     """
 
101
@@ -101,20 +101,7 @@
 
102
         reservation_string += '%s%s' % (group_delim, group.id)
 
103
         group_delim = ', '
 
104
     print 'RESERVATION\t%s' % reservation_string
 
105
-    for instance in reservation.instances:
 
106
-        instance_string = '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s' % (
 
107
-            instance.id,
 
108
-            instance.image_id,
 
109
-            instance.public_dns_name,
 
110
-            instance.private_dns_name,
 
111
-            instance.state,
 
112
-            instance.key_name,
 
113
-            instance.launch_time,
 
114
-            instance.kernel,
 
115
-            instance.ramdisk,
 
116
-            )
 
117
-        print 'INSTANCE\t%s' % instance_string
 
118
-
 
119
+    print_instances(reservation.instances)
 
120
 
 
121
 def read_user_data(user_data_filename):
 
122
     USER_DATA_CHUNK_SIZE = 512