diff --git a/doc/source/user/proxies/network.rst b/doc/source/user/proxies/network.rst index a9af0b922..3662d8fcc 100644 --- a/doc/source/user/proxies/network.rst +++ b/doc/source/user/proxies/network.rst @@ -124,6 +124,7 @@ Security Group Operations .. automethod:: openstack.network.v2._proxy.Proxy.security_groups .. automethod:: openstack.network.v2._proxy.Proxy.create_security_group_rule + .. automethod:: openstack.network.v2._proxy.Proxy.create_security_group_rules .. automethod:: openstack.network.v2._proxy.Proxy.delete_security_group_rule Availability Zone Operations diff --git a/openstack/network/v2/_proxy.py b/openstack/network/v2/_proxy.py index caf7842c7..68834a61c 100644 --- a/openstack/network/v2/_proxy.py +++ b/openstack/network/v2/_proxy.py @@ -3190,6 +3190,21 @@ class Proxy(proxy.Proxy): """ return self._create(_security_group_rule.SecurityGroupRule, **attrs) + def create_security_group_rules(self, data): + """Create new security group rules from the list of attributes + + :param list data: List of dicts of attributes which will be used to + create a :class:`~openstack.network.v2.\ + security_group_rule.SecurityGroupRule`, + comprised of the properties on the SecurityGroupRule + class. + + :returns: A generator of security group rule objects + :rtype: :class:`~openstack.network.v2.security_group_rule.\ + SecurityGroupRule` + """ + return self._bulk_create(_security_group_rule.SecurityGroupRule, data) + def delete_security_group_rule(self, security_group_rule, ignore_missing=True, if_revision=None): """Delete a security group rule diff --git a/openstack/tests/unit/network/v2/test_proxy.py b/openstack/tests/unit/network/v2/test_proxy.py index b5a5bc102..7678f4317 100644 --- a/openstack/tests/unit/network/v2/test_proxy.py +++ b/openstack/tests/unit/network/v2/test_proxy.py @@ -1163,6 +1163,14 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase): self.verify_list(self.proxy.security_group_rules, security_group_rule.SecurityGroupRule) + @mock.patch('openstack.network.v2._proxy.Proxy._bulk_create') + def test_security_group_rules_create(self, bc): + data = mock.sentinel + + self.proxy.create_security_group_rules(data) + + bc.assert_called_once_with(security_group_rule.SecurityGroupRule, data) + def test_segment_create_attrs(self): self.verify_create(self.proxy.create_segment, segment.Segment) diff --git a/releasenotes/notes/add-sg-rules-bulk-f36a3e2326d74867.yaml b/releasenotes/notes/add-sg-rules-bulk-f36a3e2326d74867.yaml new file mode 100644 index 000000000..4776d3366 --- /dev/null +++ b/releasenotes/notes/add-sg-rules-bulk-f36a3e2326d74867.yaml @@ -0,0 +1,5 @@ +--- +features: + - Added bulk create securtiy groups rules. With new proxy method + `create_security_group_rules` now it's possible to create multiple rules + for certain security group.