[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:29:43 UTC 2013


The following commit has been merged in the master branch:
commit 67d6fe6b356c9aa0da8345bd688cf71ed3ed8634
Author: Garrett Holmstrom <gholms at fedoraproject.org>
Date:   Sat Apr 21 14:19:10 2012 -0700

    Rewrite DescribeInstances
    
    FIXME:  field order may still be incorrect

diff --git a/bin/euca-describe-instances b/bin/euca-describe-instances
index 3ecef93..80edf49 100755
--- a/bin/euca-describe-instances
+++ b/bin/euca-describe-instances
@@ -1,41 +1,6 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-
-# Software License Agreement (BSD License)
-#
-# Copyright (c) 2009-2011, Eucalyptus Systems, Inc.
-# All rights reserved.
-#
-# Redistribution and use of this software in source and binary forms, with or
-# without modification, are permitted provided that the following conditions
-# are met:
-#
-#   Redistributions of source code must retain the above
-#   copyright notice, this list of conditions and the
-#   following disclaimer.
-#
-#   Redistributions in binary form must reproduce the above
-#   copyright notice, this list of conditions and the
-#   following disclaimer in the documentation and/or other
-#   materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-#
-# Author: Neil Soman neil at eucalyptus.com
-#         Mitch Garnaat mgarnaat at eucalyptus.com
+#!/usr/bin/python -tt
 
 import euca2ools.commands.euca.describeinstances
 
 if __name__ == '__main__':
-    cmd = euca2ools.commands.euca.describeinstances.DescribeInstances()
-    cmd.main_cli()
+    euca2ools.commands.euca.describeinstances.DescribeInstances().do_cli()
diff --git a/euca2ools/commands/euca/__init__.py b/euca2ools/commands/euca/__init__.py
index f0e4194..343792c 100644
--- a/euca2ools/commands/euca/__init__.py
+++ b/euca2ools/commands/euca/__init__.py
@@ -29,6 +29,7 @@
 # POSSIBILITY OF SUCH DAMAGE.
 
 import argparse
+from operator import itemgetter
 import os.path
 from requestbuilder import Arg, CONNECTION
 from requestbuilder.mixins import TabifyingCommand
@@ -151,7 +152,19 @@ class EucalyptusRequest(Euca2oolsRequest, TabifyingCommand):
         else:
             return response
 
+    def print_reservation(self, reservation):
+        res_line = ['RESERVATION', reservation['reservationId'],
+                    reservation.get('ownerId')]
+        group_ids = [group['groupId'] for group in reservation['groupSet']]
+        res_line.append(', '.join(group_ids))
+        print self.tabify(res_line)
+        for instance in sorted(reservation.get('instancesSet', []),
+                               itemgetter('amiLaunchIndex')):
+            self.print_instance(instance)
+
     def print_instance(self, instance):
+        ## FIXME: Amazon's documentation doesn't say what order the fields in
+        ##        ec2-describe-instances output appear.
         instance_line = ['INSTANCE']
         for key in ['instanceId', 'imageId', 'dnsName', 'privateDnsName']:
             instance_line.append(instance.get(key))
@@ -166,6 +179,7 @@ class EucalyptusRequest(Euca2oolsRequest, TabifyingCommand):
         instance_line.append(instance.get('placement', {}).get('availabilityZone'))
         instance_line.append(instance.get('kernelId'))
         instance_line.append(instance.get('ramdiskId'))
+        instance_line.append(None) # What is this?
         if instance.get('monitoring'):
             instance_line.append('monitoring-' +
                                  instance['monitoring'].get('state'))
@@ -173,11 +187,16 @@ class EucalyptusRequest(Euca2oolsRequest, TabifyingCommand):
             instance_line.append(None)
         instance_line.append(instance.get('ipAddress'))
         instance_line.append(instance.get('privateIpAddress'))
+        instance_line.append(instance.get('vpcId'))
+        instance_line.append(instance.get('subnetId'))
         instance_line.append(instance.get('rootDeviceType'))
+        instance_line.append(None) # What is this?
+        instance_line.append(None) # What is this?
+        instance_line.append(None) # What is this?
+        instance_line.append(None) # What is this?
         instance_line.append(instance.get('virtualizationType'))
         instance_line.append(instance.get('hypervisor'))
-        instance_line.append(instance.get('subnetId'))
-        instance_line.append(instance.get('vpcId'))
+        instance_line.append(None) # What is this?
         instance_line.append(instance.get('placement', {}).get('groupName'))
         instance_line.append(','.join([group['groupId'] for group in
                                        instance.get('groupSet', [])]))
diff --git a/euca2ools/commands/euca/describeinstances.py b/euca2ools/commands/euca/describeinstances.py
index ea10ed8..ddb322b 100644
--- a/euca2ools/commands/euca/describeinstances.py
+++ b/euca2ools/commands/euca/describeinstances.py
@@ -1,6 +1,6 @@
 # Software License Agreement (BSD License)
 #
-# Copyright (c) 2009-2011, Eucalyptus Systems, Inc.
+# Copyright (c) 2009-2012, Eucalyptus Systems, Inc.
 # All rights reserved.
 #
 # Redistribution and use of this software in source and binary forms, with or
@@ -27,146 +27,80 @@
 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 # POSSIBILITY OF SUCH DAMAGE.
-#
-# Author: Neil Soman neil at eucalyptus.com
-#         Mitch Garnaat mgarnaat at eucalyptus.com
-
-import euca2ools.commands.eucacommand
-from boto.roboto.param import Param
-import euca2ools.utils
 
-class DescribeInstances(euca2ools.commands.eucacommand.EucaCommand):
+from requestbuilder import Arg, Filter, GenericTagFilter
+from . import EucalyptusRequest
 
+class DescribeInstances(EucalyptusRequest):
     APIVersion = '2010-08-31'
-    Description = 'Shows information about instances.'
-    Args = [Param(name='instance', ptype='string',
-                  cardinality='+', optional=True)]
-    Filters = [Param(name='architecture', ptype='string',
-                     doc="""Instance architecture.
-                     Valid values are i386 | x86_64"""),
-               Param(name='availability-zone', ptype='string',
-                     doc="Instance's Availability Zone"),
-               Param(name='block-device-mapping.attach-time',
-                     ptype='datetime',
-                     doc="""Attach time for an Amazon EBS volume mapped
-                     to the instance"""),
-               Param(name='block-device-mapping.delete-on-termination',
-                     ptype='boolean',
-                     doc="""Whether the Amazon EBS volume is deleted on
-                     instance termination."""),
-               Param(name='block-device-mapping.device-name', ptype='string',
-                     doc="""Device name (e.g., /dev/sdh) for an Amazon EBS volume
-                     mapped to the image."""),
-               Param(name='block-device-mapping.status', ptype='string',
-                     doc="""Status for an Amazon EBS volume mapped to the instance.
-                     Valid Values: attaching | attached | detaching | detached"""),
-               Param(name='block-device-mapping.volume-id', ptype='string',
-                     doc="""ID for an Amazon EBS volume mapped to the instance."""),
-               Param(name='client-token', ptype='string',
-                     doc="""Idempotency token you provided when you launched
-                     the instance."""),
-               Param(name='dns-name', ptype='string',
-                     doc='Public DNS name of the instance.'),
-               Param(name='group-id', ptype='string',
-                     doc='A security group the instance is in.'),
-               Param(name='hypervisor', ptype='string',
-                     doc="""Hypervisor type of the instance.
-                     Valid values are ovm | xen."""),
-               Param(name='image-id', ptype='string',
-                     doc='ID of the imageID used to launch the instance'),
-               Param(name='instance-id', ptype='string',
-                     doc='ID of the instance'),
-               Param(name='instance-lifecycle', ptype='string',
-                     doc='Whether this is a Spot Instance.'),
-               Param(name='instance-state-code', ptype='integer',
-                     doc='Code identifying the state of the instance'),
-               Param(name='instance-state-name', ptype='string',
-                     doc='State of the instance.'),
-               Param(name='instance-type', ptype='string',
-                     doc="""Type of the instance."""),
-               Param(name='ip-address', ptype='string',
-                     doc='Public IP address of the instance.'),
-               Param(name='kernel-id', ptype='string',
-                     doc='Kernel ID.'),
-               Param(name='key-name', ptype='string',
-                     doc="""Name of the key pair used when the
-                     instance was launched."""),
-               Param(name='launch-index', ptype='string',
-                     doc="""When launching multiple instances at once,
-                     this is the index for the instance in the launch group"""),
-               Param(name='launch-time', ptype='string',
-                     doc='Time instance was launched'),
-               Param(name='monitoring-state', ptype='string',
-                     doc='Whether monitoring is enabled for the instance.'),
-               Param(name='owner-id', ptype='string',
-                     doc='AWS account ID of the image owner.'),
-               Param(name='placement-group-name', ptype='string',
-                     doc='Name of the placement group the instance is in'),
-               Param(name='platform', ptype='string',
-                     doc="""Use windows if you have Windows based AMIs;
-                     otherwise leave blank."""),
-               Param(name='private-dns-name', ptype='string',
-                     doc='Private DNS name of the instance.'),
-               Param(name='private-ip-address', ptype='string',
-                     doc='Private ip address of the instance.'),
-               Param(name='product-code', ptype='string',
-                     doc='Product code associated with the AMI.'),
-               Param(name='ramdisk-id', ptype='string',
-                     doc='The ramdisk ID.'),
-               Param(name='reason', ptype='string',
-                     doc="""Reason for the instance's current state."""),
-               Param(name='requestor-id', ptype='string',
-                     doc="""ID of the entity that launched the instance
-                     on your behalf."""),
-               Param(name='reservation-id', ptype='string',
-                     doc="""ID of the instance's reservation."""),
-               Param(name='root-device-name', ptype='string',
-                     doc='Root device name of the AMI (e.g., /dev/sda1).'),
-               Param(name='root-device-type', ptype='string',
-                     doc="""Root device type the AMI uses.
-                     Valid Values: ebs | instance-store."""),
-               Param(name='spot-instance-request-id', ptype='string',
-                     doc='ID of the Spot Instance request.'),
-               Param(name='state-reason-code', ptype='string',
-                     doc='Reason code for the state change.'),
-               Param(name='state-reason-message', ptype='string',
-                     doc='Message for the state change.'),
-               Param(name='subnet-id', ptype='string',
-                     doc='ID of the subnet the instance is in (VPC).'),
-               Param(name='tag-key', ptype='string',
-                     doc='Key of a tag assigned to the resource.'),
-               Param(name='tag-value', ptype='string',
-                     doc='Value of a tag assigned to the resource.'),
-               Param(name='tag:key', ptype='string',
-                     doc="""Filters the results based on a specific
-                     tag/value combination."""),
-               Param(name='virtualization-type', ptype='string',
-                     doc="""Virtualization type of the instance.
-                     Valid values: paravirtual | hvm"""),
-               Param(name='vpc-id', ptype='string',
-                     doc='ID of the VPC the instance is in.')]
-    
-    def display_reservations(self, reservations):
-        for reservation in reservations:
-            instances = []
-            instances = reservation.instances
-            if len(instances) == 0:
-                continue
-            reservation_string = '%s\t%s' % (reservation.id,
-                    reservation.owner_id)
-            group_delim = '\t'
-            for group in reservation.groups:
-                reservation_string += '%s%s' % (group_delim, group.id)
-                group_delim = ', '
-            print 'RESERVATION\t%s' % reservation_string
-            euca2ools.utils.print_instances(instances)
-
-    def main(self):
-        conn = self.make_connection_cli()
-        return self.make_request_cli(conn, 'get_all_instances',
-                                     instance_ids=self.instance)
-
-    def main_cli(self):
-        reservations = self.main()
-        self.display_reservations(reservations)
+    Description = 'Show information about instances'
+    Args = [Arg('InstanceId', metavar='INSTANCE', nargs='*',
+                help='Limit results to one or more instances')]
+    Filters = [Filter('architecture', help='CPU architecture'),
+               Filter('availability-zone'),
+               Filter('block-device-mapping.attach-time',
+                      help='volume attachment time'),
+               Filter('block-device-mapping.delete-on-termination', type=bool,
+                      help='''whether a volume is deleted upon instance
+                              termination'''),
+               Filter('block-device-mapping.device-name',
+                      help='volume device name (e.g. /dev/sdf)'),
+               Filter('block-device-mapping.status', help='volume status'),
+               Filter('block-device-mapping.volume-id', help='volume ID'),
+               Filter('client-token',
+                      help='idempotency token provided at instance run time'),
+               Filter('dns-name', help='public DNS name'),
+               Filter('group-id', help='security group membership'),
+               Filter('hypervisor', help='hypervisor type'),
+               Filter('image-id', help='machine image ID'),
+               Filter('instance-id'),
+               Filter('instance-lifecycle', choices=['spot'],
+                      help='whether this is a spot instance'),
+               Filter('instance-state-code', type=int,
+                      help='numeric code identifying instance state'),
+               Filter('instance-state-name', help='instance state'),
+               Filter('instance-type',),
+               Filter('ip-address', help='public IP address'),
+               Filter('kernel-id', help='kernel image ID'),
+               Filter('key-name',
+                      help='key pair name provided at instance launch time'),
+               Filter('launch-index', help='launch index within a reservation'),
+               Filter('launch-time', help='instance launch time'),
+               Filter('monitoring-state', help='whether monitoring is enabled'),
+               Filter('owner-id', help='instance owner\'s account ID'),
+               Filter('placement-group-name'),
+               Filter('platform', choices=['windows'],
+                      help='whether this is a Windows instance'),
+               Filter('private-dns-name'),
+               Filter('private-ip-address'),
+               Filter('product-code'),
+               Filter('ramdisk-id', help='ramdisk image ID'),
+               Filter('reason', help='reason for the more recent state change'),
+               Filter('requestor-id',
+                      help='ID of the entity that launched an instance'),
+               Filter('reservation-id'),
+               Filter('root-device-name',
+                      help='root device name (e.g. /dev/sda1)'),
+               Filter('root-device-type', choices=['ebs', 'instance-store'],
+                      help='root device type (ebs or instance-store)'),
+               Filter('spot-instance-request-id'),
+               Filter('state-reason-code',
+                      help='reason code for the most recent state change'),
+               Filter('state-reason-message',
+                      help='message for the most recent state change'),
+               Filter('subnet-id',
+                      help='ID of the VPC subnet the instance is in'),
+               Filter('tag-key',
+                      help='name of any tag assigned to the instance'),
+               Filter('tag-value',
+                      help='value of any tag assigned to the instance'),
+               Filter('tag:key', help='specific tag/value combination'),
+               Filter('virtualization-type', choices=['paravirtual', 'hvm']),
+               Filter('vpc-id', help='ID of the VPC the instance is in')]
+    ListMarkers = ['reservationSet', 'instancesSet', 'groupSet', 'tagSet',
+                   'blockDeviceMapping']
+    ItemMarkers = ['item']
 
+    def print_result(self, result):
+        for reservation in result.get('reservationSet'):
+            self.print_reservation(reservation)

-- 
managing cloud instances for Eucalyptus



More information about the pkg-eucalyptus-commits mailing list