1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-01 04:38:12 +00:00

Save/restore appliances Etag.

This commit is contained in:
grossmj 2021-05-17 00:37:15 +09:30
parent f416d64042
commit eb0f8c6174
3 changed files with 27 additions and 7 deletions

View File

@ -67,6 +67,7 @@ router.include_router(
router.include_router( router.include_router(
gns3vm.router, gns3vm.router,
deprecated=True,
dependencies=[Depends(get_current_active_user)], dependencies=[Depends(get_current_active_user)],
prefix="/gns3vm", prefix="/gns3vm",
tags=["GNS3 VM"] tags=["GNS3 VM"]

View File

@ -25,7 +25,7 @@ router = APIRouter()
@router.get("") @router.get("")
async def get_appliances(update: Optional[bool] = None, symbol_theme: Optional[str] = "Classic") -> List[dict]: async def get_appliances(update: Optional[bool] = False, symbol_theme: Optional[str] = "Classic") -> List[dict]:
""" """
Return all appliances known by the controller. Return all appliances known by the controller.
""" """

View File

@ -203,7 +203,7 @@ class Controller:
if iou_config.iourc_path: if iou_config.iourc_path:
iourc_path = iou_config.iourc_path iourc_path = iou_config.iourc_path
else: else:
os.makedirs(os.path.dirname(server_config.secrets_dir), exist_ok=True) os.makedirs(server_config.secrets_dir, exist_ok=True)
iourc_path = os.path.join(server_config.secrets_dir, "gns3_iourc_license") iourc_path = os.path.join(server_config.secrets_dir, "gns3_iourc_license")
try: try:
@ -213,9 +213,17 @@ class Controller:
except OSError as e: except OSError as e:
log.error(f"Cannot write IOU license file '{iourc_path}': {e}") log.error(f"Cannot write IOU license file '{iourc_path}': {e}")
# if self._appliance_manager.appliances_etag: if self._appliance_manager.appliances_etag:
# config._config.set("Controller", "appliances_etag", self._appliance_manager.appliances_etag) etag_directory = os.path.dirname(Config.instance().server_config)
# config.write_config() os.makedirs(etag_directory, exist_ok=True)
etag_appliances_path = os.path.join(etag_directory, "gns3_appliances_etag")
try:
with open(etag_appliances_path, "w+") as f:
f.write(self._appliance_manager.appliances_etag)
log.info(f"etag appliances file '{etag_appliances_path}' saved")
except OSError as e:
log.error(f"Cannot write Etag appliance file '{etag_appliances_path}': {e}")
def _load_controller_settings(self): def _load_controller_settings(self):
""" """
@ -261,8 +269,19 @@ class Controller:
log.error(f"Cannot read IOU license file '{iourc_path}': {e}") log.error(f"Cannot read IOU license file '{iourc_path}': {e}")
self._iou_license_settings["license_check"] = iou_config.license_check self._iou_license_settings["license_check"] = iou_config.license_check
# self._appliance_manager.appliances_etag = controller_config.get("appliances_etag", None)
# self._appliance_manager.load_appliances() etag_directory = os.path.dirname(Config.instance().server_config)
etag_appliances_path = os.path.join(etag_directory, "gns3_appliances_etag")
self._appliance_manager.appliances_etag = None
if os.path.exists(etag_appliances_path):
try:
with open(etag_appliances_path) as f:
self._appliance_manager.appliances_etag = f.read()
log.info(f"etag appliances file '{etag_appliances_path}' loaded")
except OSError as e:
log.error(f"Cannot read Etag appliance file '{etag_appliances_path}': {e}")
self._appliance_manager.load_appliances()
self._config_loaded = True self._config_loaded = True
async def load_projects(self): async def load_projects(self):