mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Add an appliance templates directory
Fix https://github.com/GNS3/gns3-gui/issues/2133
This commit is contained in:
6 files changed
+54
-20
No files matched your search
@@ -66,13 +66,17 @@ class Controller:
|
||||
|
||||
def load_appliances(self):
|
||||
self._appliance_templates = {}
|
||||
for file in os.listdir(get_resource('appliances')):
|
||||
path = os.path.join(get_resource('appliances'), file)
|
||||
appliance_id = uuid.uuid3(uuid.NAMESPACE_URL, path) # Generate the UUID from path to avoid change between reboots
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
appliance = ApplianceTemplate(appliance_id, json.load(f))
|
||||
if appliance.status != 'broken':
|
||||
self._appliance_templates[appliance.id] = appliance
|
||||
for directory, builtin in (
|
||||
(get_resource('appliances'), True,), (self.appliances_path(), False,)
|
||||
):
|
||||
if os.path.isdir(directory):
|
||||
for file in os.listdir(directory):
|
||||
path = os.path.join(directory, file)
|
||||
appliance_id = uuid.uuid3(uuid.NAMESPACE_URL, path) # Generate the UUID from path to avoid change between reboots
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
appliance = ApplianceTemplate(appliance_id, json.load(f), builtin=builtin)
|
||||
if appliance.status != 'broken':
|
||||
self._appliance_templates[appliance.id] = appliance
|
||||
|
||||
self._appliances = {}
|
||||
vms = []
|
||||
@@ -304,6 +308,15 @@ class Controller:
|
||||
os.makedirs(images_path, exist_ok=True)
|
||||
return images_path
|
||||
|
||||
def appliances_path(self):
|
||||
"""
|
||||
Get the image storage directory
|
||||
"""
|
||||
server_config = Config.instance().get_section_config("Server")
|
||||
appliances_path = os.path.expanduser(server_config.get("appliances_path", "~/GNS3/projects"))
|
||||
os.makedirs(appliances_path, exist_ok=True)
|
||||
return appliances_path
|
||||
|
||||
@asyncio.coroutine
|
||||
def _import_gns3_gui_conf(self):
|
||||
"""
|
||||
|
||||
@@ -21,7 +21,7 @@ import uuid
|
||||
|
||||
class ApplianceTemplate:
|
||||
|
||||
def __init__(self, appliance_id, data):
|
||||
def __init__(self, appliance_id, data, builtin=True):
|
||||
if appliance_id is None:
|
||||
self._id = str(uuid.uuid4())
|
||||
elif isinstance(appliance_id, uuid.UUID):
|
||||
@@ -29,6 +29,7 @@ class ApplianceTemplate:
|
||||
else:
|
||||
self._id = appliance_id
|
||||
self._data = data.copy()
|
||||
self._builtin = builtin
|
||||
if "appliance_id" in self._data:
|
||||
del self._data["appliance_id"]
|
||||
|
||||
@@ -44,4 +45,6 @@ class ApplianceTemplate:
|
||||
"""
|
||||
Appliance data (a hash)
|
||||
"""
|
||||
return copy.deepcopy(self._data)
|
||||
data = copy.deepcopy(self._data)
|
||||
data["builtin"] = self._builtin
|
||||
return data
|
||||
Reference in new issue
Block a user