mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 09:18:08 +00:00
Create an ApplianceTemplate class
This commit is contained in:
parent
8d86d959de
commit
2a840da462
@ -16,7 +16,6 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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")
|
||||
|
38
gns3server/controller/appliance_template.py
Normal file
38
gns3server/controller/appliance_template.py
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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
|
@ -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()])
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user