Commit 74a6cab5 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: allocate slave on instance from the same instance tree

parent 667d62fe
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<item>SlapOSMasterUpgradeConstraint</item> <item>SlapOSMasterUpgradeConstraint</item>
</portal_type> </portal_type>
<portal_type id="Allocation Supply"> <portal_type id="Allocation Supply">
<item>AllocationSupply</item>
<item>SlapOSVirtualMasterSourceProjectConstraint</item> <item>SlapOSVirtualMasterSourceProjectConstraint</item>
</portal_type> </portal_type>
<portal_type id="Allocation Supply Cell"> <portal_type id="Allocation Supply Cell">
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Property Sheet" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_count</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>_mt_index</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>_tree</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>AllocationSupply</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Property Sheet</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Length" module="BTrees.Length"/>
</pickle>
<pickle> <int>0</int> </pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Standard Property" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_local_properties</string> </key>
<value>
<tuple>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>mode</string> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>string</string> </value>
</item>
</dictionary>
</tuple>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>elementary_type/boolean</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slave_on_same_instance_tree_allocable_property</string> </value>
</item>
<item>
<key> <string>mode</string> </key>
<value> <string>w</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Standard Property</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -65,7 +65,10 @@ ...@@ -65,7 +65,10 @@
<item> <item>
<key> <string>center</string> </key> <key> <string>center</string> </key>
<value> <value>
<list/> <list>
<string>my_aggregate_title_list</string>
<string>my_slave_on_same_instance_tree_allocable</string>
</list>
</value> </value>
</item> </item>
<item> <item>
...@@ -88,7 +91,6 @@ ...@@ -88,7 +91,6 @@
<key> <string>right</string> </key> <key> <string>right</string> </key>
<value> <value>
<list> <list>
<string>my_aggregate_title_list</string>
<string>my_destination_project_title</string> <string>my_destination_project_title</string>
<string>my_destination_title</string> <string>my_destination_title</string>
<string>my_translated_validation_state_title</string> <string>my_translated_validation_state_title</string>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>my_slave_on_same_instance_tree_allocable</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_checkbox</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Allocate Slave On Same Instance Tree</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -13,11 +13,9 @@ query_kw = { ...@@ -13,11 +13,9 @@ query_kw = {
} }
if software_instance_portal_type == "Slave Instance": if software_instance_portal_type == "Slave Instance":
query_kw['free_for_request'] = 0 query_kw['free_for_request'] = 0
compute_node_portal_type = 'Instance Node'
elif software_instance_portal_type == "Software Instance": elif software_instance_portal_type == "Software Instance":
query_kw['free_for_request'] = 1 query_kw['free_for_request'] = 1
query_kw['software_release_url'] = software_release_url query_kw['software_release_url'] = software_release_url
compute_node_portal_type = 'Compute Node'
else: else:
raise NotImplementedError("Unknown portal type %s"% raise NotImplementedError("Unknown portal type %s"%
software_instance_portal_type) software_instance_portal_type)
...@@ -50,17 +48,28 @@ allocation_cell_list = software_product.getFollowUpValue().Project_getSoftwarePr ...@@ -50,17 +48,28 @@ allocation_cell_list = software_product.getFollowUpValue().Project_getSoftwarePr
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')
# Only partition with Instances from the same Instance Tree
instance_tree_partition_value_list = [sql_obj.getAggregateValue() \
for sql_obj in context.getPortalObject().portal_catalog(
portal_type=['Software Instance'],
specialise__uid=instance_tree.getUid(),
) if ((sql_obj.getAggregateValue() is not None) and (sql_obj.getUrlString() == software_release_url) and (sql_obj.getSourceReference() == software_type))
]
# Get the list of allowed Compute Node, Instance Node # Get the list of allowed Compute Node, Instance Node
compute_node_list_list = [x.getParentValue().getParentValue().getAggregateValueList(portal_type=compute_node_portal_type) for x in allocation_cell_list] compute_node_list_list = [(x.getParentValue().getParentValue().getAggregateValueList(), x.getParentValue().getParentValue().isSlaveOnSameInstanceTreeAllocable()) for x in allocation_cell_list]
parent_uid_list = [] parent_uid_list = []
partition_uid_list = [] partition_uid_list = []
for compute_node_list in compute_node_list_list: for compute_node_list, is_slave_on_same_instance_tree_allocable in compute_node_list_list:
for compute_node in compute_node_list: for compute_node in compute_node_list:
if compute_node.getPortalType() == 'Compute Node': if compute_node.getPortalType() == 'Compute Node':
parent_uid_list.append(compute_node.getUid()) parent_uid_list.append(compute_node.getUid())
if is_slave_on_same_instance_tree_allocable:
partition_uid_list.extend([x.getUid() for x in instance_tree_partition_value_list if (x.getParentValue().getUid() == compute_node.getUid())])
elif compute_node.getPortalType() == 'Instance Node': elif compute_node.getPortalType() == 'Instance Node':
shared_instance = compute_node.getSpecialiseValue(portal_type='Software Instance') shared_instance = compute_node.getSpecialiseValue(portal_type='Software Instance')
if shared_instance is not None: if (shared_instance is not None):
# No need to search for original software type/url # No need to search for original software type/url
#query_kw['software_release_url'] = software_release_url #query_kw['software_release_url'] = software_release_url
#query_kw['software_type'] = software_type #query_kw['software_type'] = software_type
...@@ -69,6 +78,7 @@ for compute_node_list in compute_node_list_list: ...@@ -69,6 +78,7 @@ for compute_node_list in compute_node_list_list:
partition_uid_list.append(shared_partition.getUid()) 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())
if len(parent_uid_list) == 0: if len(parent_uid_list) == 0:
# Ensure nothing will be found # Ensure nothing will be found
parent_uid_list.append(-1) parent_uid_list.append(-1)
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>project_uid, software_release_url, software_type, software_instance_portal_type, filter_kw, computer_network_query=None, subscription_reference=None, is_root_slave=False, test_mode=False</string> </value> <value> <string>instance_tree, project_uid, software_release_url, software_type, software_instance_portal_type, filter_kw, computer_network_query=None, subscription_reference=None, test_mode=False</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -120,13 +120,13 @@ def assignComputePartition(software_instance, instance_tree): ...@@ -120,13 +120,13 @@ def assignComputePartition(software_instance, instance_tree):
subscription_reference, instance_tree.isRootSlave()]) subscription_reference, instance_tree.isRootSlave()])
""" """
compute_partition_relative_url = person.Person_findPartition( compute_partition_relative_url = person.Person_findPartition(
instance_tree,
software_instance.getFollowUpUid(portal_type='Project'), software_instance.getFollowUpUid(portal_type='Project'),
software_instance.getUrlString(), software_instance.getUrlString(),
software_instance.getSourceReference(), software_instance.getSourceReference(),
software_instance.getPortalType(), software_instance.getPortalType(),
sla_dict, computer_network_query, sla_dict, computer_network_query,
subscription_reference, subscription_reference
instance_tree.isRootSlave()
) )
return compute_partition_relative_url, tag return compute_partition_relative_url, tag
......
Alarm Tool | SlapOSMasterUpgradeConstraint Alarm Tool | SlapOSMasterUpgradeConstraint
Allocation Supply Cell | AllocationSupplyPath Allocation Supply Cell | AllocationSupplyPath
Allocation Supply Line | AllocationSupplyPath Allocation Supply Line | AllocationSupplyPath
Allocation Supply | AllocationSupply
Allocation Supply | SlapOSVirtualMasterSourceProjectConstraint Allocation Supply | SlapOSVirtualMasterSourceProjectConstraint
Assignment | SlaposAssignmentConstraint Assignment | SlaposAssignmentConstraint
Compute Node | ComputeNodeSlapOSMetadata Compute Node | ComputeNodeSlapOSMetadata
......
...@@ -22,3 +22,4 @@ SlapOSReferenceConstraint ...@@ -22,3 +22,4 @@ SlapOSReferenceConstraint
SlapOSVirtualMasterConstraint SlapOSVirtualMasterConstraint
SlapOSVirtualMasterSourceProjectConstraint SlapOSVirtualMasterSourceProjectConstraint
AllocationSupplyPath AllocationSupplyPath
AllocationSupply
\ No newline at end of file
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