From c970f0d82a68d8f8f103a07a70f6f3654208ff07 Mon Sep 17 00:00:00 2001 From: deflax Date: Mon, 31 Jul 2017 00:10:08 +0300 Subject: [PATCH] craete seed function phase 2 --- app/main/routes.py | 3 +- app/models.py | 3 - app/templates/main/dashboard.html | 98 +++++++++++++++---------------- app/vmanager/routes.py | 21 +++---- 4 files changed, 59 insertions(+), 66 deletions(-) diff --git a/app/main/routes.py b/app/main/routes.py index 2f8c935..4d1d237 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -77,7 +77,8 @@ def dashboard(): rrd[cubeid] = {} try: query = contact_proxmaster({}, 'vmrrd', cubeid) - except: + except Exception as e: + current_app.logger.error(e) flash('Deploy #{} unreachable. Support is notified'.format(str(cubeid))) send_email(current_app.config['MAIL_USERNAME'], 'Cube {} is unreachable'.format(cubeid), 'vmanager/email/adm_unreachable', user=current_user, cubeid=cubeid) diff --git a/app/models.py b/app/models.py index 764a562..bca1e9e 100644 --- a/app/models.py +++ b/app/models.py @@ -208,15 +208,12 @@ def contact_proxmaster(data, method, cubeid=0): url = current_app.config['PROXMASTER_URL'] data['apikey'] = current_app.config['APIKEY'] data_json = json.dumps(data) - #print('--> {}'.format(data)) if method == 'vmcreate': url = '{}/{}'.format(url, method) else: url = '{}/{}/{}'.format(url, method, cubeid) - db_result = requests.post( url, data=data_json, headers={"content-type": "application/json"}, timeout=30 ) - try: proxjson = db_result.json() #print('proxmaster query {}'.format(str(proxjson))) diff --git a/app/templates/main/dashboard.html b/app/templates/main/dashboard.html index dc77116..f72ceb2 100644 --- a/app/templates/main/dashboard.html +++ b/app/templates/main/dashboard.html @@ -187,60 +187,12 @@ addEventListener("DOMContentLoaded", function() { - + {% endif %} - {% if inv_services != [] %} -
-
-
Services
-

-

- - - - - - - - - - {% for service in inv_services %} - {% if service.enabled == False %} - - {% else %} - {% if service.warning == True %} - - {% else %} - - {% endif %} - {% endif %} - - - - {% if service.enabled == False %} - - {% else %} - {% if service.warning == True %} - - {% else %} - - {% endif %} - {% endif %} - - {% endfor %} - -
CategoryDescriptionLast ChargedTime Left
{{ service.category }}{{ service.description }}{{ moment(service.date_last_charge).format('lll') }} ({{ moment(service.date_last_charge).fromNow() }}){{ service.daysleft }} day(s)
-
- - -
-
-
- {% endif %} {% if inv_domains != [] %}
@@ -317,6 +269,54 @@ addEventListener("DOMContentLoaded", function() {
{% endif %} + {% if inv_services != [] %} +
+
+
Services
+

+

+ + + + + + + + + + {% for service in inv_services %} + {% if service.enabled == False %} + + {% else %} + {% if service.warning == True %} + + {% else %} + + {% endif %} + {% endif %} + + + + {% if service.enabled == False %} + + {% else %} + {% if service.warning == True %} + + {% else %} + + {% endif %} + {% endif %} + + {% endfor %} + +
CategoryDescriptionLast ChargedTime Left
{{ service.category }}{{ service.description }}{{ moment(service.date_last_charge).format('lll') }} ({{ moment(service.date_last_charge).fromNow() }}){{ service.daysleft }} day(s)
+
+ +
+
+
+ {% endif %} + diff --git a/app/vmanager/routes.py b/app/vmanager/routes.py index 5f899c4..9249ae9 100644 --- a/app/vmanager/routes.py +++ b/app/vmanager/routes.py @@ -38,23 +38,18 @@ def createvm(): if deployment_seeds != []: flash('Offline deployments exist.') return redirect(url_for('main.dashboard')) - if current_user.confirmed and form.validate_on_submit(): - client_id = current_user.pid - data = { 'clientid': str(client_id), + data = { 'clientid': str(current_user.pid), 'clientname': str(current_user.name), 'clientemail': str(current_user.email), - 'hostname': str(form.servername.data), - 'vmpass': form.vmpassword.data, + 'hostname': str(form.deployname.data), 'region': form.region.data, - 'vps_type': 'kvm', - 'vps_cpu': form.cpu.data, - 'vps_mem': form.mem.data, - 'vps_hdd': form.hdd.data, - 'vps_ipv4': form.ipv4.data, - 'vps_mac': form.mac.data } - + 'type': 'kvm', + 'cpu': '1', + 'mem': '512', + 'hdd': '20' + } try: query = contact_proxmaster(data, 'vmcreate') except: @@ -137,7 +132,7 @@ def command(cmd=None, vmid=0): current_app.logger.warning(cmd + ' is not a valid command!') abort(404) - #work with enabled deploys only + #work with enabled deploys only that you own. result = current_user.inv_deployments.filter_by(enabled=True) inventory = [] for invcls in result: