This commit is contained in:
deflax 2017-10-29 23:06:54 +02:00
parent 79e5777ae3
commit 7bf97fc487
8 changed files with 70 additions and 43 deletions

View file

@ -189,7 +189,7 @@ def dashboard(user_pid=0):
for unit_id in inv_deploycubeids: for unit_id in inv_deploycubeids:
rrd[unit_id] = {} rrd[unit_id] = {}
data = { 'unit_id': int(unit_id), data = { 'unit_id': int(unit_id),
'type': 'deploy' } 'type': 'kvm' }
query = contact_proxmaster(data, 'vmrrd') query = contact_proxmaster(data, 'vmrrd')
if query['status'] == 'UNREACHABLE': if query['status'] == 'UNREACHABLE':
flash('Deploy #{} is unreachable. Support is notified.'.format(str(unit_id))) flash('Deploy #{} is unreachable. Support is notified.'.format(str(unit_id)))

View file

@ -94,10 +94,10 @@ def dashboard():
rrd = {} rrd = {}
statuses = {} statuses = {}
#current_app.logger.warning(str(inv_deploycubeids)) #current_app.logger.warning(str(inv_deploycubeids))
for user_id in inv_deploycubeids: for unit_id in inv_deploycubeids:
rrd[user_id] = {} rrd[unit_id] = {}
data = { 'user_id': int(user_id), data = { 'user_id': int(unit_id),
'type': 'deploy' } 'type': 'kvm' }
try: try:
query = contact_proxmaster(data, 'vmrrd') query = contact_proxmaster(data, 'vmrrd')
except Exception as e: except Exception as e:
@ -121,6 +121,6 @@ def dashboard():
send_email(current_app.config['MAIL_USERNAME'], 'Cube {} is unreachable'.format(unit_id), send_email(current_app.config['MAIL_USERNAME'], 'Cube {} is unreachable'.format(unit_id),
'vmanager/email/adm_unreachable', user=current_user, unit_id=unit_id ) 'vmanager/email/adm_unreachable', user=current_user, unit_id=unit_id )
current_app.logger.info('[{}] Enabled deployments: {}, services: {}, domains: {}, addresses: {}'.format(current_user.email, inv_deployments_list, inv_services_list, inv_domains_list, inv_addresses_list )) #current_app.logger.info('[{}] Enabled deployments: {}, services: {}, domains: {}, addresses: {}'.format(current_user.email, inv_deployments_list, inv_services_list, inv_domains_list, inv_addresses_list ))
return render_template('main/dashboard.html', rrd=rrd, status=statuses, inv_deployments=inv_deployments, inv_services=inv_services, inv_domains=inv_domains, inv_addresses=inv_addresses, region=regions) return render_template('main/dashboard.html', rrd=rrd, status=statuses, inv_deployments=inv_deployments, inv_services=inv_services, inv_domains=inv_domains, inv_addresses=inv_addresses, region=regions)

View file

@ -220,6 +220,7 @@ def contact_proxmaster(data, method):
try: try:
db_result = requests.post( url, data=data_json, headers={"content-type": "application/json"}, timeout=30 ) db_result = requests.post( url, data=data_json, headers={"content-type": "application/json"}, timeout=30 )
proxjson = db_result.json() proxjson = db_result.json()
#current_app.logger.info('grid> {}'.format(str(db_result)))
return proxjson return proxjson
except: except:
return { 'status': 'UNREACHABLE' } return { 'status': 'UNREACHABLE' }
@ -234,7 +235,7 @@ class Router(db.Model):
machine_id = db.Column(db.BigInteger) #unit_id machine_id = db.Column(db.BigInteger) #unit_id
class Bridge(db.Model): class Bridge(db.Model):
__tablename__ = 'bridge' __tablename__ = 'bridges'
pid = db.Column(db.Integer, primary_key=True) pid = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK
date_created = db.Column(db.DateTime, default=datetime.utcnow) date_created = db.Column(db.DateTime, default=datetime.utcnow)

View file

@ -375,7 +375,7 @@ addEventListener("DOMContentLoaded", function() {
</tbody> </tbody>
</table> </table>
</div> </div>
<button class="btn btn-default" onclick="window.open('{{ url_for('smanager.requestservice') }}','_self')"><img class="icon icons8-Key-2" width="32" height="32" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAADwUlEQVRYhdXYz0/bVhwA8Bz4I/Yn9A/gwKGHHApxiENwo8IG2rSqh/XUw267cRmJY8dOQpIGOq2cdtguFZNoUQQeiOBnm7h4iB+TRkJwkiJtdZ0GQzPLeTtU0bIQ0qQ8wP1K30sU6X3y/X7fs18cjk89Bsn1fjwEAgQj7nhpQXMFeeilBY1gpV2cFkgsCG7fCAwL8E5fWBQmk7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yNygAAAABJRU5ErkJggg==">Request</button> <!-- <button class="btn btn-default" onclick="window.open('{{ url_for('smanager.requestservice') }}','_self')"><img class="icon icons8-Key-2" width="32" height="32" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAADwUlEQVRYhdXYz0/bVhwA8Bz4I/Yn9A/gwKGHHApxiENwo8IG2rSqh/XUw267cRmJY8dOQpIGOq2cdtguFZNoUQQeiOBnm7h4iB+TRkJwkiJtdZ0GQzPLeTtU0bIQ0qQ8wP1K30sU6X3y/X7fs18cjk89Bsn1fjwEAgQj7nhpQXMFeeilBY1gpV2cFkgsCG7fCAwL8E5fWBQmk7IeX1bNTM6ASrkG83odKuUazOQMGF9WzYmEXPWFxd+xAO+8FphziuvzMRKDkcBKLKt/H2gWzOv1C/NAs2ByRdXdJDD9kc2oc4rru1LcSFj4dTIpn6z9edIR1pqZnAG/mt06GWXExStD+hiJ+SKR1ff/MnvCNVfz69mt1yOMOI8chwV4J0YCq9fKtSZ/aEA3Ccyh6Q0cKdAXFoUUVzJbK8IsFc4IVqoSrFSln+fffWgm83odpriSiVNgDxlukFzvn0zKeuvizFLhzEuL224SDLhJMOClBIlZKpx10+qJhFxBtrPHY9mZaLqgty5EsFLVTYKB5h9CsFK1m1ZH0wX9XlSaRQIkGHEnkzPOLXIZYCZnQIIRd5AAvbSgNQ7h5qSf59/hlCAOkuv9g+R6P06BNWoxf9oNUCnXoJcWNCRAV5C/cJaYFwWjsUmoxfxpN5ukka4gD5EAR8LtK3iZVMo1OBJGVMG7EWmv3QxeJjM5AxKstIsE+Hk8G4+mC29RAqPpo+pYbPMJEiAWBLe/fPyy0st8dXEO1rGQcA8J0OFwOPwRaT+5op47Cz8m51ZLcHwma92NSK+GQ+JnSIBYgHe6SWBedhb5QwN6KAEuKBqcXS1VkCL9kc1ou0deL6395sdt+OinAygfv/8MKdI5xfWNMuLigzmlyh/2Vkn+0IAPn27D737+A26+suDTl9aVIufdJDATK6rWzRv13GoJ4pQAv184gI3vy8f1/yF/WCtbPkYsImv30PTGKE6Bvc53kqI5kZTrY7GstaBo5/CtSOQz6XC83zweCrBtb3UUiLpIcN9LC5UUV2x7AlwL8kMxNL1xy0uLeoorvrE5UtBTvxU12yMfc6q9kZ4Q0FxBHjayExL57u412r1r2qKSnYC2Qg6HwOtPvt2/7P73tIqljyw/Kz2zDbA1t4//gTglnF7pn1AXRad2N+eDJ8obV4C/c+3A5ugEjKXVk7EZed62wPR+BfrCYvlGgZ4Q0GLpI6v1uquUa3A8nn07TPHf3ihwaHrjlp+VnuEUOL0/t6UnllVraVe3B645nFNcnyvA3/FQIOELi2Vb4bqJfwEpWpu91pyNygAAAABJRU5ErkJggg==">Request</button>-->
{% else %} {% else %}
<!--<button class="btn btn-default btn-lg btn-block" onclick="window.open('{{ url_for('smanager.requestservice') }}','_self')"><img class="icon icons8-Key-2" width="48" height="48" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAADwUlEQVRYhdXYz0/bVhwA8Bz4I/Yn9A/gwKGHHApxiENwo8IG2rSqh/XUw267cRmJY8dOQpIGOq2cdtguFZNoUQQeiOBnm7h4iB+TRkJwkiJtdZ0GQzPLeTtU0bIQ0qQ8wP1K30sU6X3y/X7fs18cjk89Bsn1fjwEAgQj7nhpQXMFeeilBY1gpV2cFkgsCG7fCAwL8E5fWBQmk7IeX1bNTM6ASrkG83odKuUazOQMGF9WzYmEXPWFxd+xAO+8FphziuvzMRKDkcBKLKt/H2gWzOv1C/NAs2ByRdXdJDD9kc2oc4rru1LcSFj4dTIpn6z9edIR1pqZnAG/mt06GWXExStD+hiJ+SKR1ff/MnvCNVfz69mt1yOMOI8chwV4J0YCq9fKtSZ/aEA3Ccyh6Q0cKdAXFoUUVzJbK8IsFc4IVqoSrFSln+fffWgm83odpriSiVNgDxlukFzvn0zKeuvizFLhzEuL224SDLhJMOClBIlZKpx10+qJhFxBtrPHY9mZaLqgty5EsFLVTYKB5h9CsFK1m1ZH0wX9XlSaRQIkGHEnkzPOLXIZYCZnQIIRd5AAvbSgNQ7h5qSf59/hlCAOkuv9g+R6P06BNWoxf9oNUCnXoJcWNCRAV5C/cJaYFwWjsUmoxfxpN5ukka4gD5EAR8LtK3iZVMo1OBJGVMG7EWmv3QxeJjM5AxKstIsE+Hk8G4+mC29RAqPpo+pYbPMJEiAWBLe/fPyy0st8dXEO1rGQcA8J0OFwOPwRaT+5op47Cz8m51ZLcHwma92NSK+GQ+JnSIBYgHe6SWBedhb5QwN6KAEuKBqcXS1VkCL9kc1ou0deL6395sdt+OinAygfv/8MKdI5xfWNMuLigzmlyh/2Vkn+0IAPn27D737+A26+suDTl9aVIufdJDATK6rWzRv13GoJ4pQAv184gI3vy8f1/yF/WCtbPkYsImv30PTGKE6Bvc53kqI5kZTrY7GstaBo5/CtSOQz6XC83zweCrBtb3UUiLpIcN9LC5UUV2x7AlwL8kMxNL1xy0uLeoorvrE5UtBTvxU12yMfc6q9kZ4Q0FxBHjayExL57u412r1r2qKSnYC2Qg6HwOtPvt2/7P73tIqljyw/Kz2zDbA1t4//gTglnF7pn1AXRad2N+eDJ8obV4C/c+3A5ugEjKXVk7EZed62wPR+BfrCYvlGgZ4Q0GLpI6v1uquUa3A8nn07TPHf3ihwaHrjlp+VnuEUOL0/t6UnllVraVe3B645nFNcnyvA3/FQIOELi2Vb4bqJfwEpWpu91pyNygAAAABJRU5ErkJggg==">Request</button>--> <!--<button class="btn btn-default btn-lg btn-block" onclick="window.open('{{ url_for('smanager.requestservice') }}','_self')"><img class="icon icons8-Key-2" width="48" height="48" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAADwUlEQVRYhdXYz0/bVhwA8Bz4I/Yn9A/gwKGHHApxiENwo8IG2rSqh/XUw267cRmJY8dOQpIGOq2cdtguFZNoUQQeiOBnm7h4iB+TRkJwkiJtdZ0GQzPLeTtU0bIQ0qQ8wP1K30sU6X3y/X7fs18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jlp+VnuEUOL0/t6UnllVraVe3B645nFNcnyvA3/FQIOELi2Vb4bqJfwEpWpu91pyNygAAAABJRU5ErkJggg==">Request</button>-->
{% endif %} {% endif %}

View file

@ -1,7 +1,7 @@
<div id="footer_copyright"> <div id="footer_copyright">
<div class="page_wrap"> <div class="page_wrap">
<p class="copyright"><a href="{{ url_for('main.terms') }}">Terms of Service</a> &copy; Copyright 2017 <a href="https://deflax.net">_sys</a>, All Rights Reserved.</p> <p class="copyright"><a href="{{ url_for('main.terms') }}">Terms of Service</a> &copy; All Rights Reserved.</p>
<p class="design_by"></p> <p class="design_by"></p>
</div><!--/page wrap--> </div><!--/page wrap-->

View file

@ -1,4 +1,4 @@
<br /><br > <br /><br >
<div class="page_wrap"> <div class="page_wrap">
<p class="copyright" style="color:#708d3f;">&copy; Copyright 2017 <a style="color:#88af46" href="https://deflax.net">_sys</a>, All Rights Reseserved. Icons by <a style="color:#88af46" href="https://icons8.com">icons8.com</a></p> <p class="copyright" style="color:#708d3f;">&copy; All Rights Reserved. Icons by <a style="color:#88af46" href="https://icons8.com">icons8</a></p>
</div><!--/page wrap--> </div><!--/page wrap-->

View file

@ -31,7 +31,7 @@
<div class="panel panel-primary panel-transparent"> <div class="panel panel-primary panel-transparent">
<div class="panel-body"> <div class="panel-body">
<iframe src="https://datapoint.bg/kiwi/" style="border:0; width:100%; height:460px;"></iframe> <iframe src="https://datapoint.bg/kiwi/" style="border:0; width:100%; height:460px;"></iframe>
To permanently stay connected to our chat network you could use an client like <a href="https://hexchat.github.io/downloads.html">HexChat</a> and use the following URL:<br /><a href="irc://irc.datapoint.bg:+6697/#support">irc://irc.datapoint.bg:+6697/#support</a> To permanently stay connected to our chat network you could use a client like <a href="https://hexchat.github.io/downloads.html">HexChat</a> and use the following URL:<br /><a href="irc://irc.datapoint.bg:+6697/#support">irc://irc.datapoint.bg:+6697/#support</a>
</div> </div>
</div> </div>
</div> </div>

View file

@ -43,52 +43,58 @@ def createvm():
if current_user.confirmed and form.validate_on_submit(): if current_user.confirmed and form.validate_on_submit():
selected_region = Region.query.filter_by(pid=int(form.region.data)).first() selected_region = Region.query.filter_by(pid=int(form.region.data)).first()
#TODO: Filter switches for the selected region only! #TODO: Filter bridges for the selected region only. switch should return slave name
selected_bridge = current_user.inv_bridges.filter_by(deleted=False).all() selected_bridge = current_user.inv_bridges.filter_by(deleted=False).first()
if selected_bridge == []: if selected_bridge is None:
#no switches in the account. create one... #no bridges in the account. create one...
data = { 'clientid': str(current_user.pid), data = { 'clientid': str(current_user.pid),
'clientemail': str(current_user.email), 'clientemail': str(current_user.email),
'region': str(selected_region.name), 'region': str(selected_region.name),
'type': 'bridge' 'type': 'br'
} }
#create bridge unit #create bridge unit
query = contact_proxmaster(data, 'create') query = contact_proxmaster(data, 'create')
if query is not None: if query['status'] == 'bridge_created':
bridge = Bridge(user_id=int(current_user.pid)) newbridge = True
#machine will be installed where the bridge physically is
region_name = query['region']
slave_name = query['slave']
bridge_id = query['unit_id']
bridge_phyid = query['phyid']
bridge = Bridge(user_id=int(current_user.pid), bridge_id=bridge_id)
db.session.add(bridge) db.session.add(bridge)
db.session.commit() db.session.commit()
flash('New point created successfully in region "{}".'.format(str(selected_region.description))) flash('New point created successfully in region "{}".'.format(str(selected_region.description)))
newbridge = True
else: else:
flash('Point could not be created! Please try again later...') flash('Point could not be created! Please try again later...')
return redirect(url_for('main.dashboard')) return redirect(url_for('main.dashboard'))
else: else:
#bridge found. lets see on which slave it is so we can create the instance on the same slave. #bridge found. lets see on which slave it is so we can create the instance on the same slave.
data = { 'unit_id': int(selected_bridge.bridge_id), data = { 'unit_id': int(selected_bridge.bridge_id),
'type': 'bridge' } 'type': 'br' }
query = contact_proxmaster(data, 'status') query = contact_proxmaster(data, 'query')
if query is not None: if query['status'] == 'query_success':
newbridge = False newbridge = False
#machine will be installed where the switch physically is
region_name = query['region']
slave_name = query['slave']
bridge_phyid = query['phyid']
else: else:
flash('Point found but cannot be used!') flash('Point found but cannot be used!')
return redirect(url_for('main.dashboard')) return redirect(url_for('main.dashboard'))
#machine will be installed where the switch physically is ###
slave_name = query['slave_name']
bridge_id = query['bridge_id']
#create new machine... #create new machine...
data = { 'clientid': str(current_user.pid), data = { 'clientid': str(current_user.pid),
'clientemail': str(current_user.email), 'clientemail': str(current_user.email),
'hostname': 'c' + str(current_user.pid) + '-' + str(form.servername.data), 'hostname': 'c' + str(current_user.pid) + '-' + str(form.servername.data),
'region': str(selected_region.name), 'region': str(region_name),
'slave': str(slave_name), 'slave': str(slave_name),
'type': 'deploy', 'type': 'kvm',
'cpu': '1', 'cpu': '1',
'mem': '512', 'mem': '512',
'hdd': '20', 'hdd': '20',
'bridge': str(bridge_id) 'net0if': 'vmbr' + str(bridge_phyid)
} }
try: try:
query = contact_proxmaster(data, 'create') query = contact_proxmaster(data, 'create')
@ -96,8 +102,8 @@ def createvm():
flash('Region not available! Please try again later...') flash('Region not available! Please try again later...')
return redirect(url_for('main.dashboard')) return redirect(url_for('main.dashboard'))
if query is not None: if query['status'] == 'kvm_created':
deployment = Deployment(user_id=int(current_user.pid), machine_alias=query['hostname'], 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=, 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.add(deployment)
db.session.commit() db.session.commit()
flash('New device created successfully in region "{}".'.format(str(selected_region.description))) flash('New device created successfully in region "{}".'.format(str(selected_region.description)))
@ -154,23 +160,43 @@ def activate(itemid=0):
return redirect(url_for('uinvoice.transactions')) return redirect(url_for('uinvoice.transactions'))
current_app.logger.info('[{}] Charge deployment: {}'.format(owner.email, deploy.machine_id)) current_app.logger.info('[{}] Charge deployment: {}'.format(owner.email, deploy.machine_id))
router = current_user.inv_routers.filter_by(deleted=False).all() #TODO: Filter routers for the selected region only. switch should return slave name
if router == []: selected_router = current_user.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()
if selected_bridge is None:
flash('No bridge created yet. Cannot activate.')
return redirect(url_for('main.dashboard'))
else:
#bridge found. lets see on which slave it is so we can create the instance on the same slave.
data = { 'unit_id': int(selected_bridge.bridge_id),
'type': 'br' }
query = contact_proxmaster(data, 'query')
if query['status'] == 'query_success':
#machine will be installed where the switch physically is
region_name = query['region']
slave_name = query['slave']
bridge_phyid = query['phyid']
else:
flash('Point found but cannot be used!')
return redirect(url_for('main.dashboard'))
#no router. creating... #no router. creating...
data = { 'clientid': str(current_user.pid), data = { 'clientid': str(current_user.pid),
'clientemail': str(current_user.email), 'clientemail': str(current_user.email),
'hostname': 'c' + str(current_user.pid) + 'router', 'hostname': 'r' + str(selected_address.ip) + '-b' + str(bridge_phyid),
'region': str(selected_region.name), 'region': str(region_name),
'slave': str(selected_slave), 'slave': str(slave_name),
'type': 'lxc', 'type': 'lxc',
'cpu': '1', 'cpu': '1',
'mem': '128', 'mem': '128',
'hdd': '1', 'hdd': '1',
'eth0br': str(bridge_id), 'net0if': 'vmbr' + bridge_phyid,
'eth0ip': '192.168.9.1', 'net0ip': '192.168.9.1',
'eth1br': 'vmbr0', 'net1if': 'vmbr0',
'eth1ip': str(selected_address.ip) 'net1ip': str(selected_address.ip),
'net1gw': '87.120.110.1' #should be queried from the current region
} }
try: try:
query = contact_proxmaster(data, 'create') query = contact_proxmaster(data, 'create')
@ -210,7 +236,7 @@ def activate(itemid=0):
@login_required @login_required
def remove(unit_id=0): def remove(unit_id=0):
data = { 'unit_id': int(unit_id), data = { 'unit_id': int(unit_id),
'type': 'deploy' } 'type': 'kvm' }
deploy = Deployment.query.filter_by(machine_id=int(unit_id)).first() deploy = Deployment.query.filter_by(machine_id=int(unit_id)).first()
if current_user.is_administrator(): if current_user.is_administrator():
if deploy.protected is not True: if deploy.protected is not True:
@ -245,7 +271,7 @@ def command(cmd=None, unit_id=0):
for invcls in result: for invcls in result:
inventory.extend([invcls.machine_id]) inventory.extend([invcls.machine_id])
data = { 'type': 'deploy', data = { 'type': 'kvm',
'unit_id': int(unit_id) } 'unit_id': int(unit_id) }
if current_user.is_administrator(): if current_user.is_administrator():