[pkg-eucalyptus-commits] [SCM] managing cloud instances for Eucalyptus branch, master, updated. 3.0.0-alpha3-257-g1da8e3a

Garrett Holmstrom gholms at fedoraproject.org
Sun Jun 16 02:30:58 UTC 2013


The following commit has been merged in the master branch:
commit a075ef6de7e88a0d391aed60a05d52cb57b54c10
Author: Garrett Holmstrom <gholms at fedoraproject.org>
Date:   Mon Apr 1 19:02:10 2013 -0700

    Port DescribeInstanceAttribute to requestbuilder

diff --git a/bin/euca-describe-instance-attribute b/bin/euca-describe-instance-attribute
index 0a5c911..ac02d9e 100755
--- a/bin/euca-describe-instance-attribute
+++ b/bin/euca-describe-instance-attribute
@@ -1,7 +1,6 @@
-#!/usr/bin/python
+#!/usr/bin/python -tt
 
 import euca2ools.commands.euca.describeinstanceattribute
 
 if __name__ == '__main__':
-    cmd = euca2ools.commands.euca.describeinstanceattribute.DescribeInstanceAttribute()
-    cmd.main_cli()
+    euca2ools.commands.euca.describeinstanceattribute.DescribeInstanceAttribute.run()
diff --git a/euca2ools/commands/euca/describeinstanceattribute.py b/euca2ools/commands/euca/describeinstanceattribute.py
index 8985945..5f256ab 100644
--- a/euca2ools/commands/euca/describeinstanceattribute.py
+++ b/euca2ools/commands/euca/describeinstanceattribute.py
@@ -28,89 +28,94 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
 
-from boto.roboto.param import Param
-import euca2ools.commands.eucacommand
+import base64
+from euca2ools.commands.euca import EucalyptusRequest
+from requestbuilder import Arg, MutuallyExclusiveArgList
+from requestbuilder.exceptions import ArgumentError
 
 
-class DescribeInstanceAttribute(euca2ools.commands.eucacommand.EucaCommand):
-    Description = ("Show one of an instance's attributes.\n\n"
+class DescribeInstanceAttribute(EucalyptusRequest):
+    DESCRIPTION = ("Show one of an instance's attributes.\n\n"
                    "Note that exactly one attribute may be shown at a time.")
-    Options = [Param(name='instanceType', short_name='t',
-                     long_name='instance-type', optional=True,
-                     ptype='boolean', doc="show the instance's type"),
-               Param(name='kernel', long_name='kernel', optional=True,
-                     ptype='boolean', doc="show the instance's kernel ID"),
-               Param(name='ramdisk', long_name='ramdisk', optional=True,
-                     ptype='boolean', doc="show the instance's ramdisk ID"),
-               Param(name='userData', long_name='user-data', optional=True,
-                     ptype='boolean',
-                     doc='show any user-data supplied to the instance'),
-               Param(name='disableApiTermination',
-                     long_name='disable-api-termination', optional=True,
-                     ptype='boolean', doc=('whether the instance can be '
-                     'terminated using euca-terminate-instances')),
-               Param(name='instanceInitiatedShutdownBehavior',
-                     long_name='instance-initiated-shutdown-behavior',
-                     optional=True, ptype='boolean', doc=('whether the '
-                     'instance will stop or terminate when shut down')),
-               Param(name='rootDeviceName', long_name='root-device-name',
-                     optional=True, ptype='boolean',
-                     doc="name of the instance's root device volume"),
-               Param(name='blockDeviceMapping', short_name='b',
-                     long_name='block-device-mapping', optional=True,
-                     ptype='boolean', doc='block device mappings'),
-               Param(name='sourceDestCheck', long_name='source-dest-check',
-                     optional=True, ptype='boolean',
-                     doc=('whether a VPC instance has source/destination '
-                     'checking of its network traffic enabled')),
-               Param(name='groupSet', short_name='g', long_name='group-id',
-                     optional=True, ptype='boolean',
-                     doc='the security groups the instance belongs to'),
-               Param(name='productCodes', short_name='p',
-                     long_name='product-code', optional=True, ptype='boolean',
-                     doc='product codes associated with the instance'),
-               Param(name='ebsOptimized', long_name='ebs-optimized',
-                     optional=True, ptype='boolean',
-                     doc='whether the instance is optimized for EBS I/O')]
-    Args = [Param(name='instance_id', optional=False, ptype='string',
-                  cardinality=1, doc='ID of the instance to describe')]
-
-    def main(self):
-        # Small bug:  when more than one is requested we arbitrarily pick one
-        for attr_name in [opt.name for opt in self.Options]:
-            if getattr(self, attr_name, None):
-                conn = self.make_connection_cli()
-                result = self.make_request_cli(conn, 'get_instance_attribute',
-                                               instance_id=self.instance_id,
-                                               attribute=attr_name)
-                return (attr_name, result)
-        self.display_error_and_exit('error: an attribute must be specified')
+    ARGS = [Arg('InstanceId', metavar='INSTANCE',
+                help='ID of the instance to show info for (required)'),
+            MutuallyExclusiveArgList(True,
+                Arg('-b', '--block-device-mapping', dest='Attribute',
+                    action='store_const', const='blockDeviceMapping',
+                    help='show block device mappings'),
+                Arg('--disable-api-termination', dest='Attribute',
+                    action='store_const', const='disableApiTermination',
+                    help='show whether termination is disabled'),
+                Arg('--ebs-optimized', dest='Attribute', action='store_const',
+                    const='ebsOptimized', help='''show whether the root volume
+                    is optimized for EBS I/O'''),
+                Arg('-g', '--group-id', dest='Attribute', action='store_const',
+                    const='groupSet',
+                    help='show the security groups the instance belongs to'),
+                Arg('-p', '--product-code', dest='Attribute',
+                    action='store_const', const='productCodes',
+                    help='show any associated product codes'),
+                Arg('--instance-initiated-shutdown-behavior', dest='Attribute',
+                    action='store_const',
+                    const='instanceInitiatedShutdownBehavior',
+                    help='''show whether the instance stops or terminates
+                    when shut down'''),
+                Arg('-t', '--instance-type', dest='Attribute',
+                    action='store_const', const='instanceType',
+                    help="show the instance's type"),
+                Arg('--kernel', dest='Attribute', action='store_const',
+                    const='kernel', help='''show the ID of the kernel image
+                    associated with the instance'''),
+                Arg('--ramdisk', dest='Attribute', action='store_const',
+                    const='ramdisk', help='''show the ID of the ramdisk image
+                    associated with the instance'''),
+                Arg('--root-device-name', dest='Attribute',
+                    action='store_const', const='rootDeviceName',
+                    help='''show the name of the instance's root device
+                    (e.g. '/dev/sda1')'''),
+                Arg('--source-dest-check', dest='Attribute',
+                    action='store_const', const='sourceDestCheck',
+                    help='''[VPC only] show whether source/destination checking
+                    is enabled for the instance'''),
+                Arg('--user-data', dest='Attribute', action='store_const',
+                    const='userData', help="show the instance's user-data"))]
+    LIST_TAGS = ['blockDeviceMapping', 'groupSet', 'productCodes']
 
     def print_result(self, result):
-        attr_name, value = result
-
         # Deal with complex data first
-        if attr_name == 'blockDeviceMapping':
-            for device, mapping in value['blockDeviceMapping'].iteritems():
-                print '\t'.join(('BLOCKDEVICE', device, mapping.volume_id,
-                                 mapping.attach_time,
-                                 str(mapping.delete_on_termination).lower()))
+        if self.args['Attribute'] == 'blockDeviceMapping':
+            for mapping in result.get('blockDeviceMapping', []):
+                ebs = mapping.get('ebs', {})
+                print self.tabify(('BLOCKDEVICE', mapping.get('deviceName'),
+                                   ebs.get('volumeId'), ebs.get('attachTime'),
+                                   ebs.get('deleteOnTermination')))
             # The EC2 tools have a couple more fields that I haven't been
             # able to identify.  If you figure out what they are, please send
             # a patch.
-        elif attr_name == 'groupSet':
-            ## TODO:  test this (EC2 doesn't seem to return any results)
-            group_ids = [getattr(group, 'id', group.name) for group in
-                         value.get('groupSet', [])]
-            print '\t'.join((attr_name, self.instance_id,
-                             ', '.join(group_ids)))
-        elif attr_name == 'productCodes':
-            ## TODO:  test this (I don't have anything I can test it with)
-            print '\t'.join((attr_name, self.instance_id,
-                             ', '.join(value.get('productCodes', []))))
+        elif self.args['Attribute'] == 'groupSet':
+            ## TODO:  test this in the wild (I don't have a VPC to work with)
+            groups = (group.get('groupId') or group.get('groupName')
+                      for group in result.get('groupSet', []))
+            print self.tabify(('groupSet', result.get('instanceId'),
+                               ', '.join(groups)))
+        elif self.args['Attribute'] == 'productCodes':
+            ## TODO:  test this in the wild (I don't have anything I can test
+            ##        it with)
+            codes = (code.get('productCode') for code in
+                     result.get('productCodes', []))
+            print self.tabify(('productCodes', result.get('instanceId'),
+                               ', '.join(codes)))
+        elif self.args['Attribute'] == 'userData':
+            userdata = base64.b64decode(result.get('userData', {})
+                                        .get('value', ''))
+            if userdata:
+                print self.tabify(('userData', result.get('instanceId')))
+                print userdata
+            else:
+                print self.tabify(('userData', result.get('instanceId'), None))
         else:
-            print '\t'.join((attr_name, self.instance_id, value[attr_name]))
-
-    def main_cli(self):
-        result = self.main()
-        self.print_result(result)
+            attr = result.get(self.args['Attribute'])
+            if isinstance(attr, dict) and 'value' in attr:
+                attr = attr['value']
+            print self.tabify((self.args['Attribute'], result.get('instanceId'),
+                               attr))

-- 
managing cloud instances for Eucalyptus



More information about the pkg-eucalyptus-commits mailing list