diff --git a/gns3server/controller/__init__.py b/gns3server/controller/__init__.py
index 87a25aeb..7afe9c14 100644
--- a/gns3server/controller/__init__.py
+++ b/gns3server/controller/__init__.py
@@ -16,7 +16,6 @@
# along with this program. If not, see .
import os
-import sys
import json
import socket
import asyncio
@@ -25,6 +24,7 @@ import aiohttp
from ..config import Config
from .project import Project
from .appliance import Appliance
+from .appliance_template import ApplianceTemplate
from .compute import Compute, ComputeError
from .notification import Notification
from .symbols import Symbols
@@ -43,23 +43,27 @@ class Controller:
def __init__(self):
self._computes = {}
self._projects = {}
- self._appliances = {}
- self.load_appliances()
+
+ # Store settings shared by the different GUI will be replaced
+ # by dedicated API later
+ self._settings = {}
self._notification = Notification(self)
self.gns3vm = GNS3VM(self)
self.symbols = Symbols()
- # Store settings shared by the different GUI will be replace by dedicated API later
- self._settings = {}
self._config_file = os.path.join(Config.instance().config_dir, "gns3_controller.conf")
log.info("Load controller configuration file {}".format(self._config_file))
+ self._appliance_templates = {}
+ self.load_appliances()
+
def load_appliances(self):
+ self._appliance_templates = {}
for file in os.listdir(get_resource('appliances')):
with open(os.path.join(get_resource('appliances'), file)) as f:
- appliance = Appliance(None, json.load(f))
- self._appliances[appliance.id] = appliance
+ appliance = ApplianceTemplate(None, json.load(f))
+ self._appliance_templates[appliance.id] = appliance
@asyncio.coroutine
def start(self):
@@ -440,11 +444,11 @@ class Controller:
return self._projects
@property
- def appliances(self):
+ def appliance_templates(self):
"""
- :returns: The dictionary of appliances managed by GNS3
+ :returns: The dictionary of appliances templates managed by GNS3
"""
- return self._appliances
+ return self._appliance_templates
def projects_directory(self):
server_config = Config.instance().get_section_config("Server")
diff --git a/gns3server/controller/appliance_template.py b/gns3server/controller/appliance_template.py
new file mode 100644
index 00000000..ab89db63
--- /dev/null
+++ b/gns3server/controller/appliance_template.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2016 GNS3 Technologies Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+
+import uuid
+
+
+class ApplianceTemplate:
+
+ def __init__(self, appliance_id, data):
+ if appliance_id is None:
+ self._id = str(uuid.uuid4())
+ else:
+ self._id = appliance_id
+ self._data = data
+
+ @property
+ def id(self):
+ return self._id
+
+ def __json__(self):
+ """
+ Appliance data (a hash)
+ """
+ return self._data
diff --git a/gns3server/handlers/api/controller/appliance_handler.py b/gns3server/handlers/api/controller/appliance_handler.py
index 7e3b0c11..226ab8a7 100644
--- a/gns3server/handlers/api/controller/appliance_handler.py
+++ b/gns3server/handlers/api/controller/appliance_handler.py
@@ -34,4 +34,4 @@ class ApplianceHandler:
def list(request, response):
controller = Controller.instance()
- response.json([c for c in controller.appliances.values()])
+ response.json([c for c in controller.appliance_templates.values()])
diff --git a/tests/controller/test_controller.py b/tests/controller/test_controller.py
index 2f8a5f1f..e1e00e17 100644
--- a/tests/controller/test_controller.py
+++ b/tests/controller/test_controller.py
@@ -24,10 +24,7 @@ import aiohttp
from unittest.mock import MagicMock
from tests.utils import AsyncioMagicMock, asyncio_patch
-from gns3server.controller import Controller
from gns3server.controller.compute import Compute
-from gns3server.controller.project import Project
-from gns3server.config import Config
from gns3server.version import __version__
@@ -467,5 +464,5 @@ def test_get_free_project_name(controller, async_run):
assert controller.get_free_project_name("Hello") == "Hello"
-def test_appliances(controller):
- assert len(controller.appliances) > 0
+def test_appliance_templates(controller):
+ assert len(controller.appliance_templates) > 0