Commit 1f4825c9 by Sulyok Gabor

SaltStack controller and error handling fixes

parent 7bc6e462
...@@ -8,6 +8,7 @@ import os ...@@ -8,6 +8,7 @@ import os
from vm.models import Instance from vm.models import Instance
class SettyController: class SettyController:
salthelper = SaltStackHelper()
@staticmethod @staticmethod
@transaction.atomic @transaction.atomic
...@@ -115,7 +116,7 @@ class SettyController: ...@@ -115,7 +116,7 @@ class SettyController:
@staticmethod @staticmethod
def getMachineAvailableList(serviceId, usedHostnames, current_user): def getMachineAvailableList(serviceId, usedHostnames, current_user):
saltMinions = []#SettyController.salthelper.getAllMinionsUngrouped() saltMinions = SettyController.salthelper.getAllMinionsUngrouped()
savedMachines = Machine.objects.filter(service=serviceId) savedMachines = Machine.objects.filter(service=serviceId)
savedHostNames = [] savedHostNames = []
...@@ -143,12 +144,12 @@ class SettyController: ...@@ -143,12 +144,12 @@ class SettyController:
return {'error': 'already added or doesnt exists'} return {'error': 'already added or doesnt exists'}
except: except:
pass pass
#if SettyController.salthelper.checkMinionExists(hostname): if SettyController.salthelper.checkMinionExists(hostname):
machine = Machine.clone() machine = Machine.clone()
machine.hostname = hostname machine.hostname = hostname
return machine.getDataDictionary() return machine.getDataDictionary()
# else: else:
# return {'error': 'already added or doesnt exists'} return {'error': 'already added or doesnt exists'}
@staticmethod @staticmethod
def addServiceNode(elementTemplateId): def addServiceNode(elementTemplateId):
......
...@@ -6,11 +6,10 @@ import salt.client ...@@ -6,11 +6,10 @@ 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()
def getAllMinionsGrouped(self): def getAllMinionsGrouped(self):
query_result = self.salt_runner.cmd('manage.status', []); query_result = self.salt_runner.cmd('manage.status', []);
...@@ -39,7 +38,8 @@ class SaltStackHelper: ...@@ -39,7 +38,8 @@ class SaltStackHelper:
def checkMinionExists(self, hostname): def checkMinionExists(self, hostname):
query_res = self.salt_localclient.cmd( hostname,'network.get_hostname' ); query_res = self.salt_localclient.cmd( hostname,'network.get_hostname' );
return query_res != None print query_res
return query_res != {}
def deploy(self, hostname, configFilePath ): def deploy(self, hostname, configFilePath ):
print configFilePath print configFilePath
......
...@@ -101,6 +101,11 @@ jsPlumb.ready(function() { ...@@ -101,6 +101,11 @@ jsPlumb.ready(function() {
event: "addMachine", event: "addMachine",
data: JSON.stringify({ "hostname": machineHostname } ) data: JSON.stringify({ "hostname": machineHostname } )
}, function(result) { }, function(result) {
if(result.error)
{
alert(result.error)
return;
}
addMachine( result ); addMachine( result );
undoStack.splice(stackIndexer, 0, removeElement); undoStack.splice(stackIndexer, 0, removeElement);
redoStack.splice(stackIndexer, 0, addElement); redoStack.splice(stackIndexer, 0, addElement);
...@@ -789,7 +794,7 @@ jsPlumb.ready(function() { ...@@ -789,7 +794,7 @@ jsPlumb.ready(function() {
$.post("", { $.post("", {
event: "deploy", event: "deploy",
}, function(result) { }, function(result) {
if ( result.status == 'error' ) if ( result.error )
alert( result.errors ); alert( result.errors );
else else
alert("Deploying...."); alert("Deploying....");
......
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