Commit 1f4825c9 by Sulyok Gabor

SaltStack controller and error handling fixes

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