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
from django.db import transaction
from saltstackhelper import *
import os
from vm.models import Instance
class SettyController:
@staticmethod
@transaction.atomic
def saveService( serviceId, serviceName, serviceNodes, machines, elementConnections ):
def saveService(serviceId, serviceName, serviceNodes, machines, elementConnections):
service = None
try:
service = Service.objects.get(id=serviceId)
except Service.DoesNotExist:
return JsonResponse( {'error': 'Service not found'})
return JsonResponse({'error': 'Service not found'})
service.name = serviceName
service.save()
......@@ -23,7 +24,7 @@ class SettyController:
Machine.objects.filter(service=service).delete()
for machineData in machines:
machineSaved = Machine(service=service)
machineSaved.fromDataDictionary( machineData )
machineSaved.fromDataDictionary(machineData)
machineSaved.save()
ServiceNode.objects.filter(service=service).delete()
......@@ -31,10 +32,10 @@ class SettyController:
for node in serviceNodes:
elementTemplateId = node["displayId"].split("_")[1]
elementTemplate = ElementTemplate.objects.get(id=elementTemplateId)
newNode = get_model('setty', elementTemplate.prototype ).clone()
newNode = get_model('setty', elementTemplate.prototype).clone()
newNode.service = service
newNode.fromDataDictionary( node )
newNode.fromDataDictionary(node)
newNode.save()
for elementConnection in elementConnections:
......@@ -63,6 +64,7 @@ class SettyController:
@staticmethod
def loadService(serviceId):
service = None
try:
service = Service.objects.get(id=serviceId)
except Service.DoesNotExist:
......@@ -81,10 +83,10 @@ class SettyController:
Q(target__in=serviveNodeList) | Q(source__in=serviveNodeList))
for servideNode in serviveNodeList:
serviceNodes.append( servideNode.cast().getDataDictionary() )
serviceNodes.append(servideNode.cast().getDataDictionary())
for elementConnection in elementConnectionList:
elementConnections.append( elementConnection.getDataDictionary() )
elementConnections.append(elementConnection.getDataDictionary())
return {'serviceName': service.name,
'elementConnections': elementConnections,
......@@ -111,19 +113,22 @@ class SettyController:
raise PermissionDenied # TODO: something more meaningful
@staticmethod
def getMachineAvailableList(service_id, used_hostnames):
all_minions = SettyController.salthelper.getAllMinionsGrouped()
result = []
#TODO: filter out used ones
for item in all_minions["up"]:
result.append( {'hostname': item,
'hardware-info': SettyController.salthelper.getMinionBasicHardwareInfo( item ),
'status': 'up'} )
def getMachineAvailableList(serviceId, used_hostnames, current_user):
all_minions = SettyController.salthelper.getAllMinionsUngrouped()
usedMachines = Machine.objects.get(service=serviceId)
user_instances = Instance.objects.get(owner=current_user)
userMachines = []
for instance in user_instances:
if user_instances.vm_name():
userMachines.append(user_instances.vm_name())
for item in all_minions["down"]:
result.append( {'hostname': item, 'status': 'down' })
result = []
for machine in usedMachines:
if machine.hostname not in userMachines:
result.append(machine.hostname)
return { 'machinedata': result }
return {'machinedata': result}
@staticmethod
def addMachine(hostname):
......@@ -143,11 +148,12 @@ class SettyController:
def addServiceNode(elementTemplateId):
if elementTemplateId:
try:
elementTemplate = ElementTemplate.objects.get(id=elementTemplateId)
model = get_model('setty', elementTemplate.prototype )
elementTemplate = ElementTemplate.objects.get(
id=elementTemplateId)
model = get_model('setty', elementTemplate.prototype)
return model.clone().getDataDictionary()
except ElementTemplate.DoesNotExist:
return {'error': "ElementTemplate doesn't exists" }
return {'error': "ElementTemplate doesn't exists"}
except:
return {'error': 'Can not get prototype'}
else:
......@@ -157,44 +163,59 @@ class SettyController:
def deploy(serviceId):
service = Service.objects.get(id=serviceId)
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 = []
#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
for machine in machines:
for connection in elementConnections:
serviceNode = None
if connection.target.cast() == machine:
serviceNode = connection.source.cast()
serviceNode.setMachineForDeploy( machine )
serviceNode.setMachineForDeploy(machine)
elif connection.source.cast() == machine:
serviceNode = connection.target.cast()
serviceNode.setMachineForDeploy( machine )
serviceNode.setMachineForDeploy(machine)
else:
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()
for serviceNode in firstLevelServiceNodes:
generatedNodes = serviceNode.generateConfigurationRecursively()
if isinstance( generatedNodes, list ):
if isinstance(generatedNodes, list):
configuratedNodes = configuratedNodes + generatedNodes
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)
return {'status': 'success'}
#deploy the nodes
for node in configuratedNodes:
SettyController.salthelper.deploy( node.machine.hostname, node.generatedConfig )
return {'status': 'deployed'}
# deploy the nodes
# for node in configuratedNodes:
# SettyController.salthelper.deploy(
# node.machine.hostname, node.generatedConfig)
# return {'status': 'deployed'}
#cleanup the temporary data
# cleanup the temporary data
''' for node in configuratedNodes:
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() {
/* 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() {
serviceName = $("#serviceName").text();
......
......@@ -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 hidden-lg" id="showAddMachineDialog" ><i class="fa fa-plus-circle"></i></button>
</div>
<div class="col-xs-4 text-center">
<div class="col-xs-3 text-center">
<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%;" />
<button class="btn btn-success btn-xs initHidden" id="serviceNameSave">{% trans 'OK' %}</button>
......@@ -47,6 +47,10 @@
<button class="btn btn-success btn-xs hidden-lg" id="saveService"><i class="fa fa-floppy-o"></i></button>
</div>
<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 hidden-lg" id="deleteService" data-toggle="modal" data-target="#deleteServiceDialog"><i class="fa fa-trash-o"></i></button>
</div>
......
......@@ -54,7 +54,7 @@ class DetailView(LoginRequiredMixin, TemplateView):
else:
raise PermissionDenied
#def get(self, request, *args, **kwargs):
# 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
......@@ -66,7 +66,6 @@ class DetailView(LoginRequiredMixin, TemplateView):
#
# return JsonResponse(result)
def post(self, request, *args, **kwargs):
service = Service.objects.get(id=kwargs['pk'])
if self.request.user != service.user or not self.request.user.is_superuser:
......@@ -87,7 +86,7 @@ class DetailView(LoginRequiredMixin, TemplateView):
'serviceNodes'], data['machines'], data['elementConnections'])
elif eventName == "getMachineAvailableList":
result = SettyController.getMachineAvailableList(
serviceId, data["usedHostnames"])
serviceId, data["usedHostnames"], self.request.user )
elif eventName == "addServiceNode":
result = SettyController.addServiceNode(
data["elementTemplateId"])
......@@ -103,8 +102,10 @@ class DetailView(LoginRequiredMixin, TemplateView):
hostname = data['hostname']
result = SettyController.getInformation(
templateId, hostname )
templateId, hostname)
print '------------'
print result
print '------------'
return JsonResponse(result)
......@@ -124,6 +125,7 @@ class DeleteView(LoginRequiredMixin, DeleteView):
class CreateView(LoginRequiredMixin, TemplateView):
def get_template_names(self):
if self.request.is_ajax():
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