summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/source/command-objects/security-group-rule.rst7
-rw-r--r--openstackclient/network/v2/security_group_rule.py8
-rw-r--r--openstackclient/tests/unit/network/v2/fakes.py2
-rw-r--r--openstackclient/tests/unit/network/v2/test_security_group_rule.py31
-rw-r--r--releasenotes/notes/bp-neutron-client-descriptions-a80902b4295843cf.yaml3
5 files changed, 51 insertions, 0 deletions
diff --git a/doc/source/command-objects/security-group-rule.rst b/doc/source/command-objects/security-group-rule.rst
index 5284b2dc..69c9fabc 100644
--- a/doc/source/command-objects/security-group-rule.rst
+++ b/doc/source/command-objects/security-group-rule.rst
@@ -22,6 +22,7 @@ Create a new security group rule
[--ingress | --egress]
[--ethertype <ethertype>]
[--project <project> [--project-domain <project-domain>]]
+ [--description <description>]
<group>
.. option:: --src-ip <ip-address>
@@ -97,6 +98,12 @@ Create a new security group rule
*Network version 2 only*
+.. option:: --description <description>
+
+ Set security group rule description
+
+ *Network version 2 only*
+
.. describe:: <group>
Create rule in this security group (name or ID)
diff --git a/openstackclient/network/v2/security_group_rule.py b/openstackclient/network/v2/security_group_rule.py
index e3be44ec..0f3bad3d 100644
--- a/openstackclient/network/v2/security_group_rule.py
+++ b/openstackclient/network/v2/security_group_rule.py
@@ -110,6 +110,11 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne):
def update_parser_network(self, parser):
parser.add_argument(
+ '--description',
+ metavar='<description>',
+ help=_("Set security group rule description")
+ )
+ parser.add_argument(
'--dst-port',
metavar='<port-range>',
action=parseractions.RangeAction,
@@ -235,6 +240,9 @@ class CreateSecurityGroupRule(common.NetworkAndComputeShowOne):
attrs = {}
attrs['protocol'] = self._get_protocol(parsed_args)
+ if parsed_args.description is not None:
+ attrs['description'] = parsed_args.description
+
# NOTE(rtheis): A direction must be specified and ingress
# is the default.
if parsed_args.ingress or not parsed_args.egress:
diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py
index f1c72461..0846af15 100644
--- a/openstackclient/tests/unit/network/v2/fakes.py
+++ b/openstackclient/tests/unit/network/v2/fakes.py
@@ -952,6 +952,8 @@ class FakeSecurityGroupRule(object):
# Set default attributes.
security_group_rule_attrs = {
+ 'description': 'security-group-rule-description-' +
+ uuid.uuid4().hex,
'direction': 'ingress',
'ethertype': 'IPv4',
'id': 'security-group-rule-id-' + uuid.uuid4().hex,
diff --git a/openstackclient/tests/unit/network/v2/test_security_group_rule.py b/openstackclient/tests/unit/network/v2/test_security_group_rule.py
index 96d58e5c..401e042f 100644
--- a/openstackclient/tests/unit/network/v2/test_security_group_rule.py
+++ b/openstackclient/tests/unit/network/v2/test_security_group_rule.py
@@ -60,6 +60,7 @@ class TestCreateSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
network_fakes.FakeSecurityGroup.create_one_security_group()
expected_columns = (
+ 'description',
'direction',
'ethertype',
'id',
@@ -81,6 +82,7 @@ class TestCreateSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
self.network.create_security_group_rule = mock.Mock(
return_value=self._security_group_rule)
self.expected_data = (
+ self._security_group_rule.description,
self._security_group_rule.direction,
self._security_group_rule.ethertype,
self._security_group_rule.id,
@@ -452,6 +454,33 @@ class TestCreateSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
self.assertEqual(self.expected_columns, columns)
self.assertEqual(self.expected_data, data)
+ def test_create_with_description(self):
+ self._setup_security_group_rule({
+ 'description': 'Setting SGR',
+ })
+ arglist = [
+ '--description', self._security_group_rule.description,
+ self._security_group.id,
+ ]
+ verifylist = [
+ ('description', self._security_group_rule.description),
+ ('group', self._security_group.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = (self.cmd.take_action(parsed_args))
+
+ self.network.create_security_group_rule.assert_called_once_with(**{
+ 'description': self._security_group_rule.description,
+ 'direction': self._security_group_rule.direction,
+ 'ethertype': self._security_group_rule.ethertype,
+ 'protocol': self._security_group_rule.protocol,
+ 'remote_ip_prefix': self._security_group_rule.remote_ip_prefix,
+ 'security_group_id': self._security_group.id,
+ })
+ self.assertEqual(self.expected_columns, columns)
+ self.assertEqual(self.expected_data, data)
+
class TestCreateSecurityGroupRuleCompute(TestSecurityGroupRuleCompute):
@@ -1075,6 +1104,7 @@ class TestShowSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
network_fakes.FakeSecurityGroupRule.create_one_security_group_rule()
columns = (
+ 'description',
'direction',
'ethertype',
'id',
@@ -1088,6 +1118,7 @@ class TestShowSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
)
data = (
+ _security_group_rule.description,
_security_group_rule.direction,
_security_group_rule.ethertype,
_security_group_rule.id,
diff --git a/releasenotes/notes/bp-neutron-client-descriptions-a80902b4295843cf.yaml b/releasenotes/notes/bp-neutron-client-descriptions-a80902b4295843cf.yaml
index 83a00902..3135d0d7 100644
--- a/releasenotes/notes/bp-neutron-client-descriptions-a80902b4295843cf.yaml
+++ b/releasenotes/notes/bp-neutron-client-descriptions-a80902b4295843cf.yaml
@@ -7,3 +7,6 @@ features:
Add ``--description`` option to ``router set`` and
``router create`` commands.
[Blueprint :oscbp:`network-commands-options`]
+ |
+ Adds ``--description`` option to ``security group rule create``.
+ [Blueprint :oscbp:`network-commands-options`]