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: ...@@ -171,12 +171,14 @@ class SettyController:
@staticmethod @staticmethod
def deploy(serviceId): def deploy(serviceId):
service = Service.objects.get(id=serviceId) service = Service.objects.get(id=serviceId)
machines = Machine.objects.filter(service=service)
serviveNodeList = ServiceNode.objects.filter(service=service) serviveNodeList = ServiceNode.objects.filter(service=service)
errorMessages = [] errorMessages = []
nodesToBeDeployed = []
for serviceNode in serviveNodeList: for serviceNode in serviveNodeList:
errorMessage = serviceNode.cast().checkDependenciesAndAttributes() castedServiceNode = serviceNode.cast()
nodesToBeDeployed.append( castedServiceNode )
errorMessage = castedServiceNode.checkDependenciesAndAttributes()
if errorMessage: if errorMessage:
errorMessages.append(errorMessage) errorMessages.append(errorMessage)
...@@ -184,52 +186,39 @@ class SettyController: ...@@ -184,52 +186,39 @@ class SettyController:
return {'status': 'error', return {'status': 'error',
'errors': errorMessages} 'errors': errorMessages}
elementConnections = ElementConnection.objects.filter( # phase one: ask the servicenodes to generate their needed salt commands
Q(target__in=machines) | Q(source__in=machines))
for serviceNode in nodesToBeDeployed:
# phase one: set the machine ptr in serviceNodes which can be accessed by serviceNode.generateSaltCommands()
# 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 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) # later in the deployement)
configuratedNodes.sort(reverse=True) nodesToBeDeployed.sort(reverse=True)
# dbgCheck = [] # dbgCheck = []
# for node in configuratedNodes: # for node in nodesToBeDeployed:
# commandDict = [] # commandArray = []
# for command in node.generatedCommands: # for command in node.generatedCommands:
# commandDict.append( command.__dict__ ) # commandArray.append( command.toDict() )
# dbgCheck.append({ "nodeName": my_instance.__class__.__name__, #
# "commands": commandDict }) # dbgCheck.append({ "nodeName": str(node.__class__.__name__),
# return dbgCheck # "hostingMachineName": str(node.hostingMachine.hostname),
# phase four: deploy the nodes # "commands": commandArray })
for node in configuratedNodes: #
# return {"status": "error", "errors":dbgCheck}
# phase three: deploy the nodes
for node in nodesToBeDeployed:
deployErrorMessages = SettyController.salthelper.executeCommand( deployErrorMessages = SettyController.salthelper.executeCommand(
node.generatedCommands) node.generatedCommands)
if errorMessages: if errorMessages:
errorMessages.append(deployErrorMessages) errorMessages.append(deployErrorMessages)
# phase five: cleanup generated commands # phase four: cleanup generated commands
for serviceNode in firstLevelServiceNodes: for serviceNode in nodesToBeDeployed:
serviceNode.generatedCommands = None serviceNode.generatedCommands = None
serviceNode.hostingMachine = None
if errorMessages: if errorMessages:
return {'status': 'error', return {'status': 'error',
......
...@@ -13,6 +13,10 @@ class SaltCommand: ...@@ -13,6 +13,10 @@ class SaltCommand:
def __str__(self): def __str__(self):
return "Command: " + self.hostname + " - " + self.command + " - " + str(self.parameters) return "Command: " + self.hostname + " - " + self.command + " - " + str(self.parameters)
def toDict(self):
return { 'hostname': self.hostname, 'command': self.command, 'parameters': self.parameters }
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')
...@@ -48,5 +52,6 @@ class SaltStackHelper: ...@@ -48,5 +52,6 @@ class SaltStackHelper:
query_res = self.salt_localclient.cmd( hostname,'network.get_hostname' ); query_res = self.salt_localclient.cmd( hostname,'network.get_hostname' );
return query_res != {} return query_res != {}
def executeCommand(self, saltCommand): def executeCommand(self, saltCommands):
return self.salt_localclient.cmd(saltCommand.hostname, "state.sls",[saltCommand.command],kwarg={"pillar":saltCommand.parameters} ) 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): ...@@ -103,9 +103,7 @@ class DetailView(LoginRequiredMixin, TemplateView):
result = SettyController.getInformation( result = SettyController.getInformation(
templateId, hostname) templateId, hostname)
print '------------'
print result
print '------------'
return JsonResponse(result) 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