summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorRichard Theis <rtheis@us.ibm.com>2016-03-17 12:58:44 -0500
committerRichard Theis <rtheis@us.ibm.com>2016-03-23 10:05:08 -0500
commit2109bce85a40da3e3cbebed1cac661611564ccb2 (patch)
tree51ebcd04762d11cc82714ef71f9e91104b0ec923 /openstackclient
parentd90650796217fbb9cdd19297ee6ff59f0e009413 (diff)
downloadpython-openstackclient-2109bce85a40da3e3cbebed1cac661611564ccb2.tar.gz
Support security group name for --src-group
Support security group name for the "--src-group" option on the "os security group rule create" command. Change-Id: Ic23d0671dad77566269c9a588644c8d774368733 Closes-Bug: #1540656
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/network/v2/security_group_rule.py12
-rw-r--r--openstackclient/tests/network/v2/test_security_group_rule.py10
2 files changed, 15 insertions, 7 deletions
diff --git a/openstackclient/network/v2/security_group_rule.py b/openstackclient/network/v2/security_group_rule.py
index e0244654..f60995ab 100644
--- a/openstackclient/network/v2/security_group_rule.py
+++ b/openstackclient/network/v2/security_group_rule.py
@@ -69,7 +69,7 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne):
source_group.add_argument(
"--src-group",
metavar="<group>",
- help="Source security group (ID only)",
+ help="Source security group (name or ID)",
)
parser.add_argument(
"--dst-port",
@@ -103,7 +103,10 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne):
attrs['port_range_max'] = parsed_args.dst_port[1]
attrs['protocol'] = parsed_args.proto
if parsed_args.src_group is not None:
- attrs['remote_group_id'] = parsed_args.src_group
+ attrs['remote_group_id'] = client.find_security_group(
+ parsed_args.src_group,
+ ignore_missing=False
+ ).id
else:
attrs['remote_ip_prefix'] = parsed_args.src_ip
attrs['security_group_id'] = security_group_id
@@ -123,6 +126,11 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne):
from_port, to_port = -1, -1
else:
from_port, to_port = parsed_args.dst_port
+ if parsed_args.src_group is not None:
+ parsed_args.src_group = utils.find_resource(
+ client.security_groups,
+ parsed_args.src_group,
+ ).id
obj = client.security_group_rules.create(
group.id,
parsed_args.proto,
diff --git a/openstackclient/tests/network/v2/test_security_group_rule.py b/openstackclient/tests/network/v2/test_security_group_rule.py
index a0d6185c..81b9e18b 100644
--- a/openstackclient/tests/network/v2/test_security_group_rule.py
+++ b/openstackclient/tests/network/v2/test_security_group_rule.py
@@ -149,13 +149,13 @@ class TestCreateSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
})
arglist = [
'--dst-port', str(self._security_group_rule.port_range_min),
- '--src-group', self._security_group.id,
+ '--src-group', self._security_group.name,
self._security_group.id,
]
verifylist = [
('dst_port', (self._security_group_rule.port_range_min,
self._security_group_rule.port_range_max)),
- ('src_group', self._security_group.id),
+ ('src_group', self._security_group.name),
('group', self._security_group.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -289,17 +289,17 @@ class TestCreateSecurityGroupRuleCompute(TestSecurityGroupRuleCompute):
expected_columns, expected_data = self._setup_security_group_rule({
'from_port': 22,
'to_port': 22,
- 'group': {'name': self._security_group.id},
+ 'group': {'name': self._security_group.name},
})
arglist = [
'--dst-port', str(self._security_group_rule.from_port),
- '--src-group', self._security_group.id,
+ '--src-group', self._security_group.name,
self._security_group.id,
]
verifylist = [
('dst_port', (self._security_group_rule.from_port,
self._security_group_rule.to_port)),
- ('src_group', self._security_group.id),
+ ('src_group', self._security_group.name),
('group', self._security_group.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)