~ubuntu-branches/ubuntu/precise/euca2ools/precise-proposed

« back to all changes in this revision

Viewing changes to .pc/debian-changes-2.0.0~bzr464-0ubuntu1/euca2ools/commands/euca/modifyimageattribute.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott Moser
  • Date: 2011-08-15 11:16:29 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20110815111629-3u49jvtwabwozpb7
Tags: 2.0.0~bzr464-0ubuntu1
* new upstream snapshot of bzr revno 464. (LP: #826022)
* Note, previous upload was incorrectly named 'bzr451'.  It should have
  been named bzr461 as it was a snapshot of revision 461.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Software License Agreement (BSD License)
 
2
#
 
3
# Copyright (c) 20092011, Eucalyptus Systems, Inc.
 
4
# All rights reserved.
 
5
#
 
6
# Redistribution and use of this software in source and binary forms, with or
 
7
# without modification, are permitted provided that the following conditions
 
8
# are met:
 
9
#
 
10
#   Redistributions of source code must retain the above
 
11
#   copyright notice, this list of conditions and the
 
12
#   following disclaimer.
 
13
#
 
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.
 
18
#
 
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.
 
30
#
 
31
# Author: Neil Soman neil@eucalyptus.com
 
32
#         Mitch Garnaat mgarnaat@eucalyptus.com
 
33
 
 
34
import euca2ools.commands.eucacommand
 
35
from boto.roboto.param import Param
 
36
 
 
37
class ModifyImageAttribute(euca2ools.commands.eucacommand.EucaCommand):
 
38
 
 
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)]
 
58
    
 
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])
 
86
 
 
87
    def main(self):
 
88
        users = []
 
89
        groups = []
 
90
        image_attribute = None
 
91
        operation_type = 'add'
 
92
        if self.productCode:
 
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)
 
99
        if self.add:
 
100
            operation_type = 'add'
 
101
        if self.remove:
 
102
            operation_type = 'remove'
 
103
        users = self.add + self.remove
 
104
        if 'all' in users:
 
105
            users.remove('all')
 
106
            groups.append('all')
 
107
        if image_attribute:
 
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,
 
113
                                         user_ids=users,
 
114
                                         groups=groups,
 
115
                                         product_codes=self.productCode)
 
116
        else:
 
117
            msg = 'No attributes were specified'
 
118
            self.display_error_and_exit(msg)
 
119
 
 
120
    def main_cli(self):
 
121
        self.main()
 
122
        print 'IMAGE\t%s' % self.image_id
 
123