mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-12 19:38:57 +00:00
parent
d8317e8128
commit
68b7f81601
@ -135,21 +135,25 @@ class Controller:
|
||||
return Config.instance().get_section_config("Server").getboolean("controller")
|
||||
|
||||
@asyncio.coroutine
|
||||
def add_compute(self, **kwargs):
|
||||
def add_compute(self, compute_id=None, name=None, **kwargs):
|
||||
"""
|
||||
Add a server to the dictionary of compute servers controlled by this controller
|
||||
|
||||
:param compute_id: Compute server identifier
|
||||
:param name: Compute name
|
||||
:param kwargs: See the documentation of Compute
|
||||
"""
|
||||
compute_id = kwargs.pop("compute_id", None)
|
||||
if compute_id not in self._computes:
|
||||
|
||||
# We disallow to create from the outside the
|
||||
if compute_id == 'local':
|
||||
return None
|
||||
|
||||
compute = Compute(compute_id=compute_id, controller=self, **kwargs)
|
||||
for compute in self._computes.values():
|
||||
if name and compute.name == name:
|
||||
raise aiohttp.web.HTTPConflict(text="Compute name {} is duplicate".format(name))
|
||||
|
||||
compute = Compute(compute_id=compute_id, controller=self, name=name, **kwargs)
|
||||
self._computes[compute.id] = compute
|
||||
self.save()
|
||||
self.notification.emit("compute.created", compute.__json__())
|
||||
@ -200,14 +204,20 @@ class Controller:
|
||||
raise aiohttp.web.HTTPNotFound(text="Compute ID {} doesn't exist".format(compute_id))
|
||||
|
||||
@asyncio.coroutine
|
||||
def add_project(self, project_id=None, **kwargs):
|
||||
def add_project(self, project_id=None, name=None, **kwargs):
|
||||
"""
|
||||
Creates a project or returns an existing project
|
||||
|
||||
:param project_id: Project ID
|
||||
:param name: Project name
|
||||
:param kwargs: See the documentation of Project
|
||||
"""
|
||||
if project_id not in self._projects:
|
||||
project = Project(project_id=project_id, controller=self, **kwargs)
|
||||
|
||||
for project in self._projects.values():
|
||||
if name and project.name == name:
|
||||
raise aiohttp.web.HTTPConflict(text="Project name {} is duplicate".format(name))
|
||||
project = Project(project_id=project_id, controller=self, name=name, **kwargs)
|
||||
self._projects[project.id] = project
|
||||
return self._projects[project.id]
|
||||
return self._projects[project_id]
|
||||
|
@ -107,6 +107,14 @@ def test_addCompute(controller, controller_config_path, async_run):
|
||||
assert len(controller.computes) == 2
|
||||
|
||||
|
||||
def test_addDuplicateCompute(controller, controller_config_path, async_run):
|
||||
controller._notification = MagicMock()
|
||||
c = async_run(controller.add_compute(compute_id="test1", name="Test"))
|
||||
assert len(controller.computes) == 1
|
||||
with pytest.raises(aiohttp.web.HTTPConflict):
|
||||
async_run(controller.add_compute(compute_id="test2", name="Test"))
|
||||
|
||||
|
||||
def test_deleteCompute(controller, controller_config_path, async_run):
|
||||
c = async_run(controller.add_compute(compute_id="test1"))
|
||||
assert len(controller.computes) == 1
|
||||
@ -170,6 +178,16 @@ def test_addProject(controller, async_run):
|
||||
assert len(controller.projects) == 2
|
||||
|
||||
|
||||
def test_addDuplicateProject(controller, async_run):
|
||||
uuid1 = str(uuid.uuid4())
|
||||
uuid2 = str(uuid.uuid4())
|
||||
|
||||
async_run(controller.add_project(project_id=uuid1, name="Test"))
|
||||
assert len(controller.projects) == 1
|
||||
with pytest.raises(aiohttp.web.HTTPConflict):
|
||||
async_run(controller.add_project(project_id=uuid2, name="Test"))
|
||||
|
||||
|
||||
def test_remove_project(controller, async_run):
|
||||
uuid1 = str(uuid.uuid4())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user