Commit f9aa89de by Sulyok Gábor

Fix javascript and integrate new backend

parent 9ab17d5f
...@@ -2,13 +2,14 @@ from .models import * ...@@ -2,13 +2,14 @@ from .models import *
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.db.models import Q from django.db.models import Q
from django.db.models.loading import get_model from django.db.models.loading import get_model
from django.db import transaction
from saltstackhelper import * from saltstackhelper import *
import os import os
class SettyController: class SettyController:
salthelper = SaltStackHelper()
@staticmethod @staticmethod
@transaction.atomic
def saveService( serviceId, serviceName, serviceNodes, machines, elementConnections ): def saveService( serviceId, serviceName, serviceNodes, machines, elementConnections ):
service = None service = None
try: try:
...@@ -19,18 +20,16 @@ class SettyController: ...@@ -19,18 +20,16 @@ class SettyController:
service.name = serviceName service.name = serviceName
service.save() service.save()
#first check machine names
#validMachineNames = self.salthelper.getAllMinionsUngrouped()
Machine.objects.filter(service=service).delete() Machine.objects.filter(service=service).delete()
for machineData in machines: for machineData in machines:
# if machineData["hostname"] in validMachineNames:
machineSaved = Machine(service=service) machineSaved = Machine(service=service)
machineSaved.fromDataDictionary( machineData ) machineSaved.fromDataDictionary( machineData )
machineSaved.save() machineSaved.save()
ServiceNode.objects.filter(service=service).delete() ServiceNode.objects.filter(service=service).delete()
for node in serviceNodes: for node in serviceNodes:
elementTemplateId = node["displayId"].split("_")[0] elementTemplateId = node["displayId"].split("_")[1]
elementTemplate = ElementTemplate.objects.get(id=elementTemplateId) elementTemplate = ElementTemplate.objects.get(id=elementTemplateId)
newNode = get_model('setty', elementTemplate.prototype ).clone() newNode = get_model('setty', elementTemplate.prototype ).clone()
...@@ -43,7 +42,6 @@ class SettyController: ...@@ -43,7 +42,6 @@ class SettyController:
targetId = elementConnection['targetId'] targetId = elementConnection['targetId']
sourceEndpoint = elementConnection['sourceEndpoint'] sourceEndpoint = elementConnection['sourceEndpoint']
targetEndpoint = elementConnection['targetEndpoint'] targetEndpoint = elementConnection['targetEndpoint']
connectionParameters = elementConnection['parameters']
targetObject = Element.objects.get( targetObject = Element.objects.get(
display_id=targetId) display_id=targetId)
...@@ -55,9 +53,9 @@ class SettyController: ...@@ -55,9 +53,9 @@ class SettyController:
target=targetObject, target=targetObject,
source=sourceObject, source=sourceObject,
target_endpoint=targetEndpoint, target_endpoint=targetEndpoint,
source_endpoint=sourceEndpoint, source_endpoint=sourceEndpoint
parameters=connectionParameters
) )
connectionObject.save() connectionObject.save()
return {"serviceName": serviceName} return {"serviceName": serviceName}
...@@ -149,9 +147,9 @@ class SettyController: ...@@ -149,9 +147,9 @@ class SettyController:
model = get_model('setty', elementTemplate.prototype ) model = get_model('setty', elementTemplate.prototype )
return model.clone().getDataDictionary() return model.clone().getDataDictionary()
except ElementTemplate.DoesNotExist: except ElementTemplate.DoesNotExist:
return {'error': 'lofaszka' } return {'error': "ElementTemplate doesn't exists" }
except: except:
return {'error': 'valami nagyon el lett baszva'} return {'error': 'Can not get prototype'}
else: else:
return {'error': 'templateid'} return {'error': 'templateid'}
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('setty', '0022_merged'),
]
operations = [
migrations.RemoveField(
model_name='elementconnection',
name='parameters',
),
]
...@@ -122,15 +122,13 @@ class ElementConnection(models.Model): ...@@ -122,15 +122,13 @@ class ElementConnection(models.Model):
on_delete=models.CASCADE) on_delete=models.CASCADE)
source_endpoint = models.TextField() source_endpoint = models.TextField()
target_endpoint = models.TextField() target_endpoint = models.TextField()
parameters = models.TextField()
def __unicode__(self): def __unicode__(self):
return "%d" % self.id return "%d" % self.id
def getDataDictionary(self): def getDataDictionary(self):
return {'targetEndpoint': self.target_endpoint, return {'targetEndpoint': self.target_endpoint,
'sourceEndpoint': self.source_endpoint, 'sourceEndpoint': self.source_endpoint }
'parameters': self.parameters}
class Machine(Element): # As a real machine class Machine(Element): # As a real machine
...@@ -233,22 +231,22 @@ class WebServerNode(ServiceNode): ...@@ -233,22 +231,22 @@ class WebServerNode(ServiceNode):
def getDataDictionary(self): def getDataDictionary(self):
element_data = ServiceNode.getDataDictionary(self) element_data = ServiceNode.getDataDictionary(self)
self_data = {'useSSL': self.useSSL, self_data = {'use-ssl': self.useSSL,
'listeningPort': self.listeningPort} 'listeningport': self.listeningPort}
element_data.update(self_data) element_data.update(self_data)
return element_data return element_data
def fromDataDictionary(self, data): def fromDataDictionary(self, data):
ServiceNode.fromDataDictionary(self, data) ServiceNode.fromDataDictionary(self, data)
self.useSSL = data['useSSL'] self.useSSL = data['use-ssl']
self.listeningPort = data['listeningPort'] self.listeningPort = data['listeningport']
@staticmethod @staticmethod
def getInformation(): def getInformation():
superInformation = ServiceNode.getInformation() superInformation = ServiceNode.getInformation()
ownInformation = {'useSSL': WebServerNode._meta.get_field('useSSL').get_internal_type(), ownInformation = {'use-ssl': WebServerNode._meta.get_field('useSSL').get_internal_type(),
'listeningPort': WebServerNode._meta.get_field('listeningPort').get_internal_type()} 'listeningport': WebServerNode._meta.get_field('listeningport').get_internal_type()}
ownInformation.update(superInformation) ownInformation.update(superInformation)
return ownInformation return ownInformation
...@@ -316,7 +314,9 @@ class DatabaseNode(ServiceNode): ...@@ -316,7 +314,9 @@ class DatabaseNode(ServiceNode):
def getDataDictionary(self): def getDataDictionary(self):
element_data = ServiceNode.getDataDictionary(self) element_data = ServiceNode.getDataDictionary(self)
self_data = {'admin_username': self.adminUserName, self_data = {'admin_username': self.adminUserName,
'admin_password': self.adminPassword, 'listeningPort': self.listeningPort} 'admin_password': self.adminPassword,
'listeningport': self.listeningPort }
element_data.update(self_data) element_data.update(self_data)
return element_data return element_data
...@@ -324,14 +324,14 @@ class DatabaseNode(ServiceNode): ...@@ -324,14 +324,14 @@ class DatabaseNode(ServiceNode):
ServiceNode.fromDataDictionary(self, data) ServiceNode.fromDataDictionary(self, data)
self.adminUserName = data['admin_username'] self.adminUserName = data['admin_username']
self.adminPassword = data['admin_password'] self.adminPassword = data['admin_password']
self.listeningPort = data['listeningPort'] self.listeningPort = data['listeningport']
@staticmethod @staticmethod
def getInformation(): def getInformation():
superInformation = ServiceNode.getInformation() superInformation = ServiceNode.getInformation()
ownInformation = {'admin_username': DatabaseNode._meta.get_field('adminUserName').get_internal_type(), ownInformation = {'admin_username': DatabaseNode._meta.get_field('adminUserName').get_internal_type(),
'admin_password': DatabaseNode._meta.get_field('adminPassword').get_internal_type(), 'admin_password': DatabaseNode._meta.get_field('adminPassword').get_internal_type(),
'listeningPort': DatabaseNode._meta.get_field('listeningPort').get_internal_type()} 'listeningport': DatabaseNode._meta.get_field('listeningPort').get_internal_type()}
ownInformation.update(superInformation) ownInformation.update(superInformation)
return ownInformation return ownInformation
......
...@@ -6,11 +6,11 @@ import salt.client ...@@ -6,11 +6,11 @@ import salt.client
SALTSTACK_STATE_FOLDER = "/srv/salt" SALTSTACK_STATE_FOLDER = "/srv/salt"
class SaltStackHelper: class SaltStackHelper:
def __init__(self): # def __init__(self):
self.master_opts = salt.config.client_config('/etc/salt/master') #self.master_opts = salt.config.client_config('/etc/salt/master')
self.salt_runner = salt.runner.RunnerClient(self.master_opts) #self.salt_runner = salt.runner.RunnerClient(self.master_opts)
self.salt_localclient = salt.client.LocalClient() #self.salt_localclient = salt.client.LocalClient()
self.salt_caller = salt.client.Caller() #self.salt_caller = salt.client.Caller()
def getAllMinionsGrouped(self): def getAllMinionsGrouped(self):
query_result = self.salt_runner.cmd('manage.status', []); query_result = self.salt_runner.cmd('manage.status', []);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
{% load staticfiles %} {% load staticfiles %}
{% load i18n %} {% load i18n %}
{% block title-page %}Setty{% endblock %} {% block title-page %}Setty{% endblock %}
{% block content %} {% block content %}
...@@ -165,9 +166,13 @@ ...@@ -165,9 +166,13 @@
<button class="close" type="button" data-dismiss="modal">&times;</button> <button class="close" type="button" data-dismiss="modal">&times;</button>
<h4 class="modal-title"><i class="fa fa-info"></i>&nbsp;{% trans 'Information' %}</h4> <h4 class="modal-title"><i class="fa fa-info"></i>&nbsp;{% trans 'Information' %}</h4>
</div> </div>
<div class="modal-body" id="informationContainer"> <div class="modal-body">
<form id="informationContainer">
</form>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<div class="btn btn-success" id="informationDialogSave" data-dismiss="modal">Mentés</div>
<div class="btn btn-primary" data-dismiss="modal"/>Mégsem</div>
</div> </div>
</div> </div>
</div> </div>
...@@ -189,6 +194,7 @@ ...@@ -189,6 +194,7 @@
</div> </div>
</div> </div>
</div> </div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsPlumb/1.4.1/jquery.jsPlumb-1.4.1-all.js"></script>
{% endblock %} {% endblock %}
...@@ -40,7 +40,6 @@ logger = logging.getLogger(__name__) ...@@ -40,7 +40,6 @@ logger = logging.getLogger(__name__)
class DetailView(LoginRequiredMixin, TemplateView): class DetailView(LoginRequiredMixin, TemplateView):
template_name = "setty/index.html" template_name = "setty/index.html"
salthelper = SaltStackHelper()
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
logger.debug('DetailView.get_context_data() called. User: %s', logger.debug('DetailView.get_context_data() called. User: %s',
...@@ -55,6 +54,19 @@ class DetailView(LoginRequiredMixin, TemplateView): ...@@ -55,6 +54,19 @@ class DetailView(LoginRequiredMixin, TemplateView):
else: else:
raise PermissionDenied raise PermissionDenied
#def get(self, request, *args, **kwargs):
# # service = Service.objects.get(id=kwargs['pk'])
# # if self.request.user != service.user or not self.request.user.is_superuser:
# # raise PermissionDenied
# # requestName = self.request.GET.get('event')
# # result = {}
# # if requestName == "elementPicture":
# # data = json.loads( self.request.GET.get('data') )
# # result = SettyController.getPictureName( data["elementTemplateId"] )
#
# return JsonResponse(result)
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
service = Service.objects.get(id=kwargs['pk']) service = Service.objects.get(id=kwargs['pk'])
if self.request.user != service.user or not self.request.user.is_superuser: if self.request.user != service.user or not self.request.user.is_superuser:
...@@ -63,14 +75,13 @@ class DetailView(LoginRequiredMixin, TemplateView): ...@@ -63,14 +75,13 @@ class DetailView(LoginRequiredMixin, TemplateView):
result = {} result = {}
eventName = self.request.POST.get('event') eventName = self.request.POST.get('event')
serviceId = kwargs['pk'] serviceId = kwargs['pk']
if eventName == 'loadService': if eventName == 'loadService':
result = SettyController.loadService(serviceId) result = SettyController.loadService(serviceId)
elif eventName == "deploy": elif eventName == "deploy":
result = SettyController.deploy(serviceId) result = SettyController.deploy(serviceId)
else:
data = json.loads(self.request.POST.get('data')) data = json.loads(self.request.POST.get('data'))
if eventName == "saveService": if eventName == "saveService":
result = SettyController.saveService(serviceId, data['serviceName'], data[ result = SettyController.saveService(serviceId, data['serviceName'], data[
'serviceNodes'], data['machines'], data['elementConnections']) 'serviceNodes'], data['machines'], data['elementConnections'])
...@@ -83,8 +94,16 @@ class DetailView(LoginRequiredMixin, TemplateView): ...@@ -83,8 +94,16 @@ class DetailView(LoginRequiredMixin, TemplateView):
elif eventName == "addMachine": elif eventName == "addMachine":
result = SettyController.addMachine(data["hostname"]) result = SettyController.addMachine(data["hostname"])
elif eventName == "getInformation": elif eventName == "getInformation":
templateId = ""
hostname = ""
if "elementTemplateId" in data.keys():
templateId = data['elementTemplateId']
if "hostname" in data.keys():
hostname = data['hostname']
result = SettyController.getInformation( result = SettyController.getInformation(
data['elementTemplateId'], data['hostname']) templateId, hostname )
return JsonResponse(result) return JsonResponse(result)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment