2
# -*- coding: utf-8 -*-
4
# Software License Agreement (BSD License)
6
# Copyright (c) 2009, Eucalyptus Systems, Inc.
9
# Redistribution and use of this software in source and binary forms, with or
10
# without modification, are permitted provided that the following conditions
13
# Redistributions of source code must retain the above
14
# copyright notice, this list of conditions and the
15
# following disclaimer.
17
# Redistributions in binary form must reproduce the above
18
# copyright notice, this list of conditions and the
19
# following disclaimer in the documentation and/or other
20
# materials provided with the distribution.
22
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
# POSSIBILITY OF SUCH DAMAGE.
34
# Author: Neil Soman neil@eucalyptus.com
39
from euca2ools import Euca2ool, Util, ConnectionFailed
43
Shows information about machine images.
45
euca-describe-images [-a] [-o owner] [-x user] [-h, --help] [--version] [--debug] [image1 image2 ... imageN]
49
image1 image2 ... imageN Images to describe.
51
-a Show all images that the user has access to.
53
-o Show only images owned by the owner specified are displayed.
55
-x Show only images that the specified user is permitted to launch.
62
Util().usage(compat=True)
67
print Util().version()
71
def display_images(images, image_ids):
72
check_image_ids = False
73
if len(image_ids) > 0:
74
check_image_ids = True
77
if not image.id in image_ids:
79
image_string = '%s\t%s\t%s\t%s' % (image.id, image.location,
80
image.ownerId, image.state)
82
image_string += '\tpublic'
84
image_string += '\tprivate'
86
image_string += '\t%s' % ','.join(image.product_codes)
88
for i in [image.architecture, image.type, image.kernel_id,
90
image_string += '\t%s' % ((' ' if i == None else i))
93
image_string += '\t%s' % image.platform
94
if image.root_device_type:
95
image_string += '\t%s' % image.root_device_type
96
print 'IMAGE\t%s' % image_string
97
if image.block_device_mapping:
98
block_dev_mapping = image.block_device_mapping
99
if image.root_device_type == 'ebs':
100
block_dev_string = '%s\t%s\t%s' \
101
% (block_dev_mapping.current_name,
102
block_dev_mapping.current_value.snapshot_id,
103
block_dev_mapping.current_value.size)
104
print 'BLOCKDEVICEMAPPING\t%s' % block_dev_string
110
euca = Euca2ool('ao:x:', compat=True)
116
executable_by = ['self']
120
for (name, value) in euca.opts:
121
if name in ('-h', '--help'):
128
executable_by.append(value)
135
executable_by = ['self', 'all']
137
elif name == '--version':
140
image_ids = euca.process_args()
141
if defaults and len(image_ids) > 0:
142
executable_by = ['self', 'all']
146
euca_conn = euca.make_connection()
147
except ConnectionFailed, e:
152
images = euca_conn.get_all_images(image_ids=image_ids,
153
owners=owners, executable_by=executable_by)
154
except Exception, ex:
155
euca.display_error_and_exit('%s' % ex)
157
display_images(images, image_ids)
160
if __name__ == '__main__':