Commit 97c4dbde by Sulyok Gabor

SaltCommand generation and deployement fixes

parent 5e8e9dca
Pipeline #260 failed with stage
in 0 seconds
......@@ -171,12 +171,14 @@ class SettyController:
@staticmethod
def deploy(serviceId):
service = Service.objects.get(id=serviceId)
machines = Machine.objects.filter(service=service)
serviveNodeList = ServiceNode.objects.filter(service=service)
errorMessages = []
nodesToBeDeployed = []
for serviceNode in serviveNodeList:
errorMessage = serviceNode.cast().checkDependenciesAndAttributes()
castedServiceNode = serviceNode.cast()
nodesToBeDeployed.append( castedServiceNode )
errorMessage = castedServiceNode.checkDependenciesAndAttributes()
if errorMessage:
errorMessages.append(errorMessage)
......@@ -184,52 +186,39 @@ class SettyController:
return {'status': 'error',
'errors': errorMessages}
elementConnections = ElementConnection.objects.filter(
Q(target__in=machines) | Q(source__in=machines))
# phase one: set the machine ptr in serviceNodes which can be accessed by
# connections from machines
logger = logging.getLogger('project.interesting.stuff')
for machine in machines:
for connection in elementConnections:
serviceNode = None
if connection.target.cast() == machine:
serviceNode = connection.source.cast()
serviceNode.setMachineForDeploy(machine)
elif connection.source.cast() == machine:
serviceNode = connection.target.cast()
serviceNode.setMachineForDeploy(machine)
# phase two: let the nodes create configurations recursively
configuratedNodes = list()
for serviceNode in serviveNodeList:
node = serviceNode.cast()
node.generateSaltCommands()
configuratedNodes.append( node )
# phase one: ask the servicenodes to generate their needed salt commands
for serviceNode in nodesToBeDeployed:
serviceNode.generateSaltCommands()
# phase three: sort the nodes by deployment priority(lower the prio,
# phase two: sort the nodes by deployment priority(lower the prio,
# later in the deployement)
configuratedNodes.sort(reverse=True)
nodesToBeDeployed.sort(reverse=True)
# dbgCheck = []
# for node in configuratedNodes:
# commandDict = []
# for node in nodesToBeDeployed:
# commandArray = []
# for command in node.generatedCommands:
# commandDict.append( command.__dict__ )
# dbgCheck.append({ "nodeName": my_instance.__class__.__name__,
# "commands": commandDict })
# return dbgCheck
# phase four: deploy the nodes
for node in configuratedNodes:
# commandArray.append( command.toDict() )
#
# dbgCheck.append({ "nodeName": str(node.__class__.__name__),
# "hostingMachineName": str(node.hostingMachine.hostname),
# "commands": commandArray })
#
# return {"status": "error", "errors":dbgCheck}
# phase three: deploy the nodes
for node in nodesToBeDeployed:
deployErrorMessages = SettyController.salthelper.executeCommand(
node.generatedCommands)
if errorMessages:
errorMessages.append(deployErrorMessages)
# phase five: cleanup generated commands
for serviceNode in firstLevelServiceNodes:
# phase four: cleanup generated commands
for serviceNode in nodesToBeDeployed:
serviceNode.generatedCommands = None
serviceNode.hostingMachine = None
if errorMessages:
return {'status': 'error',
......
......@@ -13,6 +13,10 @@ class SaltCommand:
def __str__(self):
return "Command: " + self.hostname + " - " + self.command + " - " + str(self.parameters)
def toDict(self):
return { 'hostname': self.hostname, 'command': self.command, 'parameters': self.parameters }
class SaltStackHelper:
def __init__(self):
self.master_opts = salt.config.client_config('/etc/salt/master')
......@@ -48,5 +52,6 @@ class SaltStackHelper:
query_res = self.salt_localclient.cmd( hostname,'network.get_hostname' );
return query_res != {}
def executeCommand(self, saltCommand):
return self.salt_localclient.cmd(saltCommand.hostname, "state.sls",[saltCommand.command],kwarg={"pillar":saltCommand.parameters} )
def executeCommand(self, saltCommands):
for saltCommand in saltCommands:
self.salt_localclient.cmd(saltCommand.hostname, "state.sls",[saltCommand.command],kwarg={"pillar":saltCommand.parameters} )
......@@ -103,9 +103,7 @@ class DetailView(LoginRequiredMixin, TemplateView):
result = SettyController.getInformation(
templateId, hostname)
print '------------'
print result
print '------------'
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