Merge branch 'master' into 3.0

# Conflicts:
#	dev-requirements.txt
#	gns3server/controller/__init__.py
#	gns3server/controller/appliance_manager.py
#	gns3server/controller/compute.py
#	gns3server/controller/topology.py
#	gns3server/handlers/api/compute/ethernet_switch_handler.py
#	gns3server/handlers/api/controller/link_handler.py
#	gns3server/handlers/api/controller/symbol_handler.py
#	gns3server/version.py
#	requirements.txt
#	tests/controller/test_export_project.py
#	tests/handlers/api/compute/test_qemu.py
#	tests/web/test_response.py
#	win-requirements.txt
This commit is contained in:
grossmj committed 2021-04-10 12:46:40 +09:30
commit 802959f9ab
41 files changed
+697 -74

No files matched your search

@@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import shutil
import json
import uuid
import asyncio
@@ -181,6 +182,7 @@ class ApplianceManager:
Controller.instance().save()
json_data = await response.json()
appliances_dir = get_resource('appliances')
downloaded_appliance_files = []
for appliance in json_data:
if appliance["type"] == "file":
appliance_name = appliance["name"]
@@ -201,6 +203,21 @@ class ApplianceManager:
f.write(appliance_data)
except OSError as e:
raise ControllerError("Could not write appliance file '{}': {}".format(path, e))
downloaded_appliance_files.append(appliance_name)
# delete old appliance files
for filename in os.listdir(appliances_dir):
file_path = os.path.join(appliances_dir, filename)
if filename in downloaded_appliance_files:
continue
try:
if os.path.isfile(file_path) or os.path.islink(file_path):
log.info("Deleting old appliance file {}".format(file_path))
os.unlink(file_path)
except OSError as e:
log.warning("Could not delete old appliance file '{}': {}".format(file_path, e))
continue
except ValueError as e:
raise ControllerError("Could not read appliances information from GitHub: {}".format(e))
+23 -18
View File
@@ -67,22 +67,26 @@ async def export_project(zstream, project, temporary_dir, include_images=False,
# Export the local files
for root, dirs, files in os.walk(project._path, topdown=True, followlinks=False):
files = [f for f in files if _is_exportable(os.path.join(root, f), include_snapshots)]
for file in files:
path = os.path.join(root, file)
# check if we can export the file
try:
open(path).close()
except OSError as e:
msg = "Could not export file {}: {}".format(path, e)
log.warning(msg)
project.emit_notification("log.warning", {"message": msg})
continue
# ignore the .gns3 file
if file.endswith(".gns3"):
continue
_patch_mtime(path)
zstream.write(path, os.path.relpath(path, project._path))
try:
files = [f for f in files if _is_exportable(os.path.join(root, f), include_snapshots)]
for file in files:
path = os.path.join(root, file)
# check if we can export the file
try:
open(path).close()
except OSError as e:
msg = "Could not export file {}: {}".format(path, e)
log.warning(msg)
project.emit_notification("log.warning", {"message": msg})
continue
# ignore the .gns3 file
if file.endswith(".gns3"):
continue
_patch_mtime(path)
zstream.write(path, os.path.relpath(path, project._path))
except FileNotFoundError as e:
log.warning("Cannot export local file: {}".format(e))
continue
# Export files from remote computes
for compute in project.computes:
@@ -92,8 +96,9 @@ async def export_project(zstream, project, temporary_dir, include_images=False,
if _is_exportable(compute_file["path"], include_snapshots):
log.debug("Downloading file '{}' from compute '{}'".format(compute_file["path"], compute.id))
response = await compute.download_file(project, compute_file["path"])
#if response.status != 200:
# raise aiohttp.web.HTTPConflict(text="Cannot export file from compute '{}'. Compute returned status code {}.".format(compute.id, response.status))
if response.status != 200:
log.warning("Cannot export file from compute '{}'. Compute returned status code {}.".format(compute.id, response.status))
continue
(fd, temp_path) = tempfile.mkstemp(dir=temporary_dir)
async with aiofiles.open(fd, 'wb') as f:
while True: