[pkg-eucalyptus-commits] [SCM] managing cloud instances for Eucalyptus branch, master, updated. 3.0.0-alpha3-257-g1da8e3a
Garrett Holmstrom
gholms at fedoraproject.org
Sun Jun 16 02:29:53 UTC 2013
The following commit has been merged in the master branch:
commit ef06a622930a54ebc13e6c2e4ebdf2681ebec47b
Author: Garrett Holmstrom <gholms at fedoraproject.org>
Date: Fri May 4 00:03:03 2012 -0700
Rewrite DescribeSecurityGroups
diff --git a/bin/euca-describe-group b/bin/euca-describe-group
index 8fb03e4..b829c23 100755
--- a/bin/euca-describe-group
+++ b/bin/euca-describe-group
@@ -1,42 +1,6 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
+#!/usr/bin/python -tt
-# Software License Agreement (BSD License)
-#
-# Copyright (c) 2009-2011, Eucalyptus Systems, Inc.
-# All rights reserved.
-#
-# Redistribution and use of this software in source and binary forms, with or
-# without modification, are permitted provided that the following conditions
-# are met:
-#
-# Redistributions of source code must retain the above
-# copyright notice, this list of conditions and the
-# following disclaimer.
-#
-# Redistributions in binary form must reproduce the above
-# copyright notice, this list of conditions and the
-# following disclaimer in the documentation and/or other
-# materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-#
-# Author: Neil Soman neil at eucalyptus.com
-# Mitch Garnaat mgarnaat at eucalyptus.com
-
-import euca2ools.commands.euca.describegroups
+import euca2ools.commands.euca.describesecuritygroups
if __name__ == '__main__':
- cmd = euca2ools.commands.euca.describegroups.DescribeGroups()
- cmd.main_cli()
-
+ euca2ools.commands.euca.describesecuritygroups.DescribeSecurityGroups().do_cli()
diff --git a/euca2ools/commands/euca/describegroups.py b/euca2ools/commands/euca/describegroups.py
deleted file mode 100644
index 4f16c75..0000000
--- a/euca2ools/commands/euca/describegroups.py
+++ /dev/null
@@ -1,103 +0,0 @@
-# Software License Agreement (BSD License)
-#
-# Copyright (c) 2009-2011, Eucalyptus Systems, Inc.
-# All rights reserved.
-#
-# Redistribution and use of this software in source and binary forms, with or
-# without modification, are permitted provided that the following conditions
-# are met:
-#
-# Redistributions of source code must retain the above
-# copyright notice, this list of conditions and the
-# following disclaimer.
-#
-# Redistributions in binary form must reproduce the above
-# copyright notice, this list of conditions and the
-# following disclaimer in the documentation and/or other
-# materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-#
-# Author: Neil Soman neil at eucalyptus.com
-# Mitch Garnaat mgarnaat at eucalyptus.com
-
-import euca2ools.commands.eucacommand
-from boto.roboto.param import Param
-
-class DescribeGroups(euca2ools.commands.eucacommand.EucaCommand):
-
- APIVersion = '2011-01-01'
- Description = 'Shows information about groups.'
- Args = [Param(name='group_name', ptype='string',
- doc='group to describe',
- cardinality='+', optional=True)]
- Filters = [Param(name='description', ptype='string',
- doc='Description of the security group.'),
- Param(name='group-name', ptype='string',
- doc='Name of the security group.'),
- Param(name='ip-permission.cidr', ptype='string',
- doc='CIDR range that has been granted the permission.'),
- Param(name='ip-permission.from-port', ptype='string',
- doc="""Start of port range for the TCP and UDP protocols,
- or an ICMP type number. An ICMP type number of -1 indicates
- a wildcard (i.e., any ICMP type number)."""),
- Param(name='ip-permission.group-name', ptype='string',
- doc="""Name of security group that has been granted
- the permission."""),
- Param(name='ip-permission.protocol', ptype='string',
- doc="""IP protocol for the permission.
- Valid Values: tcp | udp | icmp"""),
- Param(name='ip-permission.to-port', ptype='string',
- doc="""End of port range for the TCP and UDP protocols,
- or an ICMP code. An ICMP type number of -1 indicates a
- wildcard (i.e., any ICMP type number)."""),
- Param(name='ip-permission.user-id', ptype='string',
- doc="""ID of AWS account that has been granted
- the permission."""),
- Param(name='owner-id', ptype='string',
- doc='AWS account ID of the owner of the security group.')]
-
- def display_groups(self, groups):
- for group in groups:
- if group.id:
- group_string = '%s\t%s\t%s\t%s' % (group.id, group.owner_id,
- group.name, group.description)
- else:
- group_string = '%s\t%s\t%s' % (group.owner_id,
- group.name, group.description)
- print 'GROUP\t%s' % group_string
- for rule in group.rules:
- permission_string = '%s\t%s\tALLOWS\t%s\t%s\t%s' \
- % (group.owner_id, group.name, rule.ip_protocol,
- rule.from_port, rule.to_port)
- for grant in rule.grants:
- grant_string = '\tFROM'
- if grant.owner_id or grant.name:
- if grant.owner_id:
- grant_string = '\tUSER\t%s' % grant.owner_id
- if grant.name:
- grant_string = '\tGRPNAME\t%s' % grant.name
- else:
- grant_string += '\tCIDR\t%s' % grant.cidr_ip
- permission_string += grant_string
- print 'PERMISSION\t%s' % permission_string
-
- def main(self):
- conn = self.make_connection_cli()
- return self.make_request_cli(conn, 'get_all_security_groups',
- groupnames=self.group_name)
-
- def main_cli(self):
- groups = self.main()
- self.display_groups(groups)
-
diff --git a/euca2ools/commands/euca/describesecuritygroups.py b/euca2ools/commands/euca/describesecuritygroups.py
new file mode 100644
index 0000000..51d41d6
--- /dev/null
+++ b/euca2ools/commands/euca/describesecuritygroups.py
@@ -0,0 +1,121 @@
+# Software License Agreement (BSD License)
+#
+# Copyright (c) 2009-2012, Eucalyptus Systems, Inc.
+# All rights reserved.
+#
+# Redistribution and use of this software in source and binary forms, with or
+# without modification, are permitted provided that the following conditions
+# are met:
+#
+# Redistributions of source code must retain the above
+# copyright notice, this list of conditions and the
+# following disclaimer.
+#
+# Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the
+# following disclaimer in the documentation and/or other
+# materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+from requestbuilder import Arg, Filter
+from . import EucalyptusRequest
+
+class DescribeSecurityGroups(EucalyptusRequest):
+ Description = '''\
+ Show information about security groups
+
+ Note that filters are matched on literal strings only, so
+ "--filter ip-permission.from-port=22" will *not* match a group with a
+ port range of 20 to 30.'''
+
+ APIVersion = '2011-01-01'
+ Args = [Arg('group', metavar='GROUP', nargs='*', route_to=None, default=[],
+ help='limit results to one or more security groups')]
+ Filters = [Filter('description', help='group description'),
+ Filter('group-id'),
+ Filter('group-name'),
+ Filter('ip-permission.cidr',
+ help='CIDR IP range granted permission by the group'),
+ Filter('ip-permission.from-port',
+ help='start of TCP/UDP port range, or ICMP type number'),
+ Filter('ip-permission.group-name', help='''name of another group
+ granted permission by this group'''),
+ Filter('ip-permission.protocol',
+ choices=('tcp', 'udp', 'icmp', '6', '17', '1'),
+ help='IP protocol for the permission'),
+ Filter('ip-permission.to-port',
+ help='end of TCP/UDP port range, or ICMP code'),
+ Filter('ip-permission.user-id',
+ help='ID of an account granted permission'),
+ Filter('owner-id', help=="account ID of the group's owner"),
+ Filter('tag-key', help='key of a tag assigned to the group'),
+ Filter('tag-value',
+ help='value of a tag assigned to the group')]
+ ListMarkers = ['securityGroupInfo', 'ipPermissions', 'ipPermissionsEgress',
+ 'groups', 'ipRanges']
+ ItemMarkers = ['item']
+
+ def main(self):
+ self.params = {}
+ for group in self.args['group']:
+ # Uncomment this during the next API version bump
+ #if group.startswith('sg-'):
+ # self.params.setdefault('GroupId', [])
+ # self.params['GroupId'].append(group)
+ #else:
+ self.params.setdefault('GroupName', [])
+ self.params['GroupName'].append(group)
+ return self.send()
+
+ def print_result(self, result):
+ for group in result.get('securityGroupInfo', []):
+ self.print_group(group)
+
+ def print_group(self, group):
+ print self.tabify(('GROUP', group.get('groupId'), group.get('ownerId'),
+ group.get('groupName'),
+ group.get('groupDescription')))
+ for perm in group.get('ipPermissions', []):
+ perm_base = ['PERMISSION', group.get('ownerId'),
+ group.get('groupName'), 'ALLOWS']
+ perm_base.extend([perm.get('ipProtocol'), perm.get('fromPort'),
+ perm.get('toPort')])
+ for cidr_range in perm.get('ipRanges', []):
+ perm_item = ['FROM', 'CIDR', cidr_range.get('cidrIp'),
+ 'ingress']
+ print self.tabify(perm_base + perm_item)
+ for othergroup in perm.get('groups', []):
+ perm_item = ['FROM', 'USER', othergroup.get('userId')]
+ if othergroup.get('groupId'):
+ perm_item.extend(['ID', othergroup['groupId']])
+ else:
+ perm_item.extend(['GRPNAME', othergroup['groupName']])
+ perm_item.append('ingress')
+ print self.tabify(perm_base + perm_item)
+ for perm in group.get('ipPermissionsEgress', []):
+ perm_base = ['PERMISSION', group.get('ownerId'),
+ group.get('groupName'), 'ALLOWS']
+ perm_base.extend([perm.get('ipProtocol'), perm.get('fromPort'),
+ perm.get('toPort')])
+ for cidr_range in perm.get('ipRanges', []):
+ perm_item = ['TO', 'CIDR', cidr_range.get('cidrIp'), 'egress']
+ print self.tabify(perm_base + perm_item)
+ for othergroup in perm.get('groups', []):
+ perm_item = ['TO', 'USER', othergroup.get('userId')]
+ if othergroup.get('groupId'):
+ perm_item.extend(['ID', othergroup['groupId']])
+ else:
+ perm_item.extend(['GRPNAME', othergroup['groupName']])
+ perm_item.append('egress')
+ print self.tabify(perm_base + perm_item)
--
managing cloud instances for Eucalyptus
More information about the pkg-eucalyptus-commits
mailing list