Commit e13d6e98 by Sulyok Gabor

Better error messages and bugfixes, some code cleanup

parent 67dd3488
Pipeline #294 failed with stage
in 0 seconds
...@@ -131,6 +131,8 @@ class SettyController: ...@@ -131,6 +131,8 @@ class SettyController:
@staticmethod @staticmethod
def getInformation(elementTemplateId, hostname): def getInformation(elementTemplateId, hostname):
if hostname and elementTemplateId:
return {'status': 'error', 'errors': 'BOTH_ELEMENTEMPLATE_HOSTNAME_FILLED'}
if elementTemplateId: if elementTemplateId:
try: try:
elementTemplate = ElementTemplate.objects.get( elementTemplate = ElementTemplate.objects.get(
...@@ -143,8 +145,6 @@ class SettyController: ...@@ -143,8 +145,6 @@ class SettyController:
return {'status': 'error', 'errors': 'ELEMENTTEMPLATE_COULDNT_GET_PROTOTYPE'} return {'status': 'error', 'errors': 'ELEMENTTEMPLATE_COULDNT_GET_PROTOTYPE'}
elif hostname: elif hostname:
return Machine.getInformation() return Machine.getInformation()
elif hostname and elementTemplateId:
return {'status': 'error', 'errors': 'BOTH_ELEMENTEMPLATE_HOSTNAME_FILLED'}
else: else:
return {'status': 'error', 'errors': 'UNKNOWN_ERROR'} return {'status': 'error', 'errors': 'UNKNOWN_ERROR'}
...@@ -155,13 +155,7 @@ class SettyController: ...@@ -155,13 +155,7 @@ class SettyController:
''' '''
@staticmethod @staticmethod
def getMachineAvailableList(serviceId, usedHostnames, current_user): def getMachineAvailableList( usedHostnames, current_user):
savedMachines = Machine.objects.filter(service=serviceId)
savedHostNames = []
for machine in savedMachines:
savedHostNames.append(machine.hostname)
userInstances = Instance.objects.filter( userInstances = Instance.objects.filter(
owner=current_user, destroyed_at=None) owner=current_user, destroyed_at=None)
userMachines = [] userMachines = []
...@@ -169,14 +163,17 @@ class SettyController: ...@@ -169,14 +163,17 @@ class SettyController:
if instance.vm_name: if instance.vm_name:
userMachines.append(instance.vm_name) userMachines.append(instance.vm_name)
usedHostnamesByUser = set(savedHostNames + usedHostnames)
availableInstances = set(set(userMachines) - usedHostnamesByUser)
saltMinions = SettyController.salthelper.getAllMinionsUngrouped() saltMinions = SettyController.salthelper.getAllMinionsUngrouped()
if not usedHostnamesByUser: if not usedHostnames:
return {'machinedata': [machineName for machineName in userMachines if machineName in saltMinions]} return {'machinedata': [machineName for machineName
in userMachines if machineName in saltMinions]}
availableInstances = set(set(userMachines) - usedHostnames)
return {'machinedata':
[machineName for machineName
in availableInstances if machineName in saltMinions]}
return {'machinedata': [machineName for machineName in availableInstances if machineName in saltMinions]}
''' '''
Add a machine with the given hostname to the Service. If there is a Add a machine with the given hostname to the Service. If there is a
...@@ -185,13 +182,8 @@ class SettyController: ...@@ -185,13 +182,8 @@ class SettyController:
back the new Machine instance back the new Machine instance
''' '''
#TODO: addMachine requires usedHostnames too for safety
@staticmethod @staticmethod
def addMachine(hostname): def addMachine(hostname):
try:
Machine.objects.get(hostname=hostname)
except:
return {'status': 'error', 'errors': 'MACHINE_ALREADY_ADDED'}
if SettyController.salthelper.checkMinionExists(hostname): if SettyController.salthelper.checkMinionExists(hostname):
machine = Machine.clone() machine = Machine.clone()
machine.hostname = hostname machine.hostname = hostname
...@@ -251,19 +243,6 @@ class SettyController: ...@@ -251,19 +243,6 @@ class SettyController:
nodesToBeDeployed.sort(reverse=True) nodesToBeDeployed.sort(reverse=True)
dbgCheck = []
# for node in nodesToBeDeployed:
# commandArray = []
#
# for command in node.generatedCommands:
# logger.error( "salt '"+ command.hostname +"' state.sls " + command.command + " pillar=\"" + str(command.parameters) + '"' )
# commandArray.append( command.toDict() )
#
# dbgCheck.append({ "nodeName": str(node.__class__.__name__),
# "hostingMachineName": str(node.getHostingMachine().hostname ),
# "commands": commandArray })
#return {"status": "error", "errors":dbgCheck}
# phase three: deploy the nodes # phase three: deploy the nodes
for node in nodesToBeDeployed: for node in nodesToBeDeployed:
......
...@@ -31,13 +31,6 @@ class SaltCommand: ...@@ -31,13 +31,6 @@ class SaltCommand:
self.command = "" self.command = ""
self.parameters = None self.parameters = None
# For debugging purposes only
def toDict(self):
return {'hostname': self.hostname,
'command': self.command,
'parameters': self.parameters}
class SaltStackHelper: class SaltStackHelper:
def __init__(self): def __init__(self):
......
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