mirror of
https://github.com/GNS3/gns3-server.git
synced 2025-02-07 08:43:48 +02:00
Create the project on compute only when needed
This commit is contained in:
parent
ed0bae8689
commit
cd836f146e
@ -60,6 +60,9 @@ class Project:
|
|||||||
self._links = {}
|
self._links = {}
|
||||||
self._listeners = set()
|
self._listeners = set()
|
||||||
|
|
||||||
|
# Create the project on demand on the compute node
|
||||||
|
self._project_created_on_compute = set()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
return self._name
|
return self._name
|
||||||
@ -103,7 +106,6 @@ class Project:
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def addCompute(self, compute):
|
def addCompute(self, compute):
|
||||||
self._computes.add(compute)
|
self._computes.add(compute)
|
||||||
yield from compute.post("/projects", self)
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def addVM(self, compute, vm_id, **kwargs):
|
def addVM(self, compute, vm_id, **kwargs):
|
||||||
@ -114,6 +116,9 @@ class Project:
|
|||||||
"""
|
"""
|
||||||
if vm_id not in self._vms:
|
if vm_id not in self._vms:
|
||||||
vm = VM(self, compute, vm_id=vm_id, **kwargs)
|
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()
|
yield from vm.create()
|
||||||
self._vms[vm.id] = vm
|
self._vms[vm.id] = vm
|
||||||
return vm
|
return vm
|
||||||
|
@ -69,6 +69,13 @@ def test_captures_directory(tmpdir):
|
|||||||
assert os.path.exists(p.captures_directory)
|
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):
|
def test_addVM(async_run):
|
||||||
compute = MagicMock()
|
compute = MagicMock()
|
||||||
project = Project()
|
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"}))
|
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),
|
compute.post.assert_any_call('/projects/{}/vpcs/vms'.format(project.id),
|
||||||
data={'vm_id': vm.id,
|
data={'vm_id': vm.id,
|
||||||
'console_type': 'telnet',
|
'console_type': 'telnet',
|
||||||
'startup_config': 'test.cfg',
|
'startup_config': 'test.cfg',
|
||||||
'name': 'test'})
|
'name': 'test'})
|
||||||
|
assert compute in project._project_created_on_compute
|
||||||
|
|
||||||
|
|
||||||
def test_getVM(async_run):
|
def test_getVM(async_run):
|
||||||
|
Loading…
Reference in New Issue
Block a user