Skip to content

Commit

Permalink
Store IOU licence in the secrets directory and disable the check by d…
Browse files Browse the repository at this point in the history
…efault
  • Loading branch information
grossmj committed Dec 17, 2024
1 parent 5e1b881 commit 014d3f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 26 deletions.
27 changes: 11 additions & 16 deletions gns3server/controller/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self):
self.gns3vm = GNS3VM(self)
self.symbols = Symbols()
self._appliance_manager = ApplianceManager()
self._iou_license_settings = {"iourc_content": "", "license_check": True}
self._iou_license_settings = {"iourc_content": "", "license_check": False}
self._vars_loaded = False
self._vars_file = Config.instance().controller_vars
log.info(f'Loading controller vars file "{self._vars_file}"')
Expand Down Expand Up @@ -208,19 +208,15 @@ def save(self):
if self._vars_loaded:
controller_vars = {
"appliances_etag": self._appliance_manager.appliances_etag,
"iou_license_check": self._iou_license_settings["license_check"],
"version": __version__
}

if self._iou_license_settings["iourc_content"]:

iou_config = Config.instance().settings.IOU
server_config = Config.instance().settings.Server

if iou_config.iourc_path:
iourc_path = iou_config.iourc_path
else:
os.makedirs(server_config.secrets_dir, exist_ok=True)
iourc_path = os.path.join(server_config.secrets_dir, "gns3_iourc_license")
os.makedirs(server_config.secrets_dir, exist_ok=True)
iourc_path = os.path.join(server_config.secrets_dir, "iou_license")

try:
with open(iourc_path, "w+") as f:
Expand Down Expand Up @@ -251,15 +247,11 @@ def _load_controller_vars(self):
return []

# load the IOU license settings
iou_config = Config.instance().settings.IOU
server_config = Config.instance().settings.Server

if iou_config.iourc_path:
iourc_path = iou_config.iourc_path
else:
if not server_config.secrets_dir:
server_config.secrets_dir = os.path.dirname(Config.instance().server_config)
iourc_path = os.path.join(server_config.secrets_dir, "gns3_iourc_license")
if not server_config.secrets_dir:
server_config.secrets_dir = os.path.dirname(Config.instance().server_config)
iourc_path = os.path.join(server_config.secrets_dir, "iou_license")

if os.path.exists(iourc_path):
try:
Expand All @@ -268,7 +260,10 @@ def _load_controller_vars(self):
log.info(f"iourc file '{iourc_path}' loaded")
except OSError as e:
log.error(f"Cannot read IOU license file '{iourc_path}': {e}")
self._iou_license_settings["license_check"] = iou_config.license_check

# IOU license check is disabled by default
self._iou_license_settings["license_check"] = controller_vars.get("iou_license_check", False)
log.info("IOU license check is {} on the controller".format("enabled" if self._iou_license_settings["license_check"] else "disabled"))

# install the built-in appliances if needed
if Config.instance().settings.Server.install_builtin_appliances:
Expand Down
16 changes: 6 additions & 10 deletions gns3server/controller/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,17 +572,13 @@ async def start(self, data=None):
Start a node
"""
try:
# For IOU we need to send the licence everytime
# For IOU we need to send the licence everytime (if enabled)
if self.node_type == "iou":
license_check = self._project.controller.iou_license.get("license_check", True)
iourc_content = self._project.controller.iou_license.get("iourc_content", None)
# if license_check and not iourc_content:
# raise aiohttp.web.HTTPConflict(text="IOU licence is not configured")
await self.post(
"/start", timeout=240, data={"license_check": license_check, "iourc_content": iourc_content}
)
else:
await self.post("/start", data=data, timeout=240)
license_check = self._project.controller.iou_license.get("license_check")
iourc_content = self._project.controller.iou_license.get("iourc_content")
if license_check:
data = {"license_check": license_check, "iourc_content": iourc_content}
await self.post("/start", data=data, timeout=240)
except asyncio.TimeoutError:
raise ControllerTimeoutError(f"Timeout when starting {self._name}")

Expand Down

0 comments on commit 014d3f2

Please sign in to comment.