66 API
This commit is contained in:
parent
a5fdada20a
commit
030f26c903
8 changed files with 77 additions and 32 deletions
|
@ -463,13 +463,50 @@ def vms_create():
|
||||||
@api.route('/vms/<uuid:vm_id>', methods=['POST'])
|
@api.route('/vms/<uuid:vm_id>', methods=['POST'])
|
||||||
@auth.login_required
|
@auth.login_required
|
||||||
def vm_actions(vm_id):
|
def vm_actions(vm_id):
|
||||||
# TODO:
|
"""
|
||||||
pass
|
"""
|
||||||
|
# init ...
|
||||||
|
vm = ControllerVMS(g.user_id)
|
||||||
|
# get container details
|
||||||
|
vm_details = vm.get(vm_id=vm_id)
|
||||||
|
|
||||||
|
if request.form.get('action') == "start":
|
||||||
|
if ControllerBilling().get(g.user_id) <= 0:
|
||||||
|
return jsonify(message='no money')
|
||||||
|
|
||||||
|
vm.set_status(vm_id, 2)
|
||||||
|
# Создание задания
|
||||||
|
ControllerTasks(g.user_id).create(
|
||||||
|
datacenter_id=vm_details.datacenter.id,
|
||||||
|
server_id=vm_details.server.id,
|
||||||
|
task='vm_start',
|
||||||
|
status=0,
|
||||||
|
vm_id=vm_details.id
|
||||||
|
)
|
||||||
|
|
||||||
|
if request.form.get('action') == "restart":
|
||||||
|
return jsonify(message='not supported')
|
||||||
|
|
||||||
|
if request.form.get('action') == "stop":
|
||||||
|
vm.status_set(vm_id, 3)
|
||||||
|
# Создание задания
|
||||||
|
ControllerTasks(g.user_id).create(
|
||||||
|
vm_details.datacenter.id,
|
||||||
|
vm_details.server.id,
|
||||||
|
'vm_stop',
|
||||||
|
0,
|
||||||
|
vm_id=vm_id
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@api.route('/vms/<uuid:vm_id>', methods=['DELETE'])
|
@api.route('/vms/<uuid:vm_id>', methods=['DELETE'])
|
||||||
@auth.login_required
|
@auth.login_required
|
||||||
def vm_delete(vm_id):
|
def vm_delete(vm_id):
|
||||||
|
"""
|
||||||
|
Удаление виртуального сервера
|
||||||
|
:param vm_id:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
#
|
#
|
||||||
vms = ControllerVMS(g.user_id)
|
vms = ControllerVMS(g.user_id)
|
||||||
tasks = ControllerTasks(g.user_id)
|
tasks = ControllerTasks(g.user_id)
|
||||||
|
@ -477,10 +514,8 @@ def vm_delete(vm_id):
|
||||||
# if user not have a container then redirect to the container list
|
# if user not have a container then redirect to the container list
|
||||||
if not vms.exists(vm_id):
|
if not vms.exists(vm_id):
|
||||||
return jsonify(message='not exists')
|
return jsonify(message='not exists')
|
||||||
|
|
||||||
# get container details
|
# get container details
|
||||||
vm_details = vms.get(vm_id)
|
vm_details = vms.get(vm_id)
|
||||||
|
|
||||||
# Обновляем статус "5" для правила
|
# Обновляем статус "5" для правила
|
||||||
vms.set_status(vm_id, 5)
|
vms.set_status(vm_id, 5)
|
||||||
# Создание задания
|
# Создание задания
|
||||||
|
@ -492,5 +527,4 @@ def vm_delete(vm_id):
|
||||||
vm_id=vm_id,
|
vm_id=vm_id,
|
||||||
# hostname=vm_details.hostname
|
# hostname=vm_details.hostname
|
||||||
)
|
)
|
||||||
|
|
||||||
return jsonify(status=0, message='ok')
|
return jsonify(status=0, message='ok')
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
# coding: utf-8
|
|
@ -20,7 +20,8 @@ class ControllerCommon:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def generate_password(self, size=14, chars=string.ascii_uppercase + string.digits):
|
@staticmethod
|
||||||
|
def generate_password(size=14, chars=string.ascii_uppercase + string.digits):
|
||||||
return ''.join(random.choice(chars) for _ in range(size))
|
return ''.join(random.choice(chars) for _ in range(size))
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,19 +39,6 @@ class ControllerManagement:
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
class Containers:
|
|
||||||
def init_new_server(self, server_id):
|
|
||||||
rules = self.get_all()
|
|
||||||
|
|
||||||
for rule in rules:
|
|
||||||
if models.RulesServers.select().where(
|
|
||||||
models.RulesServers.server == server_id,
|
|
||||||
models.RulesServers.rule == rule.id
|
|
||||||
).count() == 0:
|
|
||||||
models.RulesServers.create()
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def get_all(self):
|
def get_all(self):
|
||||||
return models.Rules.select()
|
return models.Rules.select()
|
||||||
|
|
||||||
|
@ -291,6 +279,7 @@ class Admins:
|
||||||
|
|
||||||
:param email:
|
:param email:
|
||||||
:param password:
|
:param password:
|
||||||
|
:param status:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
password_hash = md5(password).hexdigest()
|
password_hash = md5(password).hexdigest()
|
||||||
|
@ -305,5 +294,5 @@ class Admins:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_id_by_email(self, email):
|
def get_id_by_email(self, email):
|
||||||
admin = models.Admins.select(models.Admins.id).where(models.Admins.email == email).limit(1)
|
admin = models.Admins.select(models.Admins.id).where(models.Admins.email == email).get()
|
||||||
return admin[0].id
|
return admin.id
|
||||||
|
|
|
@ -254,7 +254,7 @@ def settings(vm_id):
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
if request.form['action'] == 'set_status':
|
if request.form['action'] == 'set_status':
|
||||||
if request.form['status'] == 'inactive':
|
if request.form['action'] == 'stop':
|
||||||
vm.status_set(vm_id, 3)
|
vm.status_set(vm_id, 3)
|
||||||
# Создание задания
|
# Создание задания
|
||||||
ControllerTasks(session['user_id']).create(
|
ControllerTasks(session['user_id']).create(
|
||||||
|
@ -266,7 +266,7 @@ def settings(vm_id):
|
||||||
)
|
)
|
||||||
return redirect(url_for('vms.settings', vm_id=vm_id))
|
return redirect(url_for('vms.settings', vm_id=vm_id))
|
||||||
|
|
||||||
if request.form['status'] == 'active':
|
if request.form.get('action') == 'start':
|
||||||
balance = ControllerBilling().get(session['user_id'])
|
balance = ControllerBilling().get(session['user_id'])
|
||||||
|
|
||||||
if balance <= 0:
|
if balance <= 0:
|
||||||
|
@ -275,7 +275,7 @@ def settings(vm_id):
|
||||||
|
|
||||||
vm.set_status(vm_id, 2)
|
vm.set_status(vm_id, 2)
|
||||||
# Создание задания
|
# Создание задания
|
||||||
ControllerTasks(session['user_id']).create(
|
ControllerTasks(session.get('user_id')).create(
|
||||||
vm_details.datacenter.id,
|
vm_details.datacenter.id,
|
||||||
vm_details.server.id,
|
vm_details.server.id,
|
||||||
'vm_start',
|
'vm_start',
|
||||||
|
|
0
SWSCloudWeb/__init__.py
Normal file
0
SWSCloudWeb/__init__.py
Normal file
19
extra/uwsgi-api.ini
Normal file
19
extra/uwsgi-api.ini
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
[uwsgi]
|
||||||
|
virtualenv = /home/gocloud/env
|
||||||
|
|
||||||
|
;for http
|
||||||
|
;protocol = http
|
||||||
|
;socket = 127.0.0.1:8080
|
||||||
|
|
||||||
|
; for unix-socket
|
||||||
|
socket = /var/run/sws/gocloud_api.sock
|
||||||
|
chmod-socket = 777
|
||||||
|
|
||||||
|
module = SWSCloudAPI:app
|
||||||
|
|
||||||
|
master = true
|
||||||
|
processes = 1
|
||||||
|
|
||||||
|
vacuum = true
|
||||||
|
|
||||||
|
die-on-term = true
|
|
@ -1,20 +1,18 @@
|
||||||
[uwsgi]
|
[uwsgi]
|
||||||
;virtualenv
|
virtualenv = /home/gocloud/env
|
||||||
virtualenv = /var/env/gocloud.ru/
|
|
||||||
;virtualenv=/home/vanzhiganov/env/gocloud_server/
|
|
||||||
|
|
||||||
;for http
|
;for http
|
||||||
;protocol = http
|
;protocol = http
|
||||||
;socket = 127.0.0.1:8080
|
;socket = 127.0.0.1:8080
|
||||||
|
|
||||||
; for unix-socket
|
; for unix-socket
|
||||||
socket = /var/run/procdnru_control.sock
|
socket = /var/run/sws/gocloud.sock
|
||||||
chmod-socket = 770
|
chmod-socket = 777
|
||||||
|
|
||||||
module = app:app
|
module = SWSCloudCore:app
|
||||||
|
|
||||||
master = true
|
master = true
|
||||||
processes = 5
|
processes = 2
|
||||||
|
|
||||||
vacuum = true
|
vacuum = true
|
||||||
|
|
||||||
|
|
6
setup.py
6
setup.py
|
@ -4,12 +4,14 @@ from setuptools import setup
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='SWSCloudCore',
|
name='SWSCloudCore',
|
||||||
version='2.4.11',
|
version='2.5.0',
|
||||||
author='Vyacheslav Anzhiganov',
|
author='Vyacheslav Anzhiganov',
|
||||||
author_email='hello@anzhiganov.com',
|
author_email='hello@anzhiganov.com',
|
||||||
packages=[
|
packages=[
|
||||||
|
# API
|
||||||
'SWSCloudAPI',
|
'SWSCloudAPI',
|
||||||
'SWSCloudAPI.API',
|
'SWSCloudAPI.API',
|
||||||
|
# Core
|
||||||
'SWSCloudCore',
|
'SWSCloudCore',
|
||||||
'SWSCloudCore.controllers',
|
'SWSCloudCore.controllers',
|
||||||
'SWSCloudCore.controllers.administrators',
|
'SWSCloudCore.controllers.administrators',
|
||||||
|
@ -41,6 +43,8 @@ setup(
|
||||||
'SWSCloudCore.views.support',
|
'SWSCloudCore.views.support',
|
||||||
'SWSCloudCore.views.tasks',
|
'SWSCloudCore.views.tasks',
|
||||||
'SWSCloudCore.views.vms',
|
'SWSCloudCore.views.vms',
|
||||||
|
# Web
|
||||||
|
# ...
|
||||||
],
|
],
|
||||||
package_data={
|
package_data={
|
||||||
'SWSCloudCore': [
|
'SWSCloudCore': [
|
||||||
|
|
Loading…
Add table
Reference in a new issue