~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/describegroups.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) 2009-2011, 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 DescribeGroups(euca2ools.commands.eucacommand.EucaCommand):
 
38
 
 
39
    APIVersion = '2010-08-31'
 
40
    Description = 'Shows information about groups.'
 
41
    Args = [Param(name='group_name', ptype='string',
 
42
                  doc='group to describe',
 
43
                  cardinality='+', optional=True)]
 
44
    Filters = [Param(name='description', ptype='string',
 
45
                     doc='Description of the security group.'),
 
46
               Param(name='group-name', ptype='string',
 
47
                     doc='Name of the security group.'),
 
48
               Param(name='ip-permission.cidr', ptype='string',
 
49
                     doc='CIDR range that has been granted the permission.'),
 
50
               Param(name='ip-permission.from-port', ptype='string',
 
51
                     doc="""Start of port range for the TCP and UDP protocols,
 
52
                     or an ICMP type number. An ICMP type number of -1 indicates
 
53
                     a wildcard (i.e., any ICMP type number)."""),
 
54
               Param(name='ip-permission.group-name', ptype='string',
 
55
                     doc="""Name of security group that has been granted
 
56
                     the permission."""),
 
57
               Param(name='ip-permission.protocol', ptype='string',
 
58
                     doc="""IP protocol for the permission.
 
59
                     Valid Values: tcp | udp | icmp"""),
 
60
               Param(name='ip-permission.to-port', ptype='string',
 
61
                     doc="""End of port range for the TCP and UDP protocols,
 
62
                     or an ICMP code. An ICMP type number of -1 indicates a
 
63
                     wildcard (i.e., any ICMP type number)."""),
 
64
               Param(name='ip-permission.user-id', ptype='string',
 
65
                     doc="""ID of AWS account that has been granted
 
66
                     the permission."""),
 
67
               Param(name='owner-id', ptype='string',
 
68
                     doc='AWS account ID of the owner of the security group.')]
 
69
    
 
70
    def display_groups(self, groups):
 
71
        for group in groups:
 
72
            group_string = '%s\t%s\t%s' % (group.owner_id, group.name,
 
73
                    group.description)
 
74
            print 'GROUP\t%s' % group_string
 
75
            for rule in group.rules:
 
76
                permission_string = '%s\t%s\tALLOWS\t%s\t%s\t%s' \
 
77
                    % (group.owner_id, group.name, rule.ip_protocol,
 
78
                       rule.from_port, rule.to_port)
 
79
                for grant in rule.grants:
 
80
                    grant_string = '\tFROM'
 
81
                    if grant.owner_id or grant.name:
 
82
                        if grant.owner_id:
 
83
                            grant_string = '\tUSER\t%s' % grant.owner_id
 
84
                        if grant.name:
 
85
                            grant_string = '\tGRPNAME\t%s' % grant.name
 
86
                    else:
 
87
                        grant_string += '\tCIDR\t%s' % grant.cidr_ip
 
88
                    permission_string += grant_string
 
89
                    print 'PERMISSION\t%s' % permission_string
 
90
                    
 
91
    def main(self):
 
92
        conn = self.make_connection_cli()
 
93
        return self.make_request_cli(conn, 'get_all_security_groups',
 
94
                                     groupnames=self.group_name)
 
95
 
 
96
    def main_cli(self):
 
97
        groups = self.main()
 
98
        self.display_groups(groups)
 
99