update dependencies and porting for python3
This commit is contained in:
parent
4c4202b346
commit
fceb922d94
30 changed files with 123 additions and 84 deletions
4
.rsyncignore
Normal file
4
.rsyncignore
Normal file
|
@ -0,0 +1,4 @@
|
|||
.venv
|
||||
.git
|
||||
__pycache__/
|
||||
venv
|
4
Makefile
Normal file
4
Makefile
Normal file
|
@ -0,0 +1,4 @@
|
|||
DEST:=/opt/nativecloud
|
||||
|
||||
sync:
|
||||
rsync -rvza --exclude-from .rsyncignore --delete ./ root@192.168.158.136:/opt/nativecloud/
|
10
README.md
10
README.md
|
@ -34,6 +34,12 @@ Statuses:
|
|||
|
||||
_Get containers status_
|
||||
|
||||
`curl -X GET http://127.0.0.1:5000/server_api/containers/status/ -u f411b7d6-bf93-4fcd-91ee-03e5343d0187:b3c9a8b0-95ca-11e5-bec1-28d244e159e9`
|
||||
```shell
|
||||
curl -X GET http://127.0.0.1:5000/server_api/containers/status/ \
|
||||
-u f411b7d6-bf93-4fcd-91ee-03e5343d0187:b3c9a8b0-95ca-11e5-bec1-28d244e159e9
|
||||
```
|
||||
|
||||
`curl -X POST http://127.0.0.1:5000/server_api/containers/status/663b31b4-22b1-4846-bfaf-27d6389beef4 -u f411b7d6-bf93-4fcd-91ee-03e5343d0187:b3c9a8b0-95ca-11e5-bec1-28d244e159e9 -d 'status=0&message="test"'`
|
||||
```shell
|
||||
curl -X POST http://127.0.0.1:5000/server_api/containers/status/663b31b4-22b1-4846-bfaf-27d6389beef4 \
|
||||
-u f411b7d6-bf93-4fcd-91ee-03e5343d0187:b3c9a8b0-95ca-11e5-bec1-28d244e159e9 -d 'status=0&message="test"'
|
||||
```
|
|
@ -167,7 +167,7 @@ def ips_index():
|
|||
def ips_create():
|
||||
#
|
||||
if request.method == "POST":
|
||||
print request.form
|
||||
print(request.form)
|
||||
if ControllerManageIPs().is_valid_ipv4_address(request.form['ipv4'])\
|
||||
and ControllerManageIPs().is_valid_ipv4_address(request.form['ipv4_gateway']):
|
||||
ControllerManageIPs().item_create(
|
||||
|
@ -203,7 +203,7 @@ def ips_create():
|
|||
def ips_edit(ip_id):
|
||||
#
|
||||
if request.method == 'POST':
|
||||
print request.form
|
||||
print(request.form)
|
||||
# if ControllerManageIPs().is_valid_ipv4_address(request.form['ipv4'])\
|
||||
# and ControllerManageIPs().is_valid_ipv4_address(request.form['ipv4_gateway']):
|
||||
ControllerManageIPs().item_update(
|
||||
|
@ -235,7 +235,7 @@ def ips_delete():
|
|||
@requires_login
|
||||
def servers_create():
|
||||
if request.method == "POST":
|
||||
print request.form
|
||||
print(request.form)
|
||||
params = {
|
||||
'datacenter_id': request.form['datacenter_id'],
|
||||
'server_id': uuid4(),
|
||||
|
|
|
@ -43,7 +43,7 @@ app.register_blueprint(view_administrator_compute_containers)
|
|||
|
||||
# @app.errorhandler(500)
|
||||
# def page_not_found(e):
|
||||
# print e
|
||||
# print(e)
|
||||
# return render_template('errors/500.html'), 500
|
||||
|
||||
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
# coding: utf-8
|
||||
|
||||
import sys
|
||||
import os
|
||||
import ConfigParser
|
||||
from configparser import ConfigParser
|
||||
|
||||
__config_file__ = os.getenv('CLOUD_CONFIG_FILE', '/etc/sws/cloud/core.ini')
|
||||
__config_file__ = os.getenv('CONFIG', '/etc/sws/cloud/core.ini')
|
||||
|
||||
# setting file read
|
||||
config = ConfigParser.ConfigParser()
|
||||
config = ConfigParser()
|
||||
if os.path.exists(__config_file__):
|
||||
config.read(__config_file__)
|
||||
|
||||
|
|
|
@ -222,7 +222,7 @@ class Datacenters:
|
|||
"status": i.status
|
||||
}
|
||||
dcs['items'].append(dc)
|
||||
# print i
|
||||
# print(i)
|
||||
return dcs
|
||||
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ class ControllerContainers:
|
|||
)
|
||||
except Exception as e:
|
||||
# TODO: write to log
|
||||
print e
|
||||
print(e)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ class ControllerManageUsers:
|
|||
models.UsersBalance
|
||||
)
|
||||
for j in jj:
|
||||
print j.usersbalance.balance
|
||||
print(j.usersbalance.balance)
|
||||
return {
|
||||
'total': len(jj),
|
||||
'items': jj
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# coding: utf-8
|
||||
|
||||
import logging
|
||||
import os
|
||||
from flask import Flask, g, render_template
|
||||
from flask_babel import Babel
|
||||
|
@ -42,7 +42,7 @@ if app.config.get('THEME_STATIC_FOLDER', False):
|
|||
static_folder = app.config['THEME_STATIC_FOLDER']
|
||||
if static_folder[0] != '/':
|
||||
static_folder = os.path.join(app.root_path, 'static', static_folder)
|
||||
print static_folder
|
||||
# print(static_folder)
|
||||
# Unlike templates, to serve static files from multiples folders we
|
||||
# need flask-multistatic
|
||||
# app.static_folder = [static_folder, os.path.join(app.root_path, 'static')]
|
||||
|
@ -90,17 +90,20 @@ def page_not_found(e):
|
|||
|
||||
@app.errorhandler(500)
|
||||
def page_not_found(e):
|
||||
print e
|
||||
print(e)
|
||||
return render_template('errors/500.html'), 500
|
||||
|
||||
|
||||
@app.before_request
|
||||
def before_request():
|
||||
g.settings = dict()
|
||||
# извлекаем настройки и определяем их в глобальную переменную
|
||||
for setting in models.Settings.select(models.Settings.key, models.Settings.val).execute():
|
||||
g.settings[setting.key] = setting.val
|
||||
|
||||
try:
|
||||
# извлекаем настройки и определяем их в глобальную переменную
|
||||
for setting in models.Settings.select(models.Settings.key, models.Settings.val).execute():
|
||||
g.settings[setting.key] = setting.val
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
# exit(1)
|
||||
|
||||
@app.before_first_request
|
||||
def before_first_request():
|
||||
|
|
|
@ -23,7 +23,7 @@ def view(document_name):
|
|||
if not os.path.exists('docs/%s.md' % document_name):
|
||||
return redirect(url_for('homepage.index'))
|
||||
#
|
||||
print document_name
|
||||
print(document_name)
|
||||
doc_markdown = u''
|
||||
for ss in file('docs/%s.md' % document_name, 'r'):
|
||||
doc_markdown += ss.decode('UTF-8')
|
||||
|
|
2
cloud-admin-add.py
Normal file → Executable file
2
cloud-admin-add.py
Normal file → Executable file
|
@ -32,6 +32,6 @@ models.database.connect()
|
|||
if models.Admins.select().where(models.Admins.email == args.email).count() == 0:
|
||||
models.Admins.create(id=admin_id, email=admin_email, password=admin_password, status=1)
|
||||
else:
|
||||
print "already exists"
|
||||
print("already exists")
|
||||
|
||||
models.database.close()
|
||||
|
|
12
cloud-admin-ls.py
Normal file → Executable file
12
cloud-admin-ls.py
Normal file → Executable file
|
@ -9,13 +9,13 @@ __author__ = 'vanzhiganov'
|
|||
admins_total = models.Admins.select().count()
|
||||
admins_items = models.Admins.select()
|
||||
|
||||
print "Total admins: %i" % admins_total
|
||||
print("Total admins: %i" % admins_total)
|
||||
|
||||
if admins_total == 0:
|
||||
print ''
|
||||
print('')
|
||||
else:
|
||||
print 'List:'
|
||||
print('List:')
|
||||
for item in admins_items:
|
||||
print '%s\t%s\t%s' % (item.id, item.email, item.status)
|
||||
print '---'
|
||||
print 'For create a new admin account use command "procdn-admin-add --email <email> --password <password>"'
|
||||
print('%s\t%s\t%s' % (item.id, item.email, item.status))
|
||||
print('---')
|
||||
print('For create a new admin account use command "procdn-admin-add --email <email> --password <password>"')
|
||||
|
|
8
cloud-admin-password.py
Normal file → Executable file
8
cloud-admin-password.py
Normal file → Executable file
|
@ -21,10 +21,10 @@ admin_email = args.email
|
|||
admin_password = md5(args.password).hexdigest()
|
||||
|
||||
if models.Admins.select().where(models.Admins.email == args.email).count() == 0:
|
||||
print "Admin account with email '%s' not exists." % admin_email
|
||||
print '---'
|
||||
print 'For create a new admin account use command "procdn-admin-add --email <email> --password <password>"'
|
||||
print("Admin account with email '%s' not exists." % admin_email)
|
||||
print('---')
|
||||
print('For create a new admin account use command "procdn-admin-add --email <email> --password <password>"')
|
||||
else:
|
||||
query = models.Admins.update(password=admin_password).where(models.Admins.email == admin_email)
|
||||
query.execute()
|
||||
print 'Password updated.'
|
||||
print('Password updated.')
|
||||
|
|
10
cloud-cron-balance.py
Normal file → Executable file
10
cloud-cron-balance.py
Normal file → Executable file
|
@ -8,13 +8,13 @@ from SWSCloudCore.controllers.vms import ControllerVMS
|
|||
nb = models.Settings.get_item('NEGATIVE_BALANCE')
|
||||
|
||||
if int(models.Settings.get_item('SERVICE_VMS_ENABLE')) == 1:
|
||||
print 'total vms:', models.Vms.select().where(models.Vms.status == 1).count()
|
||||
print('total vms:', models.Vms.select().where(models.Vms.status == 1).count())
|
||||
|
||||
for vm in models.Vms.select().where(models.Vms.status == 1):
|
||||
# Высчитываем, сколько стоит виртуальная машина 15 минут
|
||||
price_quarter = vm.plan.price / 30 / 24 / 4
|
||||
|
||||
print dict(id=vm.id, user=vm.user.id, plan=vm.plan.id, cost_mo=vm.plan.price, cost_quarter=price_quarter)
|
||||
print(dict(id=vm.id, user=vm.user.id, plan=vm.plan.id, cost_mo=vm.plan.price, cost_quarter=price_quarter))
|
||||
|
||||
# Списание средств
|
||||
x = models.UsersBalance.update(
|
||||
|
@ -26,14 +26,14 @@ if int(models.Settings.get_item('SERVICE_VMS_ENABLE')) == 1:
|
|||
user_balance = models.UsersBalance.select(
|
||||
models.UsersBalance.balance).where(models.UsersBalance.user == vm.user.id).get().balance
|
||||
if -500 > user_balance and models.Vms.get_state(vm.id) == 1:
|
||||
print "user_balance", user_balance
|
||||
print("user_balance", user_balance)
|
||||
ControllerVMS(vm.user.id).status_set(vm.id, 3)
|
||||
# Создание задания
|
||||
ControllerTasks(vm.user.id).create(vm.datacenter.id, vm.server.id, 'vm_stop', 0, vm_id=vm.id)
|
||||
|
||||
|
||||
if int(models.Settings.get_item('SERVICE_CONTAINERS_ENABLE')) == 1:
|
||||
print 'total containers:', models.Containers.select().count()
|
||||
print('total containers:', models.Containers.select().count())
|
||||
for container in models.Containers.select():
|
||||
container_state = models.ContainersStatisticsState.select().where(
|
||||
models.ContainersStatisticsState.container == container.id
|
||||
|
@ -43,7 +43,7 @@ if int(models.Settings.get_item('SERVICE_CONTAINERS_ENABLE')) == 1:
|
|||
# # Высчитываем, сколько стоит виртуальная машина 15 минут
|
||||
price_quarter = min_price / 30 / 24 / 4
|
||||
#
|
||||
# print dict(id=vm.id, user=vm.user.id, plan=vm.plan.id, cost_mo=vm.plan.price, cost_quarter=price_quarter)
|
||||
# print(dict(id=vm.id, user=vm.user.id, plan=vm.plan.id, cost_mo=vm.plan.price, cost_quarter=price_quarter))
|
||||
#
|
||||
# Списание средств
|
||||
x = models.UsersBalance.update(
|
||||
|
|
0
cloud-db-init.py
Normal file → Executable file
0
cloud-db-init.py
Normal file → Executable file
2
cloud-dc-add.py
Normal file → Executable file
2
cloud-dc-add.py
Normal file → Executable file
|
@ -28,4 +28,4 @@ if models.DataCenters.select().where(
|
|||
status=1
|
||||
)
|
||||
else:
|
||||
print "Data center with code '%s' already exists." % args.code
|
||||
print("Data center with code '%s' already exists." % args.code)
|
||||
|
|
12
cloud-dc-ls.py
Normal file → Executable file
12
cloud-dc-ls.py
Normal file → Executable file
|
@ -25,13 +25,13 @@ x = models.Ips.select().join(models.Servers).where(
|
|||
).first()
|
||||
|
||||
|
||||
print 'total: %s' % total
|
||||
print 'items: '
|
||||
print('total: %s' % total)
|
||||
print('items: ')
|
||||
|
||||
for item in items:
|
||||
print 'id: %s code: %s name: %s country: %s, city: %s, status: %s' % (
|
||||
print('id: %s code: %s name: %s country: %s, city: %s, status: %s' % (
|
||||
item.id, item.code, item.name, item.country, item.city, item.status
|
||||
)
|
||||
))
|
||||
|
||||
print '---'
|
||||
print 'if you want to add a new data center, use cli-dc-add.py --'
|
||||
print('---')
|
||||
print('if you want to add a new data center, use cli-dc-add.py --')
|
||||
|
|
2
cloud-invoicer.py
Normal file → Executable file
2
cloud-invoicer.py
Normal file → Executable file
|
@ -169,7 +169,7 @@ html = u"""
|
|||
</html>
|
||||
"""
|
||||
|
||||
print type(html)
|
||||
print(type(html))
|
||||
pdf = MyFPDF()
|
||||
# First page
|
||||
pdf.add_page()
|
||||
|
|
0
cloud-invoicer2.py
Normal file → Executable file
0
cloud-invoicer2.py
Normal file → Executable file
2
cloud-ip-add.py
Normal file → Executable file
2
cloud-ip-add.py
Normal file → Executable file
|
@ -30,5 +30,5 @@ if success:
|
|||
args.datacenter, args.server, args.ipv4, args.ipv4_gateway, args.ipv6, args.ipv6_gateway, args.status
|
||||
)
|
||||
else:
|
||||
print 'fail'
|
||||
print('fail')
|
||||
# print "Admin account with email '%s' already exists." % args
|
||||
|
|
0
cloud-runserver-admin.py
Normal file → Executable file
0
cloud-runserver-admin.py
Normal file → Executable file
1
cloud-runserver.py
Normal file → Executable file
1
cloud-runserver.py
Normal file → Executable file
|
@ -1,5 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
from SWSCloudWeb import app
|
||||
|
||||
|
|
2
cloud-server-add.py
Normal file → Executable file
2
cloud-server-add.py
Normal file → Executable file
|
@ -21,5 +21,5 @@ if not ControllerManageServer().check_exists(args.ip, None, args.hostname):
|
|||
args.ip, None, args.status
|
||||
)
|
||||
else:
|
||||
print 'fail'
|
||||
print('fail')
|
||||
# print "Admin account with email '%s' already exists." % args
|
||||
|
|
8
cloud-server-ls.py
Normal file → Executable file
8
cloud-server-ls.py
Normal file → Executable file
|
@ -16,10 +16,10 @@ items = models.Servers.select().where(
|
|||
models.Servers.status == args.status
|
||||
)
|
||||
|
||||
print 'total: %s' % total
|
||||
print 'items: '
|
||||
print('total: %s' % total)
|
||||
print('items: ')
|
||||
|
||||
for item in items:
|
||||
print 'id: %s dc: %s status: %s ip: %s hostname: %s' % (
|
||||
print('id: %s dc: %s status: %s ip: %s hostname: %s' % (
|
||||
item.id, item.datacenter.id, item.status, item.ip, item.hostname
|
||||
)
|
||||
))
|
||||
|
|
2
cloud-settings-init.py
Normal file → Executable file
2
cloud-settings-init.py
Normal file → Executable file
|
@ -7,7 +7,7 @@ def create_key(key, val=''):
|
|||
if models.Settings.select().where(models.Settings.key == key).count() == 0:
|
||||
models.Settings.create(key=key, val=val)
|
||||
else:
|
||||
print 'key %s already exists' % key
|
||||
print('key %s already exists' % key)
|
||||
|
||||
|
||||
create_key('bonus', '300')
|
||||
|
|
0
cloud-settings.py
Normal file → Executable file
0
cloud-settings.py
Normal file → Executable file
|
@ -1,19 +1,23 @@
|
|||
[uwsgi]
|
||||
virtualenv = /home/gocloud/env
|
||||
|
||||
env = HOME=/opt/nativecloud/.venv
|
||||
env = CONFIG=/opt/nativecloud/extra/settings.origin.ini
|
||||
|
||||
chdir = /opt/nativecloud
|
||||
|
||||
;for http
|
||||
;protocol = http
|
||||
;socket = 127.0.0.1:8080
|
||||
protocol = http
|
||||
socket = 0.0.0.0:8080
|
||||
|
||||
; for unix-socket
|
||||
socket = /var/run/sws/gocloud_web.sock
|
||||
chmod-socket = 777
|
||||
; socket = /var/run/nativecloud-web.sock
|
||||
; chmod-socket = 777
|
||||
|
||||
module = SWSCloudWeb:app
|
||||
|
||||
master = true
|
||||
processes = 2
|
||||
|
||||
vacuum = true
|
||||
|
||||
die-on-term = true
|
||||
|
||||
thunder-lock = true
|
||||
enable-threads = true
|
38
requirements.txt
Normal file
38
requirements.txt
Normal file
|
@ -0,0 +1,38 @@
|
|||
async-timeout==5.0.1
|
||||
babel==2.16.0
|
||||
certifi==2024.8.30
|
||||
charset-normalizer==3.4.0
|
||||
click==8.1.7
|
||||
configparser==7.1.0
|
||||
dateutils==0.6.12
|
||||
decorator==5.1.1
|
||||
ecdsa==0.19.0
|
||||
Flask==0.12.5
|
||||
Flask-Babel==0.9
|
||||
Flask-HTTPAuth==3.1.1
|
||||
Flask-Markdown==0.3
|
||||
flask-multistatic==1.0
|
||||
flask-peewee==0.6.0
|
||||
idna==3.10
|
||||
importlib_metadata==8.5.0
|
||||
itsdangerous==2.0.1
|
||||
Jinja2==2.8
|
||||
Markdown==3.7
|
||||
MarkupSafe==2.0.1
|
||||
peewee==2.8.0
|
||||
psycopg2-binary==2.9.10
|
||||
pycrypto==2.6.1
|
||||
python-dateutil==2.9.0.post0
|
||||
pytz==2024.2
|
||||
pyuwsgi==2.0.28.post1
|
||||
redis==5.2.1
|
||||
requests==2.32.3
|
||||
six==1.17.0
|
||||
speaklater==1.3
|
||||
sshpubkeys==1.0.6
|
||||
urllib3==2.2.3
|
||||
validators==0.10
|
||||
Werkzeug==0.16.1
|
||||
wtf-peewee==0.2.6
|
||||
WTForms==3.2.1
|
||||
zipp==3.21.0
|
27
setup.py
27
setup.py
|
@ -1,7 +1,9 @@
|
|||
# coding: utf-8
|
||||
|
||||
import os
|
||||
from setuptools import setup
|
||||
|
||||
with open('requirements.txt') as f:
|
||||
required = f.read().splitlines()
|
||||
|
||||
setup(
|
||||
name='SWSCloudCore',
|
||||
version='2.7.10',
|
||||
|
@ -145,24 +147,5 @@ setup(
|
|||
# billing
|
||||
'cloud-cron-balance.py',
|
||||
],
|
||||
install_requires=[
|
||||
'Flask==0.10',
|
||||
'Flask-Markdown==0.3',
|
||||
'Flask-Babel==0.9',
|
||||
'flask-peewee==0.6.0',
|
||||
'flask-multistatic',
|
||||
'Flask-And-Redis',
|
||||
'Jinja2==2.8',
|
||||
'peewee==2.8',
|
||||
'validators==0.10',
|
||||
'psycopg2==2.6.1',
|
||||
'configparser',
|
||||
'flask_httpauth==3.1.1',
|
||||
'requests==2.7',
|
||||
'uWSGI==2.0.11.1',
|
||||
'wsgiref==0.1.2',
|
||||
'sshpubkeys==1.0.6',
|
||||
'dateutils',
|
||||
'redis',
|
||||
]
|
||||
install_requires=required
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue