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

« back to all changes in this revision

Viewing changes to .pc/describe-images-return-results-like-ec2-describe-images.patch/bin/euca-describe-images

  • 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
#!/usr/bin/python
 
2
# -*- coding: utf-8 -*-
 
3
 
 
4
# Software License Agreement (BSD License)
 
5
#
 
6
# Copyright (c) 2009, Eucalyptus Systems, Inc.
 
7
# All rights reserved.
 
8
#
 
9
# Redistribution and use of this software in source and binary forms, with or
 
10
# without modification, are permitted provided that the following conditions
 
11
# are met:
 
12
#
 
13
#   Redistributions of source code must retain the above
 
14
#   copyright notice, this list of conditions and the
 
15
#   following disclaimer.
 
16
#
 
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.
 
21
#
 
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.
 
33
#
 
34
# Author: Neil Soman neil@eucalyptus.com
 
35
 
 
36
import getopt
 
37
import sys
 
38
import os
 
39
from euca2ools import Euca2ool, Util, ConnectionFailed
 
40
 
 
41
usage_string = \
 
42
    """
 
43
Shows information about machine images.
 
44
 
 
45
euca-describe-images [-a] [-o owner] [-x user] [-h, --help] [--version] [--debug] [image1 image2 ... imageN]
 
46
 
 
47
OPTIONAL PARAMETERS
 
48
 
 
49
image1 image2 ... imageN        Images to describe.
 
50
 
 
51
-a                              Show all images that the user has access to.
 
52
 
 
53
-o                              Show only images owned by the owner specified are displayed.    
 
54
 
 
55
-x                              Show only images that the specified user is permitted to launch.
 
56
 
 
57
"""
 
58
 
 
59
 
 
60
def usage(status=1):
 
61
    print usage_string
 
62
    Util().usage(compat=True)
 
63
    sys.exit(status)
 
64
 
 
65
 
 
66
def version():
 
67
    print Util().version()
 
68
    sys.exit()
 
69
 
 
70
 
 
71
def display_images(images, image_ids):
 
72
    check_image_ids = False
 
73
    if len(image_ids) > 0:
 
74
        check_image_ids = True
 
75
    for image in images:
 
76
        if check_image_ids:
 
77
            if not image.id in image_ids:
 
78
                continue
 
79
        image_string = '%s\t%s\t%s\t%s' % (image.id, image.location,
 
80
                image.ownerId, image.state)
 
81
        if image.is_public:
 
82
            image_string += '\tpublic'
 
83
        else:
 
84
            image_string += '\tprivate'
 
85
 
 
86
        image_string += '\t%s' % ','.join(image.product_codes)
 
87
 
 
88
        for i in [image.architecture, image.type, image.kernel_id,
 
89
                  image.ramdisk_id]:
 
90
            image_string += '\t%s' % ((' ' if i == None else i))
 
91
 
 
92
        if image.platform:
 
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
 
105
 
 
106
 
 
107
def main():
 
108
    euca = None
 
109
    try:
 
110
        euca = Euca2ool('ao:x:', compat=True)
 
111
    except Exception, e:
 
112
        print e
 
113
        usage()
 
114
 
 
115
    show_all = False
 
116
    executable_by = ['self']
 
117
    owners = ['self']
 
118
    defaults = True
 
119
 
 
120
    for (name, value) in euca.opts:
 
121
        if name in ('-h', '--help'):
 
122
            usage(0)
 
123
        elif name == '-x':
 
124
            if defaults:
 
125
                executable_by = []
 
126
                defaults = False
 
127
                owners = []
 
128
            executable_by.append(value)
 
129
        elif name == '-o':
 
130
            if defaults:
 
131
                executable_by = []
 
132
                defaults = False
 
133
            owners.append(value)
 
134
        elif name == '-a':
 
135
            executable_by = ['self', 'all']
 
136
            owners = []
 
137
        elif name == '--version':
 
138
            version()
 
139
 
 
140
    image_ids = euca.process_args()
 
141
    if defaults and len(image_ids) > 0:
 
142
        executable_by = ['self', 'all']
 
143
        owners = []
 
144
 
 
145
    try:
 
146
        euca_conn = euca.make_connection()
 
147
    except ConnectionFailed, e:
 
148
        print e.message
 
149
        sys.exit(1)
 
150
 
 
151
    try:
 
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)
 
156
 
 
157
    display_images(images, image_ids)
 
158
 
 
159
 
 
160
if __name__ == '__main__':
 
161
    main()
 
162