Commit 7224f978 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: require a project reference when requesting a compute node

parent fa5102a5
...@@ -8,7 +8,12 @@ kwargs = state_change.kwargs ...@@ -8,7 +8,12 @@ kwargs = state_change.kwargs
try: try:
compute_node_title = kwargs['compute_node_title'] compute_node_title = kwargs['compute_node_title']
except KeyError: except KeyError:
raise TypeError, "Person_requestComputeNode takes exactly 1 argument" raise TypeError, "Person_requestComputeNode takes exactly 2 arguments. Missing compute_node_title."
try:
project_reference = kwargs['project_reference']
except KeyError:
raise TypeError, "Person_requestComputeNode takes exactly 2 arguments. Missing project_reference."
tag = "%s_%s_ComputeNodeInProgress" % (person.getUid(), tag = "%s_%s_ComputeNodeInProgress" % (person.getUid(),
compute_node_title) compute_node_title)
...@@ -17,6 +22,12 @@ if (portal.portal_activities.countMessageWithTag(tag) > 0): ...@@ -17,6 +22,12 @@ if (portal.portal_activities.countMessageWithTag(tag) > 0):
# As it is not possible to fetch informations, it is better to raise an error # As it is not possible to fetch informations, it is better to raise an error
raise NotImplementedError(tag) raise NotImplementedError(tag)
# Ensure project is correctly set
project_list = portal.portal_catalog.portal_catalog(portal_type='Project', reference=project_reference,
validation_state='validated', limit=2)
if len(project_list) != 1:
raise NotImplementedError
compute_node_portal_type = "Compute Node" compute_node_portal_type = "Compute Node"
compute_node_list = portal.portal_catalog.portal_catalog(portal_type=compute_node_portal_type, title=compute_node_title, limit=2) compute_node_list = portal.portal_catalog.portal_catalog(portal_type=compute_node_portal_type, title=compute_node_title, limit=2)
...@@ -24,6 +35,7 @@ if len(compute_node_list) == 2: ...@@ -24,6 +35,7 @@ if len(compute_node_list) == 2:
raise NotImplementedError raise NotImplementedError
elif len(compute_node_list) == 1: elif len(compute_node_list) == 1:
compute_node = compute_node_list[0] compute_node = compute_node_list[0]
assert compute_node.getFollowUp() == project_list[0].getRelativeUrl()
else: else:
reference = "COMP-%s" % portal.portal_ids.generateNewId( reference = "COMP-%s" % portal.portal_ids.generateNewId(
...@@ -34,6 +46,7 @@ else: ...@@ -34,6 +46,7 @@ else:
portal_type=compute_node_portal_type, portal_type=compute_node_portal_type,
title=compute_node_title, title=compute_node_title,
reference=reference, reference=reference,
follow_up_value=project_list[0],
activate_kw={'tag': tag} activate_kw={'tag': tag}
) )
compute_node.approveComputeNodeRegistration() compute_node.approveComputeNodeRegistration()
......
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