Commit 5804e551 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_cloud: Move API into SoftwareInstance to update the _updateSucessorList

parent b5c767af
...@@ -40,10 +40,12 @@ from zLOG import LOG, INFO ...@@ -40,10 +40,12 @@ from zLOG import LOG, INFO
try: try:
from slapos.slap.slap import \ from slapos.slap.slap import \
SoftwareInstance as SlapSoftwareInstance SoftwareInstance as SlapSoftwareInstance
from slapos.util import xml2dict from slapos.util import xml2dict, loads
except ImportError: except ImportError:
def xml2dict(dictionary): def xml2dict(dictionary):
raise ImportError raise ImportError
def loads(*args):
raise ImportError
class SlapSoftwareInstance: class SlapSoftwareInstance:
def __init__(self): def __init__(self):
raise ImportError raise ImportError
...@@ -288,4 +290,32 @@ class SoftwareInstance(Item): ...@@ -288,4 +290,32 @@ class SoftwareInstance(Item):
internet_protocol_address.getIpAddress().decode("UTF-8")) internet_protocol_address.getIpAddress().decode("UTF-8"))
) )
return ip_address_list return ip_address_list
\ No newline at end of file
def _updateSucessorList(self, instance_reference_xml):
"""
Update Software Instance successor list to match the given list. If one
instance was not requested by this compute partition, it should be removed
in the successor_list of this instance.
Once the link is removed, this instance will be trashed by Garbage Collect!
instance_reference_xml contain list of title of sub-instances requested by
this instance.
"""
cache_reference = '%s-PREDLIST' % self.getReference()
if not self.isLastData(cache_reference, instance_reference_xml):
instance_reference_list = loads(instance_reference_xml)
current_successor_list = self.getSuccessorValueList(
portal_type=['Software Instance', 'Slave Instance'])
current_successor_title_list = [i.getTitle() for i in current_successor_list]
# If there are items to remove
if list(set(current_successor_title_list).difference(instance_reference_list)) != []:
successor_list = [instance.getRelativeUrl() for instance in
current_successor_list if instance.getTitle()
in instance_reference_list]
LOG('SoftwareInstance', INFO, '%s : Updating successor list to %s' % (
self.getReference(), successor_list), error=False)
self.edit(successor_list=successor_list,
comment='successor_list edited to unlink non commited instances')
self.setLastData(instance_reference_xml, key=cache_reference)
\ No newline at end of file
...@@ -941,26 +941,7 @@ class SlapTool(BaseTool): ...@@ -941,26 +941,7 @@ class SlapTool(BaseTool):
_getSoftwareInstanceForComputePartition(compute_node_id, _getSoftwareInstanceForComputePartition(compute_node_id,
compute_partition_id) compute_partition_id)
cache_reference = '%s-PREDLIST' % software_instance_document.getReference() software_instance_document._updateSucessorList(instance_reference_xml)
if not software_instance_document.isLastData(cache_reference, instance_reference_xml):
instance_reference_list = loads(instance_reference_xml)
current_successor_list = software_instance_document.getSuccessorValueList(
portal_type=['Software Instance', 'Slave Instance'])
current_successor_title_list = [i.getTitle() for i in
current_successor_list]
# If there are items to remove
if list(set(current_successor_title_list).difference(instance_reference_list)) != []:
successor_list = [instance.getRelativeUrl() for instance in
current_successor_list if instance.getTitle()
in instance_reference_list]
LOG('SlapTool', INFO, '%s, %s: Updating successor list to %s' % (
compute_node_id, compute_partition_id, successor_list), error=False)
software_instance_document.edit(successor_list=successor_list,
comment='successor_list edited to unlink non commited instances')
software_instance_document.setLastData(instance_reference_xml, key=cache_reference)
#################################################### ####################################################
# Internals methods # Internals methods
......
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 to comment