Merge "Allow joining existing networks when creating environment"

This commit is contained in:
Jenkins
2015-07-29 13:57:13 +00:00
committed by Gerrit Code Review
2 changed files with 53 additions and 1 deletions

View File

@@ -226,6 +226,29 @@ class ShellTest(base.TestCaseShell):
mock.call('1234'), mock.call('4321')])
self.assertEqual(2, self.client.packages.delete.call_count)
@mock.patch('muranoclient.v1.environments.EnvironmentManager')
def test_environment_create(self, mock_manager):
self.client.environments = mock_manager()
self.make_env()
self.shell('environment-create foo')
self.client.environments.create.assert_has_calls(
[mock.call({'name': 'foo'})])
self.client.environments.create.reset_mock()
self.shell('environment-create --join-net 123 foo')
cc = self.client.environments.create
expected_call = mock.call(
{'defaultNetworks':
{'environment':
{'internalNetworkName': '123',
'?':
{'type': 'io.murano.resources.ExistingNeutronNetwork',
'id': mock.ANY}},
'flat': None},
'name': 'foo',
})
self.assertEqual(cc.call_args, expected_call)
@mock.patch('muranoclient.v1.environments.EnvironmentManager')
def test_environment_list(self, mock_manager):
self.client.environments = mock_manager()

View File

@@ -15,6 +15,7 @@
import os
import shutil
import sys
import uuid
import zipfile
from muranoclient.common import exceptions as common_exceptions
@@ -36,11 +37,39 @@ def do_environment_list(mc, args={}):
utils.print_list(environments, fields, field_labels, sortby=0)
def _generate_join_existing_net(net, subnet):
res = {
'defaultNetworks': {
'environment': {
'?': {
'id': uuid.uuid4().hex,
'type': 'io.murano.resources.ExistingNeutronNetwork'
},
},
'flat': None
}
}
if net:
res['defaultNetworks']['environment']['internalNetworkName'] = net
if subnet:
res['defaultNetworks']['environment']['internalSubnetworkName'] = \
subnet
return res
@utils.arg("--join-net-id", metavar="<NET_ID>",
help="Network id to join",)
@utils.arg("--join-subnet-id", metavar="<SUBNET_ID>",
help="Subnetwork id to join",)
@utils.arg("name", metavar="<ENVIRONMENT_NAME>",
help="Environment name")
def do_environment_create(mc, args):
"""Create an environment."""
mc.environments.create({"name": args.name})
body = {"name": args.name}
if args.join_net_id or args.join_subnet_id:
body.update(_generate_join_existing_net(
args.join_net_id, args.join_subnet_id))
mc.environments.create(body)
do_environment_list(mc)