create-activate phase 2

This commit is contained in:
deflax 2017-11-05 22:20:39 +02:00
parent 7bf97fc487
commit 9c085f4561
6 changed files with 32 additions and 19 deletions

View file

@ -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')

View file

@ -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' }

View file

@ -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())

View file

@ -5,8 +5,9 @@
<div class="row">
<ul id="navigation">
{% for item in result %}
<li><a target="_blank" href="{{ item['link'] }}">{{ item['message'] }}</a> {{ item['created_time'] }}<br />
</li><br />
<li><a target="_blank" href="{{ item['link'] }}">{{ item['message'] }}</a></li>
<i>{{ item['created_time'] | fbtime }}</i>
<br /><br />
{% endfor %}
</ul>
</div>

View file

@ -1,7 +1,10 @@
{% block page_content %}
<h4><a href="/news/all">News</a></h4>
<h4>News</h4>
{% for item in result %}
<p><span class="tweet_day">{{ item['created_time'] }}</span>
<a target="_blank" href="{{ item['link'] }}">{{ item['message'] }}</a></p>
<p>
<a target="_blank" href="{{ item['link'] }}">{{ item['message'] }}</a>
<span class="tweet_day">{{ item['created_time'] | fbtime }}</span>
</p>
{% endfor %}
<a href="/news/all">>>></a>
{% endblock %}

View file

@ -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()