diff --git a/.rsyncignore b/.rsyncignore new file mode 100644 index 0000000..ff3e151 --- /dev/null +++ b/.rsyncignore @@ -0,0 +1,5 @@ +.venv +.git +__pycache__/ +*.egg-info/ +venv \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a90e6ad --- /dev/null +++ b/Makefile @@ -0,0 +1,4 @@ +DEST:=/opt/nativecloud-agent + +sync: + rsync -rvz --exclude-from .rsyncignore --delete ./ root@192.168.11.11:/opt/nativecloud-agent/ \ No newline at end of file diff --git a/README.md b/README.md index 575119f..3a54786 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,14 @@ Version: 1.0 ## Install +### rockylinux 9 + +```shell +dnf install -y python3-netaddr python3-libvirt python3-requests +``` + +### ubuntu (old) + ``` $ apt-get install sqlite3 $ apt-get install lxc @@ -14,7 +22,6 @@ $ pip install pyparsing $ apt-get install dnsmasq ``` - ## Setting DNSMASQ Uncomment string in file `/etc/dnsmasq.conf`: diff --git a/SWSCloudNode/__init__.py b/SWSCloudNode/__init__.py index f740053..813da40 100644 --- a/SWSCloudNode/__init__.py +++ b/SWSCloudNode/__init__.py @@ -1,4 +1,3 @@ -# coding: utf-8 from SWSCloudNode.settings import settings from SWSCloudNode.compute.lxc import LXC diff --git a/SWSCloudNode/common.py b/SWSCloudNode/common.py index 33a6f6a..01807f9 100644 --- a/SWSCloudNode/common.py +++ b/SWSCloudNode/common.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- - +import time import datetime import json import os @@ -30,7 +29,7 @@ class Common: """ if code == 1: message = "Invalid JSON-RPC. Unknown RPC version" - print self.time() + " - " + message + print(time.time() + " - " + message) return {"error": {"code": code, "message": message}} def settings_node(self): @@ -41,7 +40,7 @@ class Common: with open('/etc/gocloud/node/node.json') as nodesettings_file: conf = json.load(nodesettings_file) else: - print "[Errno 2] No such file or directory: '/etc/gocloud/node/node.json'" + print("[Errno 2] No such file or directory: '/etc/gocloud/node/node.json'") sys.exit(2) return conf @@ -54,7 +53,7 @@ class Common: with open('/etc/gocloud/node/vmsettings.json') as vmsettings_file: conf = json.load(vmsettings_file) else: - print "[Errno 2] No such file or directory: '/etc/gocloud/node/vmsettings.json'" + print("[Errno 2] No such file or directory: '/etc/gocloud/node/vmsettings.json'") sys.exit(2) return conf diff --git a/SWSCloudNode/compute/lxc/lxc.py b/SWSCloudNode/compute/lxc/lxc.py index 25339d5..0b00179 100644 --- a/SWSCloudNode/compute/lxc/lxc.py +++ b/SWSCloudNode/compute/lxc/lxc.py @@ -248,12 +248,12 @@ class LXC(object): if template_options: command.append(' -- %s' % template_options) - print " ".join(command) + print(" ".join(command)) print # create = subprocess.check_call(command, shell=True) create = subprocess.check_call(" ".join(command), shell=True) print - print create + print(create) print # if create == 0: diff --git a/SWSCloudNode/compute/qemu/qemu.py b/SWSCloudNode/compute/qemu/qemu.py index c7bac46..f58f77f 100644 --- a/SWSCloudNode/compute/qemu/qemu.py +++ b/SWSCloudNode/compute/qemu/qemu.py @@ -83,7 +83,7 @@ class Qemu: try: action.create() except: - print conn.virConnGetLastError() + print(conn.virConnGetLastError()) return False return True @@ -99,7 +99,7 @@ class Qemu: try: action.destroy() except: - print conn.virConnGetLastError() + print(conn.virConnGetLastError()) return False return True diff --git a/SWSCloudNode/settings.py b/SWSCloudNode/settings.py index 91edf2e..f6fa910 100644 --- a/SWSCloudNode/settings.py +++ b/SWSCloudNode/settings.py @@ -2,15 +2,15 @@ import sys import os -import ConfigParser +from configparser import ConfigParser from .logger import logging -default_file = '/etc/sws/cloud/node.ini' +default_file = '/etc/nativecloud/agent.ini' -settings_file = os.getenv('CLOUD_SETTINGS_FILE', default_file) +settings_file = os.getenv('CONFIG', default_file) # setting file read -settings = ConfigParser.ConfigParser() +settings = ConfigParser() if os.path.exists(settings_file): settings.read(settings_file) diff --git a/SWSCloudNode/tasks.py b/SWSCloudNode/tasks.py index fd29298..d1edcd7 100644 --- a/SWSCloudNode/tasks.py +++ b/SWSCloudNode/tasks.py @@ -2,11 +2,10 @@ import os import subprocess -import commands +# import commands import requests from SWSCloudNode.logger import logging from SWSCloudNode.settings import settings -from SWSCloudNode.logger import logging ALLOWED_TASKS = [ @@ -34,9 +33,12 @@ class Tasks: logging.error('no connection with %s' % self.endpoint) return None else: + if response.status_code == 204: + logging.info(f"Status code: {response.status_code}, {response.text}") + return None if response.status_code == 200: return response.json() - logging.error("Unexpected status code: %d" % response.status_code) + logging.error(f"Unexpected status code: {response.status_code}, {response.text}") return None def interface2ip(self): @@ -66,8 +68,8 @@ class Tasks: def container_start(self, task): logging.debug("container_start") - print "================ " - print task + print("================ ") + print(task) lxc.lxc().start(task['parameters']['hostname']) # TODO: check status return True @@ -189,7 +191,7 @@ class Tasks: # todo: held job if status not 0 print - print task + print(task) nginx.Nginx().vhost_delete(task['parameters']['container_ip'], task['parameters']['vhost_id']) nginx.Service().reload() @@ -236,8 +238,8 @@ class Tasks: else: if task['status'] == 4: - print "auth fail" + print("auth fail") else: - print "structure version not supported" + print("structure version not supported") return None diff --git a/setup.py b/setup.py index 2a19c5a..5831e51 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,9 @@ -# coding: utf-8 from setuptools import setup setup( name='SWSCloudNode', - version='3.3.2', + version='4.0.1', author='Vyacheslav Anzhiganov', author_email='vanzhiganov@ya.ru', packages=[ @@ -19,7 +18,7 @@ setup( ], install_requires=[ 'requests', - 'netaddr==0.7.18', + 'netaddr>=0.7.18', 'libvirt-python>=1.3.1', ], ) diff --git a/test.py b/test.py deleted file mode 100644 index c860caa..0000000 --- a/test.py +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env python -# coding: utf-8 - -from SWSCloudNode.qemu import QEMU - -print QEMU().list()