Commit 80957db3 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: allow remote allocation on an uniq hardcoded partition

parent 8d9b8214
slap_state = context.getSlapState() slap_state = context.getSlapState()
portal = context.getPortalObject() portal = context.getPortalObject()
compute_node = context.getParentValue()
if slap_state == 'free': if slap_state == 'free':
compute_node = context.getParentValue()
return compute_node.ComputeNode_getSoftwareReleaseUrlStringList() return compute_node.ComputeNode_getSoftwareReleaseUrlStringList()
elif slap_state == 'busy': elif slap_state == 'busy':
...@@ -10,9 +11,12 @@ elif slap_state == 'busy': ...@@ -10,9 +11,12 @@ elif slap_state == 'busy':
instance = portal.portal_catalog.getResultValue( instance = portal.portal_catalog.getResultValue(
portal_type="Software Instance", portal_type="Software Instance",
validation_state="validated", validation_state="validated",
default_aggregate_uid=context.getUid(), aggregate__uid=context.getUid(),
) )
if (instance is None) or (instance.getSlapState() not in ["start_requested", "stop_requested"]): if (instance is None) or (instance.getSlapState() not in ["start_requested", "stop_requested"]):
# XXX Not very elegant
if (compute_node.getPortalType() == 'Remote Node') and (context.getId() == 'SHARED_REMOTE'):
return ['ANY_URL']
return [] return []
else: else:
return [instance.getUrlString()] return [instance.getUrlString()]
......
...@@ -7,23 +7,32 @@ assert remote_node.getPortalType() == 'Remote Node' ...@@ -7,23 +7,32 @@ assert remote_node.getPortalType() == 'Remote Node'
remote_project = remote_node.getDestinationProjectValue(portal_type='Project') remote_project = remote_node.getDestinationProjectValue(portal_type='Project')
remote_person = remote_node.getDestinationSectionValue(portal_type='Person') remote_person = remote_node.getDestinationSectionValue(portal_type='Person')
local_instance = portal.portal_catalog.getResultValue( if compute_partition.getId() == 'SHARED_REMOTE':
portal_type='Software Instance', # Hardcoded ID behaviour
aggregate__uid=compute_partition.getUid() local_instance_list = portal.portal_catalog(
) portal_type='Slave Instance',
aggregate__uid=compute_partition.getUid()
)
# XXX TODO this will increase the workflow history else:
# Use the 'cached' API instead local_instance_list = [portal.portal_catalog.getResultValue(
remote_person.requestSoftwareInstance( portal_type='Software Instance',
project_reference=remote_project.getReference(), aggregate__uid=compute_partition.getUid()
software_release=local_instance.getUrlString(), )]
software_title='_remote_%s_%s' % (remote_node.getFollowUpReference(), local_instance.getReference()),
software_type=local_instance.getSourceReference(), for local_instance in local_instance_list:
instance_xml=local_instance.getTextContent(), # XXX TODO this will increase the workflow history
sla_xml=None, # Use the 'cached' API instead
shared=False, remote_person.requestSoftwareInstance(
state={'start_requested': 'started', 'stop_requested': 'stopped'}[local_instance.getSlapState()] project_reference=remote_project.getReference(),
) software_release=local_instance.getUrlString(),
requested_software_instance = context.REQUEST.get('request_instance') software_title='_remote_%s_%s' % (remote_node.getFollowUpReference(), local_instance.getReference()),
if requested_software_instance is not None: software_type=local_instance.getSourceReference(),
local_instance.setConnectionXml(requested_software_instance.getConnectionXml()) instance_xml=local_instance.getTextContent(),
sla_xml=None,
shared=(local_instance.getPortalType() == 'Slave Instance'),
state={'start_requested': 'started', 'stop_requested': 'stopped'}[local_instance.getSlapState()]
)
requested_software_instance = context.REQUEST.get('request_instance')
if requested_software_instance is not None:
local_instance.setConnectionXml(requested_software_instance.getConnectionXml())
...@@ -36,6 +36,8 @@ software_product, release_variation, type_variation = tmp_instance.InstanceTree_ ...@@ -36,6 +36,8 @@ software_product, release_variation, type_variation = tmp_instance.InstanceTree_
if software_product is None: if software_product is None:
raise ValueError('No Software Product matching') raise ValueError('No Software Product matching')
assert software_product.getFollowUpUid() == project_uid
allocation_cell_list = software_product.getFollowUpValue().Project_getSoftwareProductPredicateList( allocation_cell_list = software_product.getFollowUpValue().Project_getSoftwareProductPredicateList(
software_product=software_product, software_product=software_product,
software_product_type=type_variation, software_product_type=type_variation,
...@@ -44,7 +46,6 @@ allocation_cell_list = software_product.getFollowUpValue().Project_getSoftwarePr ...@@ -44,7 +46,6 @@ allocation_cell_list = software_product.getFollowUpValue().Project_getSoftwarePr
predicate_portal_type='Allocation Supply Cell' predicate_portal_type='Allocation Supply Cell'
) )
#context.log('allocation_cell_list %s' % str(allocation_cell_list))
if not allocation_cell_list: if not allocation_cell_list:
raise ValueError('No Allocation Supply allowing this operation') raise ValueError('No Allocation Supply allowing this operation')
...@@ -79,6 +80,10 @@ for compute_node_list, is_slave_on_same_instance_tree_allocable in compute_node_ ...@@ -79,6 +80,10 @@ for compute_node_list, is_slave_on_same_instance_tree_allocable in compute_node_
elif compute_node.getPortalType() == 'Remote Node': elif compute_node.getPortalType() == 'Remote Node':
parent_uid_list.append(compute_node.getUid()) parent_uid_list.append(compute_node.getUid())
# This is the only hardcoded partition accepting any slave instance allocation
shared_partition = compute_node.restrictedTraverse('SHARED_REMOTE', None)
if shared_partition is not None:
partition_uid_list.append(shared_partition.getUid())
else: else:
raise NotImplementedError('Unsupported Node type: %s' % compute_node.getPortalType()) raise NotImplementedError('Unsupported Node type: %s' % compute_node.getPortalType())
......
...@@ -4,4 +4,14 @@ reference = "REMOTE-%s" % portal.portal_ids.generateNewId( ...@@ -4,4 +4,14 @@ reference = "REMOTE-%s" % portal.portal_ids.generateNewId(
id_group='slap_instance_node_reference', id_group='slap_instance_node_reference',
id_generator='uid', default=1) id_generator='uid', default=1)
# XXX format
partition = context.newContent(
portal_type='Compute Partition',
reference='shared_partition',
id='SHARED_REMOTE'
)
partition.markFree()
partition.markBusy()
partition.validate()
context.edit(reference=reference) context.edit(reference=reference)
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