up
This commit is contained in:
parent
3ca08bfb37
commit
f26e36daf1
13 changed files with 161 additions and 38 deletions
|
@ -1 +1,9 @@
|
||||||
__author__ = 'vanzhiganov'
|
from app import models
|
||||||
|
|
||||||
|
|
||||||
|
class ControllerManageIPs:
|
||||||
|
def items_get(self):
|
||||||
|
return {
|
||||||
|
'total': models.Ips.select().count(),
|
||||||
|
'items': models.Ips.select()
|
||||||
|
}
|
||||||
|
|
6
app/cloud/controllers/server_api/server.py
Normal file
6
app/cloud/controllers/server_api/server.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
from app import models
|
||||||
|
|
||||||
|
|
||||||
|
class ControllerServerServerAPI:
|
||||||
|
def report_set(self):
|
||||||
|
pass
|
|
@ -19,6 +19,7 @@ from app.cloud.controllers.datacenters.manage import ControllerManageDatacenters
|
||||||
from app.cloud.controllers.servers.manage import ControllerManageServer
|
from app.cloud.controllers.servers.manage import ControllerManageServer
|
||||||
from app.cloud.controllers.billing import ControllerBilling
|
from app.cloud.controllers.billing import ControllerBilling
|
||||||
from app.cloud.controllers.containers.manage import ControllerManageContainers
|
from app.cloud.controllers.containers.manage import ControllerManageContainers
|
||||||
|
from app.cloud.controllers.ips.manage import ControllerManageIPs
|
||||||
|
|
||||||
viewAdministrator = Blueprint('administrator', __name__, url_prefix='/administrator')
|
viewAdministrator = Blueprint('administrator', __name__, url_prefix='/administrator')
|
||||||
|
|
||||||
|
@ -128,7 +129,10 @@ def containers():
|
||||||
return redirect(url_for("administrator.logout"))
|
return redirect(url_for("administrator.logout"))
|
||||||
# формируем список правил
|
# формируем список правил
|
||||||
rules_items = ControllerManageContainers().get_all_items()
|
rules_items = ControllerManageContainers().get_all_items()
|
||||||
return render_template('administrator/containers/index.html', rules=rules_items)
|
return render_template(
|
||||||
|
'administrator/containers/index.html',
|
||||||
|
containers=rules_items
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@viewAdministrator.route('/payments')
|
@viewAdministrator.route('/payments')
|
||||||
|
@ -220,10 +224,26 @@ def servers_index():
|
||||||
# auth user
|
# auth user
|
||||||
if not ControllerAdministrators().auth(session['admin_email'], session['admin_password']):
|
if not ControllerAdministrators().auth(session['admin_email'], session['admin_password']):
|
||||||
return redirect(url_for("administrator.logout"))
|
return redirect(url_for("administrator.logout"))
|
||||||
|
#
|
||||||
|
return render_template(
|
||||||
|
'administrator/servers/index.html',
|
||||||
|
servers=ControllerManageServer().items_get()
|
||||||
|
)
|
||||||
|
|
||||||
servers_items = ControllerManageServer().items_get()
|
|
||||||
|
|
||||||
return render_template('administrator/servers/index.html', servers=servers_items)
|
@viewAdministrator.route('/ips/')
|
||||||
|
def ips_index():
|
||||||
|
# check session
|
||||||
|
if not ControllerAdministrators().check_session():
|
||||||
|
return redirect(url_for("administrator.logout"))
|
||||||
|
# auth user
|
||||||
|
if not ControllerAdministrators().auth(session['admin_email'], session['admin_password']):
|
||||||
|
return redirect(url_for("administrator.logout"))
|
||||||
|
#
|
||||||
|
return render_template(
|
||||||
|
'administrator/ips/index.html',
|
||||||
|
ips=ControllerManageIPs().items_get()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@viewAdministrator.route('/servers/create', methods=['GET', 'POST'])
|
@viewAdministrator.route('/servers/create', methods=['GET', 'POST'])
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import uuid
|
# import uuid
|
||||||
|
# from flask import Response
|
||||||
from flask import Response
|
|
||||||
from flask import request
|
from flask import request
|
||||||
from flask import Blueprint
|
from flask import Blueprint
|
||||||
from flask import jsonify
|
from flask import jsonify
|
||||||
|
# from app import models
|
||||||
from app import models
|
|
||||||
from app.cloud.controllers.tasks.server import ControllerTasksServer
|
from app.cloud.controllers.tasks.server import ControllerTasksServer
|
||||||
# from .controllers import ControllerRulesStatistics
|
# from .controllers import ControllerRulesStatistics
|
||||||
|
|
||||||
|
@ -61,3 +59,28 @@ def task_status_update():
|
||||||
server_api.update(task_id, status)
|
server_api.update(task_id, status)
|
||||||
|
|
||||||
return jsonify({'status': 0})
|
return jsonify({'status': 0})
|
||||||
|
|
||||||
|
|
||||||
|
@viewServerAPI.route('/report/container_status', methods=['POST'])
|
||||||
|
def report_container_status():
|
||||||
|
node_id = request.args.get('node_id')
|
||||||
|
node_secret = request.args.get('node_secret')
|
||||||
|
server_api = ControllerTasksServer(node_id, node_secret)
|
||||||
|
# auth request
|
||||||
|
if not server_api.auth():
|
||||||
|
# status: 403 - access denied
|
||||||
|
return jsonify({'status': 403})
|
||||||
|
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"cpu_use": 644394623336,
|
||||||
|
"memory_use": 614473728,
|
||||||
|
"link": "vethB2RLMU"
|
||||||
|
"tx_bytes": 48337383,
|
||||||
|
"rx_bytes": 1049439046,
|
||||||
|
"total_bytes": 1097776429
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
status = json.loads(request.form['status'])
|
||||||
|
|
||||||
|
return jsonify({})
|
||||||
|
|
|
@ -77,6 +77,8 @@ class UsersSecrets(PgSQLModel):
|
||||||
user = ForeignKeyField(Users, related_name='userssecrets')
|
user = ForeignKeyField(Users, related_name='userssecrets')
|
||||||
secret = CharField(unique=True, null=False)
|
secret = CharField(unique=True, null=False)
|
||||||
acl = TextField()
|
acl = TextField()
|
||||||
|
# 0 - inactive
|
||||||
|
# 1 - active
|
||||||
status = IntegerField()
|
status = IntegerField()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,7 @@
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="{{ url_for('administrator.datacenters') }}"><i class="fa fa-fw fa-table"></i> Datacenters</a></li>
|
<li><a href="{{ url_for('administrator.datacenters') }}"><i class="fa fa-fw fa-table"></i> Datacenters</a></li>
|
||||||
<li><a href="{{ url_for('administrator.servers_index') }}"><i class="fa fa-fw fa-table"></i> Servers</a></li>
|
<li><a href="{{ url_for('administrator.servers_index') }}"><i class="fa fa-fw fa-table"></i> Servers</a></li>
|
||||||
<li><a href="{{ url_for('administrator.servers_index') }}"><i class="fa fa-fw fa-table"></i> IPs</a></li>
|
<li><a href="{{ url_for('administrator.ips_index') }}"><i class="fa fa-fw fa-table"></i> IPs</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li><a href="{{ url_for('administrator.settings_index') }}"><i class="fa fa-fw fa-table"></i> Settings</a></li>
|
<li><a href="{{ url_for('administrator.settings_index') }}"><i class="fa fa-fw fa-table"></i> Settings</a></li>
|
||||||
|
|
|
@ -1,35 +1,38 @@
|
||||||
{% extends 'administrator/_layout.auth.html' %}
|
{% extends 'administrator/_layout.auth.html' %}
|
||||||
|
|
||||||
{% block title %}Rules{% endblock %}
|
{% block title %}Containers{% endblock %}
|
||||||
|
|
||||||
{% block subtitle %}Rules list{% endblock %}
|
{% block subtitle %}Containers list{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
Total: {{ rules.total }}
|
Total: {{ containers.total }}
|
||||||
<table class="table table-bordered">
|
<table class="table table-bordered">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Id</th>
|
<th>Id</th>
|
||||||
<th>Email</th>
|
<th>Datacenter</th>
|
||||||
|
<th>Server</th>
|
||||||
|
<th>User</th>
|
||||||
|
<th>IPv4</th>
|
||||||
|
<th>IPv6</th>
|
||||||
<th>Status</th>
|
<th>Status</th>
|
||||||
<th>Source</th>
|
|
||||||
<th>Alias</th>
|
|
||||||
<th>Action</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% if rules.total == 0 %}
|
{% if containers.total == 0 %}
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6">Нет ни одного правила</td>
|
<td colspan="6">Нет ни одного правила</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% else %}
|
{% else %}
|
||||||
{% for rule in rules['items'] %}
|
{% for container in containers['items'] %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ rule.id }}</td>
|
<td>{{ container.id }}</td>
|
||||||
<td>{{ rule.user.email }}</td>
|
<td>{{ container.datacenter.name }}</td>
|
||||||
<td>{{ rule.status }}</td>
|
<td>{{ container.server.hostname }}</td>
|
||||||
<td>{{ rule.source }}</td>
|
<td>{{ container.user.email }}</td>
|
||||||
<td>{{ rule.alias }}</td>
|
<td>{{ container.ipv4 }}</td>
|
||||||
|
<td>{{ container.ipv6 }}</td>
|
||||||
|
<td>{{ container.status }}</td>
|
||||||
<td><a href="#">Edit</a></td>
|
<td><a href="#">Edit</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
51
app/templates/administrator/ips/index.html
Normal file
51
app/templates/administrator/ips/index.html
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
{% extends 'administrator/_layout.auth.html' %}
|
||||||
|
|
||||||
|
{% block title %}IPs{% endblock %}
|
||||||
|
|
||||||
|
{% block subtitle %}IPs list{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
Total: {{ ips['total'] }}
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Id</th>
|
||||||
|
<th>Data center</th>
|
||||||
|
<th>Server</th>
|
||||||
|
<th>IPv4</th>
|
||||||
|
<th>IPv4 gateway</th>
|
||||||
|
<th>IPv6</th>
|
||||||
|
<th>IPv6 gateway</th>
|
||||||
|
<th>Status</th>
|
||||||
|
<th>Action</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% if ips['total'] == 0 %}
|
||||||
|
<tr>
|
||||||
|
<td colspan="6">Нет ни одного правила</td>
|
||||||
|
</tr>
|
||||||
|
{% else %}
|
||||||
|
{% for ip in ips['items'] %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ ip.id }}</td>
|
||||||
|
<td><a href="#">{{ ip.datacenter.name }}</a></td>
|
||||||
|
<td><a href="#">{{ ip.server.hostname }}</a></td>
|
||||||
|
<td>{{ ip.ipv4 }}</td>
|
||||||
|
<td>{{ ip.ipv4_gateway }}</td>
|
||||||
|
<td>{{ ip.ipv6 }}</td>
|
||||||
|
<td>{{ ip.ipv6_gateway }}</td>
|
||||||
|
<td>
|
||||||
|
{% if ip.status == 0 %}
|
||||||
|
<span class="label label-default">Free</span>
|
||||||
|
{% else %}
|
||||||
|
<span class="label label-primary">Busy</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td><a href="#">Edit</a></td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% endblock %}
|
|
@ -26,7 +26,13 @@
|
||||||
<td>{{ payment.id }}</td>
|
<td>{{ payment.id }}</td>
|
||||||
<td>{{ payment.user.email }}</td>
|
<td>{{ payment.user.email }}</td>
|
||||||
<td>{{ payment.amount }}</td>
|
<td>{{ payment.amount }}</td>
|
||||||
<td>{{ payment.status }}</td>
|
<td>
|
||||||
|
{% if payment.status == 'process' %}
|
||||||
|
<span class="label label-info">{{ payment.status }}</span>
|
||||||
|
{% elif payment.status == 'success' %}
|
||||||
|
<span class="label laber-success">{{ payment.status }}</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
<td>{{ payment.notified }}</td>
|
<td>{{ payment.notified }}</td>
|
||||||
<td>{{ payment.created }}</td>
|
<td>{{ payment.created }}</td>
|
||||||
<td><a href="">edit</a></td>
|
<td><a href="">edit</a></td>
|
||||||
|
|
|
@ -22,7 +22,13 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ user.id }}</td>
|
<td>{{ user.id }}</td>
|
||||||
<td>{{ user.email }}</td>
|
<td>{{ user.email }}</td>
|
||||||
<td>{{ user.status }}</td>
|
<td>
|
||||||
|
{% if user.status == 0 %}
|
||||||
|
<span class="label label-alert">Inactive</span>
|
||||||
|
{% else %}
|
||||||
|
<span class="label label-success">Active</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ url_for('administrator.user_details', user_id=user.id) }}">Edit</a>
|
<a href="{{ url_for('administrator.user_details', user_id=user.id) }}">Edit</a>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -21,3 +21,6 @@ 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
|
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 --'
|
||||||
|
|
|
@ -2,6 +2,7 @@ import argparse
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
from app import models
|
from app import models
|
||||||
|
from app.cloud.controllers.servers.manage import ControllerManageServer
|
||||||
|
|
||||||
__author__ = 'vanzhiganov'
|
__author__ = 'vanzhiganov'
|
||||||
|
|
||||||
|
@ -17,17 +18,10 @@ args = parser.parse_args()
|
||||||
|
|
||||||
server_id = uuid4()
|
server_id = uuid4()
|
||||||
|
|
||||||
if models.Servers.select().where(
|
if not ControllerManageServer().check_exists(args.ip, None, args.hostname):
|
||||||
(models.Servers.ip == args.ip) |
|
ControllerManageServer().item_create(
|
||||||
(models.Servers.hostname == args.hostname)
|
args.datacenter, server_id, args.secret, args.hostname,
|
||||||
).count() == 0:
|
args.ip, None, args.status
|
||||||
models.Servers.create(
|
|
||||||
id=server_id,
|
|
||||||
datacenter=args.datacenter,
|
|
||||||
secret=args.secret,
|
|
||||||
ip=args.ip,
|
|
||||||
hostname=args.hostname,
|
|
||||||
status=args.status
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
print 'fail'
|
print 'fail'
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
Flask==0.10.1
|
Flask==0.10.1
|
||||||
|
Flask-Markdown==0.3
|
||||||
psycopg2==2.6.1
|
psycopg2==2.6.1
|
||||||
requests==2.7.0
|
requests==2.7.0
|
||||||
uWSGI==2.0.11.1
|
uWSGI==2.0.11.1
|
||||||
wsgiref==0.1.2
|
wsgiref==0.1.2
|
||||||
validators
|
validators
|
||||||
sshpubkeys
|
sshpubkeys
|
||||||
|
|
Loading…
Add table
Reference in a new issue