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()
portal = context.getPortalObject()
compute_node = context.getParentValue()
if slap_state == 'free':
compute_node = context.getParentValue()
return compute_node.ComputeNode_getSoftwareReleaseUrlStringList()
elif slap_state == 'busy':
......@@ -10,9 +11,12 @@ elif slap_state == 'busy':
instance = portal.portal_catalog.getResultValue(
portal_type="Software Instance",
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"]):
# XXX Not very elegant
if (compute_node.getPortalType() == 'Remote Node') and (context.getId() == 'SHARED_REMOTE'):
return ['ANY_URL']
return []
else:
return [instance.getUrlString()]
......
......@@ -7,23 +7,32 @@ assert remote_node.getPortalType() == 'Remote Node'
remote_project = remote_node.getDestinationProjectValue(portal_type='Project')
remote_person = remote_node.getDestinationSectionValue(portal_type='Person')
local_instance = portal.portal_catalog.getResultValue(
portal_type='Software Instance',
aggregate__uid=compute_partition.getUid()
)
if compute_partition.getId() == 'SHARED_REMOTE':
# Hardcoded ID behaviour
local_instance_list = portal.portal_catalog(
portal_type='Slave Instance',
aggregate__uid=compute_partition.getUid()
)
# XXX TODO this will increase the workflow history
# Use the 'cached' API instead
remote_person.requestSoftwareInstance(
project_reference=remote_project.getReference(),
software_release=local_instance.getUrlString(),
software_title='_remote_%s_%s' % (remote_node.getFollowUpReference(), local_instance.getReference()),
software_type=local_instance.getSourceReference(),
instance_xml=local_instance.getTextContent(),
sla_xml=None,
shared=False,
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())
else:
local_instance_list = [portal.portal_catalog.getResultValue(
portal_type='Software Instance',
aggregate__uid=compute_partition.getUid()
)]
for local_instance in local_instance_list:
# XXX TODO this will increase the workflow history
# Use the 'cached' API instead
remote_person.requestSoftwareInstance(
project_reference=remote_project.getReference(),
software_release=local_instance.getUrlString(),
software_title='_remote_%s_%s' % (remote_node.getFollowUpReference(), local_instance.getReference()),
software_type=local_instance.getSourceReference(),
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_
if software_product is None:
raise ValueError('No Software Product matching')
assert software_product.getFollowUpUid() == project_uid
allocation_cell_list = software_product.getFollowUpValue().Project_getSoftwareProductPredicateList(
software_product=software_product,
software_product_type=type_variation,
......@@ -44,7 +46,6 @@ allocation_cell_list = software_product.getFollowUpValue().Project_getSoftwarePr
predicate_portal_type='Allocation Supply Cell'
)
#context.log('allocation_cell_list %s' % str(allocation_cell_list))
if not allocation_cell_list:
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_
elif compute_node.getPortalType() == 'Remote Node':
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:
raise NotImplementedError('Unsupported Node type: %s' % compute_node.getPortalType())
......
......@@ -4,4 +4,14 @@ reference = "REMOTE-%s" % portal.portal_ids.generateNewId(
id_group='slap_instance_node_reference',
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)
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