up
This commit is contained in:
parent
45bee9a7b3
commit
88aa066c30
11 changed files with 41 additions and 32 deletions
5
.rsyncignore
Normal file
5
.rsyncignore
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
.venv
|
||||||
|
.git
|
||||||
|
__pycache__/
|
||||||
|
*.egg-info/
|
||||||
|
venv
|
4
Makefile
Normal file
4
Makefile
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
DEST:=/opt/nativecloud-agent
|
||||||
|
|
||||||
|
sync:
|
||||||
|
rsync -rvz --exclude-from .rsyncignore --delete ./ root@192.168.11.11:/opt/nativecloud-agent/
|
|
@ -4,6 +4,14 @@ Version: 1.0
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
|
### rockylinux 9
|
||||||
|
|
||||||
|
```shell
|
||||||
|
dnf install -y python3-netaddr python3-libvirt python3-requests
|
||||||
|
```
|
||||||
|
|
||||||
|
### ubuntu (old)
|
||||||
|
|
||||||
```
|
```
|
||||||
$ apt-get install sqlite3
|
$ apt-get install sqlite3
|
||||||
$ apt-get install lxc
|
$ apt-get install lxc
|
||||||
|
@ -14,7 +22,6 @@ $ pip install pyparsing
|
||||||
$ apt-get install dnsmasq
|
$ apt-get install dnsmasq
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Setting DNSMASQ
|
## Setting DNSMASQ
|
||||||
|
|
||||||
Uncomment string in file `/etc/dnsmasq.conf`:
|
Uncomment string in file `/etc/dnsmasq.conf`:
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# coding: utf-8
|
|
||||||
|
|
||||||
from SWSCloudNode.settings import settings
|
from SWSCloudNode.settings import settings
|
||||||
from SWSCloudNode.compute.lxc import LXC
|
from SWSCloudNode.compute.lxc import LXC
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
import time
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
@ -30,7 +29,7 @@ class Common:
|
||||||
"""
|
"""
|
||||||
if code == 1:
|
if code == 1:
|
||||||
message = "Invalid JSON-RPC. Unknown RPC version"
|
message = "Invalid JSON-RPC. Unknown RPC version"
|
||||||
print self.time() + " - " + message
|
print(time.time() + " - " + message)
|
||||||
return {"error": {"code": code, "message": message}}
|
return {"error": {"code": code, "message": message}}
|
||||||
|
|
||||||
def settings_node(self):
|
def settings_node(self):
|
||||||
|
@ -41,7 +40,7 @@ class Common:
|
||||||
with open('/etc/gocloud/node/node.json') as nodesettings_file:
|
with open('/etc/gocloud/node/node.json') as nodesettings_file:
|
||||||
conf = json.load(nodesettings_file)
|
conf = json.load(nodesettings_file)
|
||||||
else:
|
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)
|
sys.exit(2)
|
||||||
|
|
||||||
return conf
|
return conf
|
||||||
|
@ -54,7 +53,7 @@ class Common:
|
||||||
with open('/etc/gocloud/node/vmsettings.json') as vmsettings_file:
|
with open('/etc/gocloud/node/vmsettings.json') as vmsettings_file:
|
||||||
conf = json.load(vmsettings_file)
|
conf = json.load(vmsettings_file)
|
||||||
else:
|
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)
|
sys.exit(2)
|
||||||
|
|
||||||
return conf
|
return conf
|
||||||
|
|
|
@ -248,12 +248,12 @@ class LXC(object):
|
||||||
if template_options:
|
if template_options:
|
||||||
command.append(' -- %s' % template_options)
|
command.append(' -- %s' % template_options)
|
||||||
|
|
||||||
print " ".join(command)
|
print(" ".join(command))
|
||||||
print
|
print
|
||||||
# create = subprocess.check_call(command, shell=True)
|
# create = subprocess.check_call(command, shell=True)
|
||||||
create = subprocess.check_call(" ".join(command), shell=True)
|
create = subprocess.check_call(" ".join(command), shell=True)
|
||||||
print
|
print
|
||||||
print create
|
print(create)
|
||||||
print
|
print
|
||||||
|
|
||||||
# if create == 0:
|
# if create == 0:
|
||||||
|
|
|
@ -83,7 +83,7 @@ class Qemu:
|
||||||
try:
|
try:
|
||||||
action.create()
|
action.create()
|
||||||
except:
|
except:
|
||||||
print conn.virConnGetLastError()
|
print(conn.virConnGetLastError())
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -99,7 +99,7 @@ class Qemu:
|
||||||
try:
|
try:
|
||||||
action.destroy()
|
action.destroy()
|
||||||
except:
|
except:
|
||||||
print conn.virConnGetLastError()
|
print(conn.virConnGetLastError())
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -2,15 +2,15 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import ConfigParser
|
from configparser import ConfigParser
|
||||||
from .logger import logging
|
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
|
# setting file read
|
||||||
settings = ConfigParser.ConfigParser()
|
settings = ConfigParser()
|
||||||
if os.path.exists(settings_file):
|
if os.path.exists(settings_file):
|
||||||
settings.read(settings_file)
|
settings.read(settings_file)
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,10 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import commands
|
# import commands
|
||||||
import requests
|
import requests
|
||||||
from SWSCloudNode.logger import logging
|
from SWSCloudNode.logger import logging
|
||||||
from SWSCloudNode.settings import settings
|
from SWSCloudNode.settings import settings
|
||||||
from SWSCloudNode.logger import logging
|
|
||||||
|
|
||||||
|
|
||||||
ALLOWED_TASKS = [
|
ALLOWED_TASKS = [
|
||||||
|
@ -34,9 +33,12 @@ class Tasks:
|
||||||
logging.error('no connection with %s' % self.endpoint)
|
logging.error('no connection with %s' % self.endpoint)
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
|
if response.status_code == 204:
|
||||||
|
logging.info(f"Status code: {response.status_code}, {response.text}")
|
||||||
|
return None
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
return response.json()
|
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
|
return None
|
||||||
|
|
||||||
def interface2ip(self):
|
def interface2ip(self):
|
||||||
|
@ -66,8 +68,8 @@ class Tasks:
|
||||||
|
|
||||||
def container_start(self, task):
|
def container_start(self, task):
|
||||||
logging.debug("container_start")
|
logging.debug("container_start")
|
||||||
print "================ "
|
print("================ ")
|
||||||
print task
|
print(task)
|
||||||
lxc.lxc().start(task['parameters']['hostname'])
|
lxc.lxc().start(task['parameters']['hostname'])
|
||||||
# TODO: check status
|
# TODO: check status
|
||||||
return True
|
return True
|
||||||
|
@ -189,7 +191,7 @@ class Tasks:
|
||||||
# todo: held job if status not 0
|
# todo: held job if status not 0
|
||||||
|
|
||||||
print
|
print
|
||||||
print task
|
print(task)
|
||||||
|
|
||||||
nginx.Nginx().vhost_delete(task['parameters']['container_ip'], task['parameters']['vhost_id'])
|
nginx.Nginx().vhost_delete(task['parameters']['container_ip'], task['parameters']['vhost_id'])
|
||||||
nginx.Service().reload()
|
nginx.Service().reload()
|
||||||
|
@ -236,8 +238,8 @@ class Tasks:
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if task['status'] == 4:
|
if task['status'] == 4:
|
||||||
print "auth fail"
|
print("auth fail")
|
||||||
else:
|
else:
|
||||||
print "structure version not supported"
|
print("structure version not supported")
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
5
setup.py
5
setup.py
|
@ -1,10 +1,9 @@
|
||||||
# coding: utf-8
|
|
||||||
|
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='SWSCloudNode',
|
name='SWSCloudNode',
|
||||||
version='3.3.2',
|
version='4.0.1',
|
||||||
author='Vyacheslav Anzhiganov',
|
author='Vyacheslav Anzhiganov',
|
||||||
author_email='vanzhiganov@ya.ru',
|
author_email='vanzhiganov@ya.ru',
|
||||||
packages=[
|
packages=[
|
||||||
|
@ -19,7 +18,7 @@ setup(
|
||||||
],
|
],
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'requests',
|
'requests',
|
||||||
'netaddr==0.7.18',
|
'netaddr>=0.7.18',
|
||||||
'libvirt-python>=1.3.1',
|
'libvirt-python>=1.3.1',
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
6
test.py
6
test.py
|
@ -1,6 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
# coding: utf-8
|
|
||||||
|
|
||||||
from SWSCloudNode.qemu import QEMU
|
|
||||||
|
|
||||||
print QEMU().list()
|
|
Loading…
Add table
Reference in a new issue