Commit 93a6e237 by Sulyok Gábor

Removed unneccesary file, added relation & attribute checks for

deployment in setty
parent f9aa89de
...@@ -5,17 +5,18 @@ from django.db.models.loading import get_model ...@@ -5,17 +5,18 @@ from django.db.models.loading import get_model
from django.db import transaction from django.db import transaction
from saltstackhelper import * from saltstackhelper import *
import os import os
from vm.models import Instance
class SettyController: class SettyController:
@staticmethod @staticmethod
@transaction.atomic @transaction.atomic
def saveService( serviceId, serviceName, serviceNodes, machines, elementConnections ): def saveService(serviceId, serviceName, serviceNodes, machines, elementConnections):
service = None service = None
try: try:
service = Service.objects.get(id=serviceId) service = Service.objects.get(id=serviceId)
except Service.DoesNotExist: except Service.DoesNotExist:
return JsonResponse( {'error': 'Service not found'}) return JsonResponse({'error': 'Service not found'})
service.name = serviceName service.name = serviceName
service.save() service.save()
...@@ -23,7 +24,7 @@ class SettyController: ...@@ -23,7 +24,7 @@ class SettyController:
Machine.objects.filter(service=service).delete() Machine.objects.filter(service=service).delete()
for machineData in machines: for machineData in machines:
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()
...@@ -31,10 +32,10 @@ class SettyController: ...@@ -31,10 +32,10 @@ class SettyController:
for node in serviceNodes: for node in serviceNodes:
elementTemplateId = node["displayId"].split("_")[1] 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()
newNode.service = service newNode.service = service
newNode.fromDataDictionary( node ) newNode.fromDataDictionary(node)
newNode.save() newNode.save()
for elementConnection in elementConnections: for elementConnection in elementConnections:
...@@ -63,6 +64,7 @@ class SettyController: ...@@ -63,6 +64,7 @@ class SettyController:
@staticmethod @staticmethod
def loadService(serviceId): def loadService(serviceId):
service = None service = None
try: try:
service = Service.objects.get(id=serviceId) service = Service.objects.get(id=serviceId)
except Service.DoesNotExist: except Service.DoesNotExist:
...@@ -81,10 +83,10 @@ class SettyController: ...@@ -81,10 +83,10 @@ class SettyController:
Q(target__in=serviveNodeList) | Q(source__in=serviveNodeList)) Q(target__in=serviveNodeList) | Q(source__in=serviveNodeList))
for servideNode in serviveNodeList: for servideNode in serviveNodeList:
serviceNodes.append( servideNode.cast().getDataDictionary() ) serviceNodes.append(servideNode.cast().getDataDictionary())
for elementConnection in elementConnectionList: for elementConnection in elementConnectionList:
elementConnections.append( elementConnection.getDataDictionary() ) elementConnections.append(elementConnection.getDataDictionary())
return {'serviceName': service.name, return {'serviceName': service.name,
'elementConnections': elementConnections, 'elementConnections': elementConnections,
...@@ -111,19 +113,22 @@ class SettyController: ...@@ -111,19 +113,22 @@ class SettyController:
raise PermissionDenied # TODO: something more meaningful raise PermissionDenied # TODO: something more meaningful
@staticmethod @staticmethod
def getMachineAvailableList(service_id, used_hostnames): def getMachineAvailableList(serviceId, used_hostnames, current_user):
all_minions = SettyController.salthelper.getAllMinionsGrouped() all_minions = SettyController.salthelper.getAllMinionsUngrouped()
result = [] usedMachines = Machine.objects.get(service=serviceId)
#TODO: filter out used ones user_instances = Instance.objects.get(owner=current_user)
for item in all_minions["up"]:
result.append( {'hostname': item, userMachines = []
'hardware-info': SettyController.salthelper.getMinionBasicHardwareInfo( item ), for instance in user_instances:
'status': 'up'} ) if user_instances.vm_name():
userMachines.append(user_instances.vm_name())
for item in all_minions["down"]: result = []
result.append( {'hostname': item, 'status': 'down' }) for machine in usedMachines:
if machine.hostname not in userMachines:
result.append(machine.hostname)
return { 'machinedata': result } return {'machinedata': result}
@staticmethod @staticmethod
def addMachine(hostname): def addMachine(hostname):
...@@ -143,11 +148,12 @@ class SettyController: ...@@ -143,11 +148,12 @@ class SettyController:
def addServiceNode(elementTemplateId): def addServiceNode(elementTemplateId):
if elementTemplateId: if elementTemplateId:
try: try:
elementTemplate = ElementTemplate.objects.get(id=elementTemplateId) elementTemplate = ElementTemplate.objects.get(
model = get_model('setty', elementTemplate.prototype ) id=elementTemplateId)
model = get_model('setty', elementTemplate.prototype)
return model.clone().getDataDictionary() return model.clone().getDataDictionary()
except ElementTemplate.DoesNotExist: except ElementTemplate.DoesNotExist:
return {'error': "ElementTemplate doesn't exists" } return {'error': "ElementTemplate doesn't exists"}
except: except:
return {'error': 'Can not get prototype'} return {'error': 'Can not get prototype'}
else: else:
...@@ -157,44 +163,59 @@ class SettyController: ...@@ -157,44 +163,59 @@ class SettyController:
def deploy(serviceId): def deploy(serviceId):
service = Service.objects.get(id=serviceId) service = Service.objects.get(id=serviceId)
machines = Machine.objects.filter(service=service) machines = Machine.objects.filter(service=service)
elementConnections = ElementConnection.objects.filter(
Q(target__in=machines) | Q(source__in=machines) )
serviveNodeList = ServiceNode.objects.filter(service=service)
errorMessages = []
for serviceNode in serviveNodeList:
errorMessage = serviceNode.cast().checkDependenciesAndAttributes()
if errorMessage:
errorMessages.append(errorMessage)
if errorMessages:
return {'status': 'error',
'errors': errorMessages }
elementConnections = ElementConnection.objects.filter(
Q(target__in=machines) | Q(source__in=machines))
firstLevelServiceNodes = [] firstLevelServiceNodes = []
#phase one: set the machine ptr in serviceNodes which can be accessed by
# phase one: set the machine ptr in serviceNodes which can be accessed by
# connections from machines # connections from machines
for machine in machines: for machine in machines:
for connection in elementConnections: for connection in elementConnections:
serviceNode = None serviceNode = None
if connection.target.cast() == machine: if connection.target.cast() == machine:
serviceNode = connection.source.cast() serviceNode = connection.source.cast()
serviceNode.setMachineForDeploy( machine ) serviceNode.setMachineForDeploy(machine)
elif connection.source.cast() == machine: elif connection.source.cast() == machine:
serviceNode = connection.target.cast() serviceNode = connection.target.cast()
serviceNode.setMachineForDeploy( machine ) serviceNode.setMachineForDeploy(machine)
else: else:
raise PermissionDenied raise PermissionDenied
firstLevelServiceNodes.append( serviceNode ) firstLevelServiceNodes.append(serviceNode)
#phase two: let the nodes create configurations recursively # phase two: let the nodes create configurations recursively
configuratedNodes = list() configuratedNodes = list()
for serviceNode in firstLevelServiceNodes: for serviceNode in firstLevelServiceNodes:
generatedNodes = serviceNode.generateConfigurationRecursively() generatedNodes = serviceNode.generateConfigurationRecursively()
if isinstance( generatedNodes, list ): if isinstance(generatedNodes, list):
configuratedNodes = configuratedNodes + generatedNodes configuratedNodes = configuratedNodes + generatedNodes
else: else:
configuratedNodes.append( generatedNodes ) configuratedNodes.append(generatedNodes)
#phase three: sort the nodes by deployment priority(lower the prio, later in the deployement) # phase three: sort the nodes by deployment priority(lower the prio,
# later in the deployement)
configuratedNodes.sort(reverse=True) configuratedNodes.sort(reverse=True)
return {'status': 'success'}
#deploy the nodes # deploy the nodes
for node in configuratedNodes: # for node in configuratedNodes:
SettyController.salthelper.deploy( node.machine.hostname, node.generatedConfig ) # SettyController.salthelper.deploy(
return {'status': 'deployed'} # node.machine.hostname, node.generatedConfig)
# return {'status': 'deployed'}
#cleanup the temporary data # cleanup the temporary data
''' for node in configuratedNodes: ''' for node in configuratedNodes:
node.deployCleanUp()''' node.deployCleanUp()'''
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('setty', '0021_element_real_type'),
]
\ No newline at end of file
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('setty', '0023_drop_parameters_from_elementconnection'),
]
operations = [
migrations.CreateModel(
name='ApacheNode',
fields=[
('webservernode_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='setty.WebServerNode')),
],
options={
'abstract': False,
},
bases=('setty.webservernode',),
),
migrations.CreateModel(
name='WordpressNode',
fields=[
('servicenode_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='setty.ServiceNode')),
('databaseListeningPort', models.PositiveIntegerField()),
('databaseHost', models.TextField()),
('databaseUser', models.TextField()),
('databasePass', models.TextField()),
('adminUsername', models.TextField()),
('adminPassword', models.TextField()),
('adminEmail', models.TextField()),
('siteTitle', models.TextField()),
('siteUrl', models.TextField()),
],
options={
'abstract': False,
},
bases=('setty.servicenode',),
),
migrations.RemoveField(
model_name='machine',
name='config_file',
),
]

9.07 KB | W: | H:

9.07 KB | W: | H:

circle/setty/static/setty/mysql.jpg
circle/setty/static/setty/mysql.jpg
circle/setty/static/setty/mysql.jpg
circle/setty/static/setty/mysql.jpg
  • 2-up
  • Swipe
  • Onion skin

84.4 KB | W: | H:

84.4 KB | W: | H:

circle/setty/static/setty/postgresql.png
circle/setty/static/setty/postgresql.png
circle/setty/static/setty/postgresql.png
circle/setty/static/setty/postgresql.png
  • 2-up
  • Swipe
  • Onion skin
...@@ -803,6 +803,16 @@ jsPlumb.ready(function() { ...@@ -803,6 +803,16 @@ jsPlumb.ready(function() {
/* Registering events concerning persistence. */ /* Registering events concerning persistence. */
$('body').on('click', '#saveService',function() {
$.post("", {
event: "deploy",
}, function(result) {
if ( result.status == 'error' )
alert( result.errors );
else
alert("Deploying....");
});
})
$('body').on('click', '#saveService', function() { $('body').on('click', '#saveService', function() {
serviceName = $("#serviceName").text(); serviceName = $("#serviceName").text();
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
<button class="btn btn-success btn-xs btn-block hidden-xs hidden-sm hidden-md" id="showAddMachineDialog">{% trans 'Machines' %}</button> <button class="btn btn-success btn-xs btn-block hidden-xs hidden-sm hidden-md" id="showAddMachineDialog">{% trans 'Machines' %}</button>
<button class="btn btn-success btn-xs hidden-lg" id="showAddMachineDialog" ><i class="fa fa-plus-circle"></i></button> <button class="btn btn-success btn-xs hidden-lg" id="showAddMachineDialog" ><i class="fa fa-plus-circle"></i></button>
</div> </div>
<div class="col-xs-4 text-center"> <div class="col-xs-3 text-center">
<h3 class="no-margin" id="serviceName"></h3> <h3 class="no-margin" id="serviceName"></h3>
<input class="form-control form-control-sm initHidden" id="serviceNameEdit" type="text" style="margin-top: -4px !important; margin-bottom: -4px !important; width: 80%;" /> <input class="form-control form-control-sm initHidden" id="serviceNameEdit" type="text" style="margin-top: -4px !important; margin-bottom: -4px !important; width: 80%;" />
<button class="btn btn-success btn-xs initHidden" id="serviceNameSave">{% trans 'OK' %}</button> <button class="btn btn-success btn-xs initHidden" id="serviceNameSave">{% trans 'OK' %}</button>
...@@ -47,6 +47,10 @@ ...@@ -47,6 +47,10 @@
<button class="btn btn-success btn-xs hidden-lg" id="saveService"><i class="fa fa-floppy-o"></i></button> <button class="btn btn-success btn-xs hidden-lg" id="saveService"><i class="fa fa-floppy-o"></i></button>
</div> </div>
<div class="col-xs-1 col-xs-push-1 text-right"> <div class="col-xs-1 col-xs-push-1 text-right">
<button class="btn btn-success btn-xs btn-block hidden-xs hidden-sm hidden-md" id="saveService">{% trans 'Deploy' %}</button>
<button class="btn btn-success btn-xs hidden-lg" id="deployService"><i class="fa fa-floppy-o"></i></button>
</div>
<div class="col-xs-1 col-xs-push-1 text-right">
<button class="btn btn-danger btn-xs btn-block hidden-xs hidden-sm hidden-md" id="deleteService" data-toggle="modal" data-target="#deleteServiceDialog">{% trans 'Delete' %}</button> <button class="btn btn-danger btn-xs btn-block hidden-xs hidden-sm hidden-md" id="deleteService" data-toggle="modal" data-target="#deleteServiceDialog">{% trans 'Delete' %}</button>
<button class="btn btn-danger btn-xs hidden-lg" id="deleteService" data-toggle="modal" data-target="#deleteServiceDialog"><i class="fa fa-trash-o"></i></button> <button class="btn btn-danger btn-xs hidden-lg" id="deleteService" data-toggle="modal" data-target="#deleteServiceDialog"><i class="fa fa-trash-o"></i></button>
</div> </div>
......
...@@ -54,7 +54,7 @@ class DetailView(LoginRequiredMixin, TemplateView): ...@@ -54,7 +54,7 @@ class DetailView(LoginRequiredMixin, TemplateView):
else: else:
raise PermissionDenied raise PermissionDenied
#def get(self, request, *args, **kwargs): # def get(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:
# # raise PermissionDenied # # raise PermissionDenied
...@@ -66,7 +66,6 @@ class DetailView(LoginRequiredMixin, TemplateView): ...@@ -66,7 +66,6 @@ class DetailView(LoginRequiredMixin, TemplateView):
# #
# return JsonResponse(result) # 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:
...@@ -87,7 +86,7 @@ class DetailView(LoginRequiredMixin, TemplateView): ...@@ -87,7 +86,7 @@ class DetailView(LoginRequiredMixin, TemplateView):
'serviceNodes'], data['machines'], data['elementConnections']) 'serviceNodes'], data['machines'], data['elementConnections'])
elif eventName == "getMachineAvailableList": elif eventName == "getMachineAvailableList":
result = SettyController.getMachineAvailableList( result = SettyController.getMachineAvailableList(
serviceId, data["usedHostnames"]) serviceId, data["usedHostnames"], self.request.user )
elif eventName == "addServiceNode": elif eventName == "addServiceNode":
result = SettyController.addServiceNode( result = SettyController.addServiceNode(
data["elementTemplateId"]) data["elementTemplateId"])
...@@ -103,8 +102,10 @@ class DetailView(LoginRequiredMixin, TemplateView): ...@@ -103,8 +102,10 @@ class DetailView(LoginRequiredMixin, TemplateView):
hostname = data['hostname'] hostname = data['hostname']
result = SettyController.getInformation( result = SettyController.getInformation(
templateId, hostname ) templateId, hostname)
print '------------'
print result
print '------------'
return JsonResponse(result) return JsonResponse(result)
...@@ -124,6 +125,7 @@ class DeleteView(LoginRequiredMixin, DeleteView): ...@@ -124,6 +125,7 @@ class DeleteView(LoginRequiredMixin, DeleteView):
class CreateView(LoginRequiredMixin, TemplateView): class CreateView(LoginRequiredMixin, TemplateView):
def get_template_names(self): def get_template_names(self):
if self.request.is_ajax(): if self.request.is_ajax():
return ['dashboard/_modal.html'] return ['dashboard/_modal.html']
......
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