diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..f4daa60 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +docker-compose.yml +.gitignore +.env +.git +.cache diff --git a/.gitignore b/.gitignore index 5eb810c..226ce51 100644 --- a/.gitignore +++ b/.gitignore @@ -163,3 +163,4 @@ cython_debug/ # Project specific config.json +**/dummy_platform diff --git a/Dockerfile b/Dockerfile index 3a61849..cb9a37b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,59 @@ +# app/Dockerfile + +# pull the official docker image +FROM python:3.11-alpine as poetry-base + +# default build args +ARG APP_VERSION=0.1.0 \ + APP_DIR=/app \ + SRC_DIR=./mgrctl \ + PKG_NAME=mgrctl \ + PKG_VERSION=0.1.0 + +# set env variables +ENV APP_NAME=mgrctl \ + # Python3: + PYTHONFAULTHANDLER=1 \ + PYTHONUNBUFFERED=1 \ + PYTHONHASHSEED=random \ + # Pip: + PIP_NO_CACHE_DIR=on \ + PIP_DISABLE_PIP_VERSION_CHECK=on \ + PIP_ROOT_USER_ACTION=ignore \ + PIP_DEFAULT_TIMEOUT=100 \ + # Poetry: + POETRY_NO_INTERACTION=1 \ + POETRY_VIRTUALENVS_CREATE=false \ + POETRY_CACHE_DIR='/var/cache/pypoetry' \ + POETRY_HOME='/usr/local' \ + POETRY_VERSION=1.7.1 + +# install system deps +RUN apk --no-cache add curl \ + && curl -sSL https://install.python-poetry.org | python3 - \ + && mkdir ${APP_DIR} + +COPY ./pyproject.toml ./poetry.lock ./README.md ${APP_DIR} +COPY ${SRC_DIR} ${APP_DIR}/${PKG_NAME} + +# set workdir +WORKDIR ${APP_DIR} + +# build pkg whl +RUN poetry build --format wheel \ + && pip install ${APP_DIR}/dist/${PKG_NAME}-${PKG_VERSION}-py3-none-any.whl \ + && rm -r /usr/local/venv + +# now multistage builds FROM python:3.11-alpine -WORKDIR /app +# copy app and dependences +COPY --from=poetry-base /usr/local/ /usr/local/ -COPY requirements.txt ./ -RUN pip install --no-cache-dir --root-user-action=ignore -r requirements.txt +# install bash and mgrctl shell completion +RUN apk --no-cache add bash \ + && echo 'eval "$(_MGRCTL_COMPLETE=bash_source mgrctl)"' > ~/.bashrc -COPY main.py . - -CMD [ "python", "-u", "main.py" ] +# "demonize" container +# use docker attach mgrctl or docker exec -it mgrctl mgrctl --help for example +CMD [ "bash"] diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..9ea0244 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,59 @@ +# ? docker-compose.yml for development environment + +# ! To start development you need to create a directory ./dummy_platform. +# ? Place files from the test platform into it: +# ? VM6: +# ? /opt/ispsystem/vm/config.json - configuration file +# ? /opt/ispsystem/vm/mysql - database directory +# ? DCI6: +# ? /opt/ispsystem/dci/config.json - configuration file +# ? /opt/ispsystem/dci/mysql - database directory + +# ? Create ./.env file and fill it with required vars: +# ? PLATFORM_TYPE='vm' +# ? Database container: +# ? MYSQL_DATABASE="database name" +# ? MYSQL_ROOT_PASSWORD="super secret password from config.json" + +# ? Launch: +# ? docker-compose up -d --force-recreate +# ? docker attach mgrctl + +services: + mgrctl: + container_name: mgrctl + restart: unless-stopped + build: + context: . + args: + - APP_VERSION=${APP_VERSION} + - APP_DIR=${APP_DIR} + - SRC_DIR=${SRC_DIR} + - PKG_NAME=${PKG_NAME} + - PKG_VERSION=${PKG_VERSION} + networks: + vm_box_net: null + volumes: + - type: bind + source: ./dummy_platform/opt/ispsystem/${PLATFORM_TYPE}/config.json + target: /opt/ispsystem/${PLATFORM_TYPE}/config.json + env_file: + - ./.env + tty: true + stdin_open: true + mysql: + container_name: mysql + image: docker-registry.ispsystem.com/mysql:5 + volumes: + - ./dummy_platform/opt/ispsystem/${PLATFORM_TYPE}/mysql:/var/lib/mysql + env_file: + - ./.env + labels: + autoconf_mysql: "true" + networks: + vm_box_net: null + command: --group-concat-max-len=131072 --max-connections=1000 --optimizer-search-depth=0 + +networks: + vm_box_net: + driver: bridge diff --git a/isp_maintenance/apps/vm6/commands.py b/isp_maintenance/apps/vm6/commands.py deleted file mode 100644 index ad96145..0000000 --- a/isp_maintenance/apps/vm6/commands.py +++ /dev/null @@ -1,12 +0,0 @@ -import click -from cli.lazy_group import LazyGroup -from settings.general import INSTALLED_APPS - - -@click.group( - cls=LazyGroup, - lazy_subcommands=INSTALLED_APPS['vm6'], - help='vm6 command for lazy example', -) -def cli(): - pass diff --git a/isp_maintenance/apps/vm6/migrations/__init__.py b/isp_maintenance/apps/vm6/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/isp_maintenance/apps/vm6/nodes/__init__.py b/isp_maintenance/apps/vm6/nodes/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/isp_maintenance/apps/vm6/nodes/commands.py b/isp_maintenance/apps/vm6/nodes/commands.py deleted file mode 100644 index 014b468..0000000 --- a/isp_maintenance/apps/vm6/nodes/commands.py +++ /dev/null @@ -1,13 +0,0 @@ -import click - - -@click.group(help='nodes command for lazy example') -def cli(): - pass - - -@cli.command(name='list') -def nodes_list(): - click.echo('NODES LIST: etc...') - for num in range(1, 10): - click.echo(num) diff --git a/isp_maintenance/cli/__init__.py b/isp_maintenance/cli/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/isp_maintenance/db/__init__.py b/isp_maintenance/db/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/isp_maintenance/db/dci6/__init__.py b/isp_maintenance/db/dci6/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/isp_maintenance/db/vm6/__init__.py b/isp_maintenance/db/vm6/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/isp_maintenance/ispmgr.py b/isp_maintenance/ispmgr.py deleted file mode 100755 index 380a1de..0000000 --- a/isp_maintenance/ispmgr.py +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -import click - -from cli.lazy_group import LazyGroup - - -@click.group( - cls=LazyGroup, - lazy_subcommands={ - 'vm6': 'apps.vm6.commands.cli', - 'dci6': 'apps.dci6.commands.cli', - }, - help='main CLI command for lazy example', -) -def cli(): - pass - - -if __name__ == '__main__': - cli() diff --git a/isp_maintenance/settings/platform.py b/isp_maintenance/settings/platform.py deleted file mode 100644 index 0bf34ae..0000000 --- a/isp_maintenance/settings/platform.py +++ /dev/null @@ -1,13 +0,0 @@ -from settings.environment import env -from settings.general import BASE_DIR -from utils.helpers import parse_json_file - - -PLATFORM_TYPE = env.str('PLATFORM_TYPE', 'vm') - -PLATFORM_CONFIG = parse_json_file(f'{BASE_DIR}/config.json') - -PLATFORM_URL = env.url( - 'PLATFORM_URL', - f"https://{PLATFORM_CONFIG.get('DomainName' ,'replace.me')}" -) diff --git a/isp_maintenance/utils/__init__.py b/isp_maintenance/utils/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/mgrctl/__init__.py b/mgrctl/__init__.py new file mode 100644 index 0000000..3cb5478 --- /dev/null +++ b/mgrctl/__init__.py @@ -0,0 +1,15 @@ +# █▀▄▀█ █▀▀ ▀█▀ ▄▀█ ▀ +# █░▀░█ ██▄ ░█░ █▀█ ▄ +# -- -- -- -- -- -- - +__author__ = "MOIS3Y, a.garaev, Failak3, Ann_M" +__credits__ = [ + "Stepan Zhukovsky", + "Arthur Garaev", + "Vladislav Shmidt", + "Anna Moskovkina" +] +__license__ = "MIT" +__version__ = "0.1.0" +__maintainer__ = "Stepan Zhukovsky" +__email__ = "stepan@zhukovsky.me" +__status__ = "Development" diff --git a/isp_maintenance/__init__.py b/mgrctl/api/__init__.py similarity index 100% rename from isp_maintenance/__init__.py rename to mgrctl/api/__init__.py diff --git a/isp_maintenance/api/base.py b/mgrctl/api/base.py similarity index 94% rename from isp_maintenance/api/base.py rename to mgrctl/api/base.py index 84a0468..bc3b00c 100644 --- a/isp_maintenance/api/base.py +++ b/mgrctl/api/base.py @@ -3,7 +3,7 @@ import json import urllib import requests -from settings.api import INPUT_HOSTNAME, INPUT_PORT, HEADERS +from mgrctl.settings.api import INPUT_HOSTNAME, INPUT_PORT, HEADERS class BaseAPI(object): @@ -61,6 +61,12 @@ class BaseAPI(object): print(response) raise sys.exit() + def get(self, url, headers={}, data={}): + return self.call_api(url, headers, data, method='GET') + + def post(self, url, headers={}, data={}): + return self.call_api(url, headers, data, method='POST') + class BaseAuthAPI(BaseAPI): def __init__(self, api_url=None, verify_ssl=True): diff --git a/isp_maintenance/api/dci6.py b/mgrctl/api/dci6.py similarity index 93% rename from isp_maintenance/api/dci6.py rename to mgrctl/api/dci6.py index 80aebe2..f5639de 100644 --- a/isp_maintenance/api/dci6.py +++ b/mgrctl/api/dci6.py @@ -1,4 +1,4 @@ -from api.base import BaseAPI, BaseAuthAPI, BaseDnsProxyAPI, BaseIpAPI +from mgrctl.api.base import BaseAPI, BaseAuthAPI, BaseDnsProxyAPI, BaseIpAPI class AuthAPI(BaseAuthAPI): diff --git a/isp_maintenance/api/vm6.py b/mgrctl/api/vm6.py similarity index 78% rename from isp_maintenance/api/vm6.py rename to mgrctl/api/vm6.py index fc9eaed..3391717 100644 --- a/isp_maintenance/api/vm6.py +++ b/mgrctl/api/vm6.py @@ -1,4 +1,4 @@ -from api.base import BaseAPI, BaseAuthAPI, BaseDnsProxyAPI, BaseIpAPI +from mgrctl.api.base import BaseAPI, BaseAuthAPI, BaseDnsProxyAPI, BaseIpAPI class AuthAPI(BaseAuthAPI): diff --git a/mgrctl/apps/__init__.py b/mgrctl/apps/__init__.py new file mode 100644 index 0000000..3cb5478 --- /dev/null +++ b/mgrctl/apps/__init__.py @@ -0,0 +1,15 @@ +# █▀▄▀█ █▀▀ ▀█▀ ▄▀█ ▀ +# █░▀░█ ██▄ ░█░ █▀█ ▄ +# -- -- -- -- -- -- - +__author__ = "MOIS3Y, a.garaev, Failak3, Ann_M" +__credits__ = [ + "Stepan Zhukovsky", + "Arthur Garaev", + "Vladislav Shmidt", + "Anna Moskovkina" +] +__license__ = "MIT" +__version__ = "0.1.0" +__maintainer__ = "Stepan Zhukovsky" +__email__ = "stepan@zhukovsky.me" +__status__ = "Development" diff --git a/mgrctl/apps/dci6/__init__.py b/mgrctl/apps/dci6/__init__.py new file mode 100644 index 0000000..3cb5478 --- /dev/null +++ b/mgrctl/apps/dci6/__init__.py @@ -0,0 +1,15 @@ +# █▀▄▀█ █▀▀ ▀█▀ ▄▀█ ▀ +# █░▀░█ ██▄ ░█░ █▀█ ▄ +# -- -- -- -- -- -- - +__author__ = "MOIS3Y, a.garaev, Failak3, Ann_M" +__credits__ = [ + "Stepan Zhukovsky", + "Arthur Garaev", + "Vladislav Shmidt", + "Anna Moskovkina" +] +__license__ = "MIT" +__version__ = "0.1.0" +__maintainer__ = "Stepan Zhukovsky" +__email__ = "stepan@zhukovsky.me" +__status__ = "Development" diff --git a/isp_maintenance/api/__init__.py b/mgrctl/apps/dci6/auth/__init__.py similarity index 100% rename from isp_maintenance/api/__init__.py rename to mgrctl/apps/dci6/auth/__init__.py diff --git a/isp_maintenance/apps/dci6/access/commands.py b/mgrctl/apps/dci6/auth/commands.py similarity index 100% rename from isp_maintenance/apps/dci6/access/commands.py rename to mgrctl/apps/dci6/auth/commands.py diff --git a/isp_maintenance/apps/dci6/commands.py b/mgrctl/apps/dci6/commands.py similarity index 62% rename from isp_maintenance/apps/dci6/commands.py rename to mgrctl/apps/dci6/commands.py index e864586..cf56b73 100644 --- a/isp_maintenance/apps/dci6/commands.py +++ b/mgrctl/apps/dci6/commands.py @@ -1,7 +1,7 @@ import click -from cli.lazy_group import LazyGroup -from settings.general import INSTALLED_APPS +from mgrctl.cli.lazy_group import LazyGroup +from mgrctl.settings.general import INSTALLED_APPS @click.group( diff --git a/mgrctl/apps/vm6/__init__.py b/mgrctl/apps/vm6/__init__.py new file mode 100644 index 0000000..3cb5478 --- /dev/null +++ b/mgrctl/apps/vm6/__init__.py @@ -0,0 +1,15 @@ +# █▀▄▀█ █▀▀ ▀█▀ ▄▀█ ▀ +# █░▀░█ ██▄ ░█░ █▀█ ▄ +# -- -- -- -- -- -- - +__author__ = "MOIS3Y, a.garaev, Failak3, Ann_M" +__credits__ = [ + "Stepan Zhukovsky", + "Arthur Garaev", + "Vladislav Shmidt", + "Anna Moskovkina" +] +__license__ = "MIT" +__version__ = "0.1.0" +__maintainer__ = "Stepan Zhukovsky" +__email__ = "stepan@zhukovsky.me" +__status__ = "Development" diff --git a/mgrctl/apps/vm6/auth/__init__.py b/mgrctl/apps/vm6/auth/__init__.py new file mode 100644 index 0000000..aff160b --- /dev/null +++ b/mgrctl/apps/vm6/auth/__init__.py @@ -0,0 +1,10 @@ +# █▀▄▀█ █▀▀ ▀█▀ ▄▀█ ▀ +# █░▀░█ ██▄ ░█░ █▀█ ▄ +# -- -- -- -- -- -- - +__author__ = "MOIS3Y" +__credits__ = ["Stepan Zhukovsky"] +__license__ = "MIT" +__version__ = "0.1.0" +__maintainer__ = "Stepan Zhukovsky" +__email__ = "stepan@zhukovsky.me" +__status__ = "Development" diff --git a/isp_maintenance/apps/vm6/access/commands.py b/mgrctl/apps/vm6/auth/commands.py similarity index 62% rename from isp_maintenance/apps/vm6/access/commands.py rename to mgrctl/apps/vm6/auth/commands.py index 045a60a..8c49886 100644 --- a/isp_maintenance/apps/vm6/access/commands.py +++ b/mgrctl/apps/vm6/auth/commands.py @@ -1,10 +1,17 @@ import click -from db.vm6.databases import isp_database -from db.vm6.models import AuthUser +from mgrctl.db.vm6.databases import isp_database +from mgrctl.db.vm6.models import AuthUser + +from mgrctl.apps.vm6.auth import __version__ -@click.group(help='access command for lazy example') +@click.group(help='auth cmd for auth in VMmanager 6') +@click.version_option( + version=__version__, + package_name='mgrctl.apps.vm6.auth', + message=__version__ +) def cli(): pass diff --git a/mgrctl/apps/vm6/commands.py b/mgrctl/apps/vm6/commands.py new file mode 100644 index 0000000..c469c36 --- /dev/null +++ b/mgrctl/apps/vm6/commands.py @@ -0,0 +1,19 @@ +import click + +from mgrctl.cli.lazy_group import LazyGroup +from mgrctl.settings.general import INSTALLED_APPS +from mgrctl.apps.vm6 import __version__ + + +@click.group( + cls=LazyGroup, + lazy_subcommands=INSTALLED_APPS['vm6'], + help='vm6 command for lazy example', +) +@click.version_option( + version=__version__, + package_name='mgrctl', + message=__version__ +) +def cli(): + pass diff --git a/isp_maintenance/apps/__init__.py b/mgrctl/cli/__init__.py similarity index 100% rename from isp_maintenance/apps/__init__.py rename to mgrctl/cli/__init__.py diff --git a/isp_maintenance/cli/lazy_group.py b/mgrctl/cli/lazy_group.py similarity index 100% rename from isp_maintenance/cli/lazy_group.py rename to mgrctl/cli/lazy_group.py diff --git a/isp_maintenance/apps/dci6/__init__.py b/mgrctl/db/__init__.py similarity index 100% rename from isp_maintenance/apps/dci6/__init__.py rename to mgrctl/db/__init__.py diff --git a/isp_maintenance/db/common.py b/mgrctl/db/common.py similarity index 100% rename from isp_maintenance/db/common.py rename to mgrctl/db/common.py diff --git a/isp_maintenance/db/connection.py b/mgrctl/db/connection.py similarity index 97% rename from isp_maintenance/db/connection.py rename to mgrctl/db/connection.py index c86f80d..113a46f 100644 --- a/isp_maintenance/db/connection.py +++ b/mgrctl/db/connection.py @@ -1,5 +1,5 @@ from peewee import MySQLDatabase, PostgresqlDatabase -from settings.db import ( +from mgrctl.settings.db import ( DB_ENGINE, DB_HOST, DB_PORT, diff --git a/isp_maintenance/apps/dci6/access/__init__.py b/mgrctl/db/dci6/__init__.py similarity index 100% rename from isp_maintenance/apps/dci6/access/__init__.py rename to mgrctl/db/dci6/__init__.py diff --git a/isp_maintenance/db/dci6/databases.py b/mgrctl/db/dci6/databases.py similarity index 86% rename from isp_maintenance/db/dci6/databases.py rename to mgrctl/db/dci6/databases.py index be997d3..c2892dd 100644 --- a/isp_maintenance/db/dci6/databases.py +++ b/mgrctl/db/dci6/databases.py @@ -1,4 +1,4 @@ -from db.connection import guess_database +from mgrctl.db.connection import guess_database # The variable will contain an object of diff --git a/isp_maintenance/db/dci6/models.py b/mgrctl/db/dci6/models.py similarity index 99% rename from isp_maintenance/db/dci6/models.py rename to mgrctl/db/dci6/models.py index 98c5dfe..467fd89 100644 --- a/isp_maintenance/db/dci6/models.py +++ b/mgrctl/db/dci6/models.py @@ -11,8 +11,8 @@ from peewee import ( TextField, SQL ) -from db.common import UnknownField -from db.dci6.databases import auth_database +from mgrctl.db.common import UnknownField +from mgrctl.db.dci6.databases import auth_database class BaseModel(Model): diff --git a/isp_maintenance/apps/vm6/__init__.py b/mgrctl/db/vm6/__init__.py similarity index 100% rename from isp_maintenance/apps/vm6/__init__.py rename to mgrctl/db/vm6/__init__.py diff --git a/isp_maintenance/db/vm6/databases.py b/mgrctl/db/vm6/databases.py similarity index 84% rename from isp_maintenance/db/vm6/databases.py rename to mgrctl/db/vm6/databases.py index 597b0b6..3544668 100644 --- a/isp_maintenance/db/vm6/databases.py +++ b/mgrctl/db/vm6/databases.py @@ -1,4 +1,4 @@ -from db.connection import guess_database +from mgrctl.db.connection import guess_database # The variable will contain an object of diff --git a/isp_maintenance/db/vm6/models.py b/mgrctl/db/vm6/models.py similarity index 99% rename from isp_maintenance/db/vm6/models.py rename to mgrctl/db/vm6/models.py index f9a9f4d..0616d41 100644 --- a/isp_maintenance/db/vm6/models.py +++ b/mgrctl/db/vm6/models.py @@ -12,8 +12,8 @@ from peewee import ( TextField, SQL ) -from db.common import UnknownField, JSONField -from db.vm6.databases import isp_database +from mgrctl.db.common import UnknownField, JSONField +from mgrctl.db.vm6.databases import isp_database class BaseModel(Model): diff --git a/mgrctl/mgrctl.py b/mgrctl/mgrctl.py new file mode 100755 index 0000000..afe8246 --- /dev/null +++ b/mgrctl/mgrctl.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# █▀▄▀█ █▀▀ █▀█ █▀▀ ▀█▀ █░░ ▀ +# █░▀░█ █▄█ █▀▄ █▄▄ ░█░ █▄▄ ▄ +# -- -- -- -- -- -- -- -- -- + +import click + +from mgrctl import __version__ +from mgrctl.cli.lazy_group import LazyGroup + + +@click.group( + cls=LazyGroup, + lazy_subcommands={ + 'vm6': 'mgrctl.apps.vm6.commands.cli', + 'dci6': 'mgrctl.apps.dci6.commands.cli', + }, + help='main CLI command for lazy example', +) +@click.version_option( + version=__version__, + package_name='mgrctl', + message=__version__ +) +def cli(): + pass + + +if __name__ == '__main__': + cli() diff --git a/isp_maintenance/settings/__init__.py b/mgrctl/settings/__init__.py similarity index 53% rename from isp_maintenance/settings/__init__.py rename to mgrctl/settings/__init__.py index a108dad..1bae8b9 100644 --- a/isp_maintenance/settings/__init__.py +++ b/mgrctl/settings/__init__.py @@ -1,12 +1,12 @@ -from settings.general import BASE_DIR +from mgrctl.settings.general import BASE_DIR -from settings.platform import ( +from mgrctl.settings.platform import ( PLATFORM_TYPE, PLATFORM_URL, PLATFORM_CONFIG ) -from settings.db import( +from mgrctl.settings.db import( DB_ENGINE, DB_HOST, DB_PORT, diff --git a/isp_maintenance/settings/api.py b/mgrctl/settings/api.py similarity index 83% rename from isp_maintenance/settings/api.py rename to mgrctl/settings/api.py index 5e26345..b027494 100644 --- a/isp_maintenance/settings/api.py +++ b/mgrctl/settings/api.py @@ -1,4 +1,4 @@ -from settings.platform import PLATFORM_TYPE +from mgrctl.settings.platform import PLATFORM_TYPE # Name of nginx container: INPUT_HOSTNAME = 'input' if PLATFORM_TYPE == 'vm' else 'dci_input_1' diff --git a/isp_maintenance/settings/db.py b/mgrctl/settings/db.py similarity index 83% rename from isp_maintenance/settings/db.py rename to mgrctl/settings/db.py index c6bb73e..fa279a0 100644 --- a/isp_maintenance/settings/db.py +++ b/mgrctl/settings/db.py @@ -1,5 +1,5 @@ -from settings.environment import env -from settings.platform import PLATFORM_CONFIG +from mgrctl.settings.environment import env +from mgrctl.settings.platform import PLATFORM_CONFIG # ! Required because some instance use psql db: diff --git a/isp_maintenance/settings/environment.py b/mgrctl/settings/environment.py similarity index 100% rename from isp_maintenance/settings/environment.py rename to mgrctl/settings/environment.py diff --git a/isp_maintenance/settings/general.py b/mgrctl/settings/general.py similarity index 57% rename from isp_maintenance/settings/general.py rename to mgrctl/settings/general.py index 433df37..4b060fa 100644 --- a/isp_maintenance/settings/general.py +++ b/mgrctl/settings/general.py @@ -6,10 +6,9 @@ BASE_DIR = pathlib.Path(__file__).resolve().parent.parent INSTALLED_APPS = { 'vm6': { - 'access': 'apps.vm6.access.commands.cli', - 'nodes': 'apps.vm6.nodes.commands.cli', + 'auth': 'mgrctl.apps.vm6.auth.commands.cli', }, 'dci6': { - 'access': 'apps.dci6.access.commands.cli', + 'auth': 'mgrctl.apps.dci6.auth.commands.cli', }, } diff --git a/mgrctl/settings/platform.py b/mgrctl/settings/platform.py new file mode 100644 index 0000000..49420e1 --- /dev/null +++ b/mgrctl/settings/platform.py @@ -0,0 +1,17 @@ +from mgrctl.settings.environment import env +from mgrctl.utils.helpers import parse_json_file + + +PLATFORM_TYPE = env.str('PLATFORM_TYPE', 'vm') + +PLATFORM_CONFIG = env.str( + 'PLATFORM_CONFIG', + f'/opt/ispsystem/{PLATFORM_TYPE}/config.json' +) + +PLATFORM_CONFIG = parse_json_file(PLATFORM_CONFIG) + +PLATFORM_URL = env.url( + 'PLATFORM_URL', + f"https://{PLATFORM_CONFIG.get('DomainName' ,'replace.me')}" +) diff --git a/isp_maintenance/apps/vm6/access/__init__.py b/mgrctl/utils/__init__.py similarity index 100% rename from isp_maintenance/apps/vm6/access/__init__.py rename to mgrctl/utils/__init__.py diff --git a/isp_maintenance/utils/helpers.py b/mgrctl/utils/helpers.py similarity index 61% rename from isp_maintenance/utils/helpers.py rename to mgrctl/utils/helpers.py index 0a85dc2..3cb4d26 100644 --- a/isp_maintenance/utils/helpers.py +++ b/mgrctl/utils/helpers.py @@ -1,8 +1,9 @@ import json import sys +import click -def parse_json_file(file_path): +def parse_json_file(file_path: str) -> dict: """ Function read json file as usual config.json then parse it to python dict @@ -16,5 +17,7 @@ def parse_json_file(file_path): with open(file_path, 'r') as f: return json.load(f) except Exception as error: - print(error) + click.echo(error) + click.echo("Required: /opt/ispsystem/PLATFORM_TYPE/config.json") + click.echo("Note: don't forget to mount this file into the container") sys.exit(1) diff --git a/pyproject.toml b/pyproject.toml index 60095d5..42aebb0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,13 @@ [tool.poetry] -name = "isp-maintenance" +name = "mgrctl" version = "0.1.0" description = "Maintenance service for ISPsystem platforms" -authors = ["MOIS3Y ", "Failak3 ", "a.garaev ", "Ann_M "] +authors = [ + "MOIS3Y ", + "Failak3 ", + "a.garaev ", + "Ann_M " +] license = "MIT" readme = "README.md" @@ -19,7 +24,9 @@ sh = "^2.0.7" [tool.poetry.group.dev.dependencies] flake8 = "^7.0.0" +[tool.poetry.scripts] +mgrctl = 'mgrctl.mgrctl:cli' + [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" -