Add bulk creation of rules for Security Group.

With new method _bulk_create in OpenStackSDK, now it is possible to use
it for API methods, which supports creating multiple instances in single
call. Neutron supports couple of resources to be created at once. In
this change we propose to add multiple rules creation for a single
security group.

Change-Id: I5855a6faa706adeaf738a797af0048985bffe65f
This commit is contained in:
Roman Dobosz 2020-03-20 13:04:42 +01:00
parent 60a24f6c47
commit 9e58f9d77d
4 changed files with 29 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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.