mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 22:11:14 +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):
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user