forked from mirrors/thatmattlove-hyperglass
check the NodeJS version on startup, closes #105
This commit is contained in:
parent
844958726f
commit
a3d9cf4e54
4 changed files with 42 additions and 8 deletions
2
.flake8
2
.flake8
|
|
@ -16,7 +16,7 @@ per-file-ignores=
|
||||||
# Disable unused import warning for modules
|
# Disable unused import warning for modules
|
||||||
hyperglass/*/__init__.py:F401
|
hyperglass/*/__init__.py:F401
|
||||||
hyperglass/models/*/__init__.py:F401
|
hyperglass/models/*/__init__.py:F401
|
||||||
ignore=W503,C0330,R504,D202,S403,S301
|
ignore=W503,C0330,R504,D202,S403,S301,S404
|
||||||
select=B, BLK, C, D, E, F, I, II, N, P, PIE, S, R, W
|
select=B, BLK, C, D, E, F, I, II, N, P, PIE, S, R, W
|
||||||
disable-noqa=False
|
disable-noqa=False
|
||||||
hang-closing=False
|
hang-closing=False
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ METADATA = (__name__, __version__, __author__, __copyright__, __license__)
|
||||||
|
|
||||||
MIN_PYTHON_VERSION = (3, 6)
|
MIN_PYTHON_VERSION = (3, 6)
|
||||||
|
|
||||||
|
MIN_NODE_VERSION = 14
|
||||||
|
|
||||||
TARGET_FORMAT_SPACE = ("huawei", "huawei_vrpv8")
|
TARGET_FORMAT_SPACE = ("huawei", "huawei_vrpv8")
|
||||||
|
|
||||||
TARGET_JUNIPER_ASPATH = ("juniper", "juniper_junos")
|
TARGET_JUNIPER_ASPATH = ("juniper", "juniper_junos")
|
||||||
|
|
|
||||||
|
|
@ -12,18 +12,27 @@ from gunicorn.arbiter import Arbiter
|
||||||
from gunicorn.app.base import BaseApplication
|
from gunicorn.app.base import BaseApplication
|
||||||
from gunicorn.glogging import Logger
|
from gunicorn.glogging import Logger
|
||||||
|
|
||||||
# Project
|
# Local
|
||||||
from hyperglass.log import log, setup_lib_logging
|
from .log import log, setup_lib_logging
|
||||||
from hyperglass.constants import MIN_PYTHON_VERSION, __version__
|
from .constants import MIN_NODE_VERSION, MIN_PYTHON_VERSION, __version__
|
||||||
|
from .util.frontend import get_node_version
|
||||||
|
|
||||||
|
# Ensure the Python version meets the minimum requirements.
|
||||||
pretty_version = ".".join(tuple(str(v) for v in MIN_PYTHON_VERSION))
|
pretty_version = ".".join(tuple(str(v) for v in MIN_PYTHON_VERSION))
|
||||||
if sys.version_info < MIN_PYTHON_VERSION:
|
if sys.version_info < MIN_PYTHON_VERSION:
|
||||||
raise RuntimeError(f"Python {pretty_version}+ is required.")
|
raise RuntimeError(f"Python {pretty_version}+ is required.")
|
||||||
|
|
||||||
# Project
|
# Ensure the NodeJS version meets the minimum requirements.
|
||||||
from hyperglass.cache import SyncCache
|
node_version = get_node_version()
|
||||||
|
|
||||||
from hyperglass.configuration import ( # isort:skip
|
if node_version != MIN_NODE_VERSION:
|
||||||
|
raise RuntimeError(f"NodeJS {MIN_NODE_VERSION}+ is required.")
|
||||||
|
|
||||||
|
|
||||||
|
# Local
|
||||||
|
from .cache import SyncCache
|
||||||
|
|
||||||
|
from .configuration import ( # isort:skip
|
||||||
params,
|
params,
|
||||||
URL_DEV,
|
URL_DEV,
|
||||||
URL_PROD,
|
URL_PROD,
|
||||||
|
|
@ -31,12 +40,14 @@ from hyperglass.configuration import ( # isort:skip
|
||||||
REDIS_CONFIG,
|
REDIS_CONFIG,
|
||||||
frontend_params,
|
frontend_params,
|
||||||
)
|
)
|
||||||
from hyperglass.util import ( # isort:skip
|
from .util import ( # isort:skip
|
||||||
cpu_count,
|
cpu_count,
|
||||||
build_frontend,
|
build_frontend,
|
||||||
clear_redis_cache,
|
clear_redis_cache,
|
||||||
format_listen_address,
|
format_listen_address,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
from hyperglass.compat._asyncio import aiorun # isort:skip
|
from hyperglass.compat._asyncio import aiorun # isort:skip
|
||||||
|
|
||||||
if params.debug:
|
if params.debug:
|
||||||
|
|
|
||||||
21
hyperglass/util/frontend.py
Normal file
21
hyperglass/util/frontend.py
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
"""Utility functions for frontend-related tasks."""
|
||||||
|
|
||||||
|
# Standard Library
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def get_node_version() -> int:
|
||||||
|
"""Get the system's NodeJS version."""
|
||||||
|
node_path = shutil.which("node")
|
||||||
|
|
||||||
|
raw_version = subprocess.check_output( # noqa: S603
|
||||||
|
[node_path, "--version"]
|
||||||
|
).decode()
|
||||||
|
|
||||||
|
# Node returns the version as 'v14.5.0', for example. Remove the v.
|
||||||
|
version = raw_version.replace("v", "")
|
||||||
|
# Parse the version parts.
|
||||||
|
major, minor, patch = version.split(".")
|
||||||
|
|
||||||
|
return int(major)
|
||||||
Loading…
Add table
Reference in a new issue