1
# Software License Agreement (BSD License)
3
# Copyright (c) 20092011, Eucalyptus Systems, Inc.
6
# Redistribution and use of this software in source and binary forms, with or
7
# without modification, are permitted provided that the following conditions
10
# Redistributions of source code must retain the above
11
# copyright notice, this list of conditions and the
12
# following disclaimer.
14
# Redistributions in binary form must reproduce the above
15
# copyright notice, this list of conditions and the
16
# following disclaimer in the documentation and/or other
17
# materials provided with the distribution.
19
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
# POSSIBILITY OF SUCH DAMAGE.
31
# Author: Neil Soman neil@eucalyptus.com
32
# Mitch Garnaat mgarnaat@eucalyptus.com
34
import euca2ools.commands.eucacommand
35
from boto.roboto.param import Param
37
class ModifyImageAttribute(euca2ools.commands.eucacommand.EucaCommand):
39
Description = 'Show image attributes.'
40
Options = [Param(name='launchPermission', metavar='launch_permission',
41
short_name='l', long_name='launch-permission',
42
optional=True, ptype='boolean',
43
doc='show launch permissions.'),
44
Param(name='productCode', metavar='product_code',
45
short_name='p', long_name='product-code',
46
optional=True, ptype='string', cardinality='*',
47
doc='show the product codes associated with the image.'),
48
Param(name='add', short_name='a', long_name='add',
49
optional=True, ptype='string', cardinality='*',
50
doc='Entity (typically, user id) to add.'),
51
Param(name='remove', short_name='r', long_name='remove',
52
optional=True, ptype='string', cardinality='*',
53
doc='Entity (typically, user id) to remove.')]
54
Args = [Param(name='image_id', ptype='string',
55
doc="""unique identifier for the image that you want
56
to modify the attributes of.""",
57
cardinality=1, optional=False)]
59
def display_image_attribute(self, image_id, image_attribute):
60
if image_attribute.name == 'launch_permission':
61
if image_attribute.attrs.has_key('groups'):
62
for group in image_attribute.attrs['groups']:
63
print 'launchPermission\t%s\tgroup\t%s' \
64
% (image_attribute.image_id, group)
65
if image_attribute.attrs.has_key('user_ids'):
66
for userid in image_attribute.attrs['user_ids']:
67
print 'launchPermission\t%s\tuserId\t%s' \
68
% (image_attribute.image_id, userid)
69
if image_attribute.attrs.has_key('product_codes'):
70
for product_code in image_attribute.attrs['product_codes']:
71
print 'productCodes\t%s\tproductCode\t%s' \
72
% (image_attribute.image_id, product_code)
73
if image_attribute.kernel is not None:
74
print 'kernel\t%s\t\t%s' % (image_attribute.image_id,
75
getattr(image_attribute, 'value', ""))
76
if image_attribute.ramdisk is not None:
77
print 'ramdisk\t%s\t\t%s' % (image_attribute.image_id,
78
getattr(image_attribute, 'value', ""))
79
if image_attribute.attrs.has_key('block_device_mapping'):
80
block_device_mapping = \
81
image_attribute.attrs['block_device_mapping']
82
for dev_name in block_device_mapping:
83
print 'blockDeviceMapping\t%s\tblockDeviceMap\t%s: %s' \
84
% (image_id, dev_name,
85
block_device_mapping[dev_name])
90
image_attribute = None
91
operation_type = 'add'
93
image_attribute = 'productCodes'
94
if not image_attribute and self.launchPermission:
95
image_attribute = 'launchPermission'
96
if self.add and self.remove:
97
msg = 'You cannot add and remove in the same call'
98
self.display_error_and_exit(msg)
100
operation_type = 'add'
102
operation_type = 'remove'
103
users = self.add + self.remove
108
conn = self.make_connection_cli()
109
return self.make_request_cli(conn, 'modify_image_attribute',
110
image_id=self.image_id,
111
attribute=image_attribute,
112
operation=operation_type,
115
product_codes=self.productCode)
117
msg = 'No attributes were specified'
118
self.display_error_and_exit(msg)
122
print 'IMAGE\t%s' % self.image_id