summaryrefslogtreecommitdiff
path: root/openstackclient/compute
diff options
context:
space:
mode:
authorRichard Theis <rtheis@us.ibm.com>2015-12-16 16:01:40 -0600
committerRichard Theis <rtheis@us.ibm.com>2015-12-17 12:49:13 -0600
commit96cc5eb3540e4753a8862020b2f6e78a465be4e2 (patch)
tree5e20fc77844aacb0c251b9e9b646793b810a9c07 /openstackclient/compute
parentd72f6228cf0823f4a13df9da84455e1d6c242c76 (diff)
downloadpython-openstackclient-96cc5eb3540e4753a8862020b2f6e78a465be4e2.tar.gz
Add support to list all security group rules
Both nova and neutron allow security group rules to be listed without specifying the owning security group. This patch set makes the group argument on 'os security group rule list' optional. Behavior is unchanged when the argument is specified. When the argument is not specified then all accessible security group rules will be listed. The listing will include the owning security group for each rule. Change-Id: I6914baecf70a65354e1e82dad92c6afbd32b4973 Related-Bug: #1519512
Diffstat (limited to 'openstackclient/compute')
-rw-r--r--openstackclient/compute/v2/security_group.py32
1 files changed, 21 insertions, 11 deletions
diff --git a/openstackclient/compute/v2/security_group.py b/openstackclient/compute/v2/security_group.py
index a514085b..42581d55 100644
--- a/openstackclient/compute/v2/security_group.py
+++ b/openstackclient/compute/v2/security_group.py
@@ -278,6 +278,7 @@ class ListSecurityGroupRule(lister.Lister):
parser.add_argument(
'group',
metavar='<group>',
+ nargs='?',
help='List all rules in this security group (name or ID)',
)
return parser
@@ -286,26 +287,35 @@ class ListSecurityGroupRule(lister.Lister):
self.log.debug("take_action(%s)", parsed_args)
compute_client = self.app.client_manager.compute
- group = utils.find_resource(
- compute_client.security_groups,
- parsed_args.group,
+ columns = column_headers = (
+ "ID",
+ "IP Protocol",
+ "IP Range",
+ "Port Range",
+ "Remote Security Group",
)
+ rules_to_list = []
+ if parsed_args.group:
+ group = utils.find_resource(
+ compute_client.security_groups,
+ parsed_args.group,
+ )
+ rules_to_list = group.rules
+ else:
+ columns = columns + ('parent_group_id',)
+ column_headers = column_headers + ('Security Group',)
+ for group in compute_client.security_groups.list():
+ rules_to_list.extend(group.rules)
+
# Argh, the rules are not Resources...
rules = []
- for rule in group.rules:
+ for rule in rules_to_list:
rules.append(security_group_rules.SecurityGroupRule(
compute_client.security_group_rules,
_xform_security_group_rule(rule),
))
- columns = column_headers = (
- "ID",
- "IP Protocol",
- "IP Range",
- "Port Range",
- "Remote Security Group",
- )
return (column_headers,
(utils.get_item_properties(
s, columns,