Merge "Allow passing project_id to create_network"
This commit is contained in:
@@ -1703,7 +1703,7 @@ class OpenStackCloud(object):
|
||||
return True
|
||||
|
||||
def create_network(self, name, shared=False, admin_state_up=True,
|
||||
external=False, provider=None):
|
||||
external=False, provider=None, project_id=None):
|
||||
"""Create a network.
|
||||
|
||||
:param string name: Name of the network being created.
|
||||
@@ -1713,17 +1713,21 @@ class OpenStackCloud(object):
|
||||
:param dict provider: A dict of network provider options. Example::
|
||||
|
||||
{ 'network_type': 'vlan', 'segmentation_id': 'vlan1' }
|
||||
:param string project_id: Specify the project ID this network
|
||||
will be created on (admin-only).
|
||||
|
||||
:returns: The network object.
|
||||
:raises: OpenStackCloudException on operation error.
|
||||
"""
|
||||
|
||||
network = {
|
||||
'name': name,
|
||||
'shared': shared,
|
||||
'admin_state_up': admin_state_up,
|
||||
}
|
||||
|
||||
if project_id is not None:
|
||||
network['tenant_id'] = project_id
|
||||
|
||||
if provider:
|
||||
if not isinstance(provider, dict):
|
||||
raise OpenStackCloudException(
|
||||
|
||||
@@ -36,6 +36,20 @@ class TestNetwork(base.TestCase):
|
||||
)
|
||||
)
|
||||
|
||||
@mock.patch.object(shade.OpenStackCloud, 'neutron_client')
|
||||
def test_create_network_specific_tenant(self, mock_neutron):
|
||||
self.cloud.create_network("netname", project_id="project_id_value")
|
||||
mock_neutron.create_network.assert_called_with(
|
||||
body=dict(
|
||||
network=dict(
|
||||
name='netname',
|
||||
shared=False,
|
||||
admin_state_up=True,
|
||||
tenant_id="project_id_value",
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@mock.patch.object(shade.OpenStackCloud, 'neutron_client')
|
||||
def test_create_network_external(self, mock_neutron):
|
||||
self.cloud.create_network("netname", external=True)
|
||||
|
||||
Reference in New Issue
Block a user