1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 11:18:11 +00:00

Create the project on compute only when needed

This commit is contained in:
Julien Duponchelle 2016-05-11 10:56:43 +02:00
parent ed0bae8689
commit cd836f146e
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 19 additions and 6 deletions

View File

@ -60,6 +60,9 @@ class Project:
self._links = {}
self._listeners = set()
# Create the project on demand on the compute node
self._project_created_on_compute = set()
@property
def name(self):
return self._name
@ -103,7 +106,6 @@ class Project:
@asyncio.coroutine
def addCompute(self, compute):
self._computes.add(compute)
yield from compute.post("/projects", self)
@asyncio.coroutine
def addVM(self, compute, vm_id, **kwargs):
@ -114,6 +116,9 @@ class Project:
"""
if vm_id not in self._vms:
vm = VM(self, compute, vm_id=vm_id, **kwargs)
if compute not in self._project_created_on_compute:
yield from compute.post("/projects", self)
self._project_created_on_compute.add(compute)
yield from vm.create()
self._vms[vm.id] = vm
return vm

View File

@ -69,6 +69,13 @@ def test_captures_directory(tmpdir):
assert os.path.exists(p.captures_directory)
def test_addCompute(async_run):
compute = MagicMock()
project = Project()
async_run(project.addCompute(compute))
assert compute in project._computes
def test_addVM(async_run):
compute = MagicMock()
project = Project()
@ -79,11 +86,12 @@ def test_addVM(async_run):
vm = async_run(project.addVM(compute, None, name="test", vm_type="vpcs", properties={"startup_config": "test.cfg"}))
compute.post.assert_called_with('/projects/{}/vpcs/vms'.format(project.id),
data={'vm_id': vm.id,
'console_type': 'telnet',
'startup_config': 'test.cfg',
'name': 'test'})
compute.post.assert_any_call('/projects/{}/vpcs/vms'.format(project.id),
data={'vm_id': vm.id,
'console_type': 'telnet',
'startup_config': 'test.cfg',
'name': 'test'})
assert compute in project._project_created_on_compute
def test_getVM(async_run):