diff --git a/app/main/routes.py b/app/main/routes.py index 465b2b2..ade13c8 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -96,7 +96,7 @@ def dashboard(): #current_app.logger.warning(str(inv_deploycubeids)) for unit_id in inv_deploycubeids: rrd[unit_id] = {} - data = { 'user_id': int(unit_id), + data = { 'unit_id': int(unit_id), 'type': 'kvm' } try: query = contact_proxmaster(data, 'vmrrd') diff --git a/app/models.py b/app/models.py index 4361a7b..014c8d9 100644 --- a/app/models.py +++ b/app/models.py @@ -220,7 +220,7 @@ def contact_proxmaster(data, method): try: db_result = requests.post( url, data=data_json, headers={"content-type": "application/json"}, timeout=30 ) proxjson = db_result.json() - #current_app.logger.info('grid> {}'.format(str(db_result))) + current_app.logger.info('grid> {}'.format(str(proxjson))) return proxjson except: return { 'status': 'UNREACHABLE' } diff --git a/app/news/routes.py b/app/news/routes.py index 2055498..7efd614 100644 --- a/app/news/routes.py +++ b/app/news/routes.py @@ -4,6 +4,8 @@ from . import news from functools import lru_cache import requests import json +from dateutil.parser import parse +from dateutil.tz import tzutc from facepy import GraphAPI @lru_cache(maxsize=32) @@ -15,6 +17,13 @@ def get_fb_token(): #current_app.logger.info("FB Token: {}".format(fbtoken)) return fbtoken +@news.app_template_filter('fbtime') +def fbtime(event_date): + UTC = tzutc() + dt = parse(event_date) + dt_utc = dt.astimezone(UTC) # Convert to UTC + return dt.strftime('%d %b %Y') + @news.route("/all", methods=['GET']) def all(): graph = GraphAPI(get_fb_token()) diff --git a/app/templates/news/facebook.html b/app/templates/news/facebook.html index 36f0a2b..6789416 100644 --- a/app/templates/news/facebook.html +++ b/app/templates/news/facebook.html @@ -5,8 +5,9 @@
diff --git a/app/templates/news/latest.html b/app/templates/news/latest.html index 06ffb70..932d80a 100644 --- a/app/templates/news/latest.html +++ b/app/templates/news/latest.html @@ -1,7 +1,10 @@ {% block page_content %} -

News

+

News

{% for item in result %} -

{{ item['created_time'] }} - {{ item['message'] }}

+

+ {{ item['message'] }} + {{ item['created_time'] | fbtime }} +

{% endfor %} + >>> {% endblock %} diff --git a/app/vmanager/routes.py b/app/vmanager/routes.py index f73582a..f7c78b7 100644 --- a/app/vmanager/routes.py +++ b/app/vmanager/routes.py @@ -60,7 +60,7 @@ def createvm(): region_name = query['region'] slave_name = query['slave'] bridge_id = query['unit_id'] - bridge_phyid = query['phyid'] + bridge_phy_id = query['phy_id'] bridge = Bridge(user_id=int(current_user.pid), bridge_id=bridge_id) db.session.add(bridge) db.session.commit() @@ -78,7 +78,7 @@ def createvm(): #machine will be installed where the switch physically is region_name = query['region'] slave_name = query['slave'] - bridge_phyid = query['phyid'] + bridge_phy_id = query['phy_id'] else: flash('Point found but cannot be used!') return redirect(url_for('main.dashboard')) @@ -94,7 +94,7 @@ def createvm(): 'cpu': '1', 'mem': '512', 'hdd': '20', - 'net0if': 'vmbr' + str(bridge_phyid) + 'net0if': 'vmbr' + str(bridge_phy_id) } try: query = contact_proxmaster(data, 'create') @@ -103,7 +103,7 @@ def createvm(): return redirect(url_for('main.dashboard')) if query['status'] == 'kvm_created': - deployment = Deployment(user_id=int(current_user.pid), machine_alias=, machine_id=query['unit_id'], machine_cpu=data['cpu'], machine_mem=data['mem'], machine_hdd=data['hdd'], enabled=True, protected=False, daysleft=15, warning=True, discount=0) + deployment = Deployment(user_id=int(current_user.pid), machine_alias=str(form.servername.data), machine_id=query['unit_id'], machine_cpu=data['cpu'], machine_mem=data['mem'], machine_hdd=data['hdd'], enabled=True, protected=False, daysleft=15, warning=True, discount=0) db.session.add(deployment) db.session.commit() flash('New device created successfully in region "{}".'.format(str(selected_region.description))) @@ -161,10 +161,10 @@ def activate(itemid=0): current_app.logger.info('[{}] Charge deployment: {}'.format(owner.email, deploy.machine_id)) #TODO: Filter routers for the selected region only. switch should return slave name - selected_router = current_user.inv_routers.filter_by(deleted=False).first() + selected_router = owner.inv_routers.filter_by(deleted=False).first() if selected_router is None: #TODO: Filter bridges for the selected region only. switch should return slave name - selected_bridge = current_user.inv_bridges.filter_by(deleted=False).first() + selected_bridge = owner.inv_bridges.filter_by(deleted=False).first() if selected_bridge is None: flash('No bridge created yet. Cannot activate.') return redirect(url_for('main.dashboard')) @@ -177,22 +177,22 @@ def activate(itemid=0): #machine will be installed where the switch physically is region_name = query['region'] slave_name = query['slave'] - bridge_phyid = query['phyid'] + bridge_phy_id = query['phy_id'] else: flash('Point found but cannot be used!') return redirect(url_for('main.dashboard')) #no router. creating... - data = { 'clientid': str(current_user.pid), - 'clientemail': str(current_user.email), - 'hostname': 'r' + str(selected_address.ip) + '-b' + str(bridge_phyid), + data = { 'clientid': str(owner.pid), + 'clientemail': str(owner.email), + 'hostname': 'c' + str(owner.pid) + '-rt' + str(selected_address.ip), 'region': str(region_name), 'slave': str(slave_name), 'type': 'lxc', 'cpu': '1', 'mem': '128', 'hdd': '1', - 'net0if': 'vmbr' + bridge_phyid, + 'net0if': 'vmbr' + bridge_phy_id, 'net0ip': '192.168.9.1', 'net1if': 'vmbr0', 'net1ip': str(selected_address.ip), @@ -204,7 +204,7 @@ def activate(itemid=0): flash('Region unreachable! Cannot create router. Please try again later...') return redirect(url_for('main.dashboard')) if query is not None: - router = Router(user_id=int(current_user.pid), machine_id=query['cube']) + router = Router(user_id=int(owner.pid), machine_id=query['cube']) db.session.add(router) db.session.commit()