mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Generate an uuid for compute node if None is provided
This commit is contained in:
5 files changed
+51
-18
No files matched your search
@@ -85,8 +85,7 @@ class Controller:
|
||||
log.critical("Cannot load %s: %s", self._config_file, str(e))
|
||||
return
|
||||
for c in data["computes"]:
|
||||
compute_id = c.pop("compute_id")
|
||||
yield from self.add_compute(compute_id, **c)
|
||||
yield from self.add_compute(**c)
|
||||
|
||||
def is_enabled(self):
|
||||
"""
|
||||
@@ -96,26 +95,28 @@ class Controller:
|
||||
return Config.instance().get_section_config("Server").getboolean("controller")
|
||||
|
||||
@asyncio.coroutine
|
||||
def add_compute(self, compute_id, **kwargs):
|
||||
def add_compute(self, **kwargs):
|
||||
"""
|
||||
Add a server to the dictionary of compute servers controlled by this controller
|
||||
|
||||
:param compute_id: Compute server identifier
|
||||
: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_server = Compute(compute_id=compute_id, controller=self, **kwargs)
|
||||
self._computes[compute_id] = compute_server
|
||||
compute = Compute(compute_id=compute_id, controller=self, **kwargs)
|
||||
self._computes[compute.id] = compute
|
||||
self.save()
|
||||
self.notification.emit("compute.created", compute_server.__json__())
|
||||
self.notification.emit("compute.created", compute.__json__())
|
||||
return compute
|
||||
else:
|
||||
self.notification.emit("compute.updated", self._computes[compute_id].__json__())
|
||||
return self._computes[compute_id]
|
||||
return self._computes[compute_id]
|
||||
|
||||
@asyncio.coroutine
|
||||
def delete_compute(self, compute_id):
|
||||
@@ -125,6 +126,7 @@ class Controller:
|
||||
"""
|
||||
compute = self.get_compute(compute_id)
|
||||
del self._computes[compute_id]
|
||||
self.save()
|
||||
self.notification.emit("compute.deleted", compute.__json__())
|
||||
|
||||
@property
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
import aiohttp
|
||||
import asyncio
|
||||
import json
|
||||
import uuid
|
||||
|
||||
from ..utils import parse_version
|
||||
from ..controller.controller_error import ControllerError
|
||||
@@ -38,10 +39,15 @@ class Compute:
|
||||
A GNS3 compute.
|
||||
"""
|
||||
|
||||
def __init__(self, compute_id, controller=None, protocol="http", host="localhost", port=8000, user=None, password=None, name=None):
|
||||
def __init__(self, compute_id, controller=None, protocol="http", host="localhost", port=3080, user=None, password=None, name=None):
|
||||
assert controller is not None
|
||||
log.info("Create compute %s", compute_id)
|
||||
self._id = compute_id
|
||||
|
||||
if compute_id is None:
|
||||
self._id = str(uuid.uuid4())
|
||||
else:
|
||||
self._id = compute_id
|
||||
|
||||
self.protocol = protocol
|
||||
self.host = host
|
||||
self.port = port
|
||||
|
||||
Reference in new issue
Block a user