From 763624dcd31e81be37db456fb1abddd98f0df97d Mon Sep 17 00:00:00 2001 From: RemiZOffAlex Date: Fri, 27 Sep 2024 12:16:37 +0300 Subject: [PATCH] Add infector --- .gitignore | 2 ++ README.md | 5 +++++ infector/__init__.py | 42 ++++++++++++++++++++++++++++++++++++++++++ infector/__main__.py | 10 ++++++++++ pyproject.toml | 42 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+) create mode 100644 .gitignore create mode 100644 infector/__init__.py create mode 100644 infector/__main__.py create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ac8d7b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__ +dist diff --git a/README.md b/README.md index e69de29..af5de92 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,5 @@ +# Infector + +``` +python -m infector +``` diff --git a/infector/__init__.py b/infector/__init__.py new file mode 100644 index 0000000..4eedc89 --- /dev/null +++ b/infector/__init__.py @@ -0,0 +1,42 @@ +__author__ = 'RemiZOffAlex' +__email__ = 'remizoffalex@mail.ru' + +import npyscreen +from pyroute2 import NDB + + +ndb = NDB() + + +def network_config(ip, mask, gateway): + # ip = IPRoute() + # index = ip.link_lookup(ifname='em1')[0] + # ip.addr('add', index, address='192.168.0.1', mask=24) + # ip.close() + # ip = IPDB() + # with ip.interfaces.br0 as br0: + # em1.add_ip('{ip}/{mask}'.format(ip=ip, mask=mask)) + # ip.release() + with ndb.interfaces['br0'] as br0: + br0.add_ip('{ip}/{mask}'.format(ip=ip, mask=mask)).commit() + + ndb.routes.create(dst='0.0.0.0/0', gateway=gateway).commit() + + +def TestApp(*args): + # These lines create the form and populate it with widgets. + # A fairly complex screen in only 8 or so lines of code - a line for each control. + F = npyscreen.Form(name = "SaaS",) + ip = F.add(npyscreen.TitleText, name = "IP:",) + mask = F.add(npyscreen.TitleText, name = "Netmask:",) + gateway = F.add(npyscreen.TitleText, name = "Gateway:",) + + # This lets the user interact with the Form. + F.edit() + + network_config(ip, mask, gateway) + return { + 'ip': ip.value, + 'mask': mask.value, + 'gateway': gateway.value, + } diff --git a/infector/__main__.py b/infector/__main__.py new file mode 100644 index 0000000..29f24a3 --- /dev/null +++ b/infector/__main__.py @@ -0,0 +1,10 @@ +__author__ = 'RemiZOffAlex' +__email__ = 'remizoffalex@mail.ru' + +import npyscreen + +from . import TestApp + + +result = npyscreen.wrapper_basic(TestApp) +print(result) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..8632d22 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,42 @@ +[project] +name = "infector" +version ="0.1" +authors = [ + { name="RemiZOffAlex", email="remizoffalex@gmail.com" }, +] +maintainers = [ + { name="RemiZOffAlex", email="remizoffalex@gmail.com" }, +] +description = "infector - инсталлятор системы" +requires-python = ">=3.10" +classifiers = [ + "Environment :: Console", + "Intended Audience :: Developers", + "Intended Audience :: Information Technology", + "Intended Audience :: System Administrators", + "Operating System :: POSIX :: Linux", + "Programming Language :: Formal", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", +# "Topic :: Software Development :: Code Generators", +# "Topic :: Software Development :: Compilers", + "Topic :: Software Development :: Libraries", +] +keywords = ["config", "configurator", "configuration management"] +dependencies = [ + "pyyaml", + "pyroute2", + "npyscreen", + "middleware@git+https://codex.r10x.net/RemiZOffAlex/middleware", +] + +[build-system] +requires = ["flit_core >=3.2,<4"] +build-backend = "flit_core.buildapi" + +[tool.flit.sdist] +include = [] +exclude = []