Commit be11fd4f authored by Rafael Monnerat's avatar Rafael Monnerat

Minor improvements for view Computer Usage

See merge request nexedi/slapos.core!571
parents 5c29de81 859ed207
compute_node = context.REQUEST.get('here')
software_release = context
return compute_node.ComputeNode_getSoftwareReleaseState(software_release.getUid())
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>*args, **kwargs</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getSoftwareReleaseStateOnComputeNode</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
current = context.REQUEST.get('here')
if current.getPortalType() == 'Software Release':
software_release = current
compute_node = context
else:
compute_node = current
software_release = context
return compute_node.ComputeNode_getSoftwareReleaseUsage(software_release.getUrlString())
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>*args, **kwargs</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getSoftwareReleaseUsageOnComputeNode</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
software_installation_list = portal.portal_catalog(
portal_type='Software Installation',
default_aggregate_uid=context.getUid(),
validation_state='validated',
limit=1,
url_string={'query': portal.portal_catalog.getResultValue(uid=software_release_uid).getUrlString(), 'key': 'ExactMatch'},
sort_on=(('creation_date', 'DESC'),)
)
if len(software_installation_list) == 0:
return 'Destroyed'
software_installation = software_installation_list[0].getObject()
s = software_installation.getSlapState()
if s == 'start_requested':
return 'Installation requested'
else:
return 'Destruction requested'
return context.getPortalObject().portal_catalog.countResults( portal = context.getPortalObject()
if context.getParentValue().isMemberOf('allocation_scope/open'):
# This is faster but all values are free_for_request == 0 if the computer is closed
return context.getPortalObject().portal_catalog.countResults(
portal_type='Compute Partition', portal_type='Compute Partition',
parent_uid=context.getUid(), parent_uid=context.getUid(),
free_for_request=0, free_for_request=0,
software_release_url=software_release_url software_release_url=software_release_url)[0][0]
)[0][0] else:
computer_uid_list = [i.uid for i in portal.portal_catalog(
portal_type='Compute Partition',
parent_uid=context.getUid()
)]
if not computer_uid_list:
return 0
return portal.portal_catalog.countResults(
portal_type='Software Instance',
default_aggregate_uid=computer_uid_list,
url_string=software_release_url)[0][0]
...@@ -102,13 +102,14 @@ ...@@ -102,13 +102,14 @@
<string>listbox_installation_state</string> <string>listbox_installation_state</string>
<string>listbox_usage</string> <string>listbox_usage</string>
<string>my_busy_compute_partition_list_creation_date</string> <string>my_busy_compute_partition_list_creation_date</string>
<string>listbox_installation_status</string>
<string>my_busy_compute_partition_list_instance_tree_title</string> <string>my_busy_compute_partition_list_instance_tree_title</string>
<string>my_busy_compute_partition_list_instance_title</string> <string>my_busy_compute_partition_list_instance_title</string>
<string>listbox_image</string> <string>listbox_image</string>
<string>listbox_software_release</string> <string>listbox_software_release</string>
<string>my_busy_compute_partition_list_error_reported</string>
<string>my_busy_compute_partition_list_status</string> <string>my_busy_compute_partition_list_status</string>
<string>listbox_status</string>
<string>my_busy_compute_partition_list_error_reported</string>
<string>listbox_error_reported</string>
</list> </list>
</value> </value>
</item> </item>
......
...@@ -145,9 +145,13 @@ ...@@ -145,9 +145,13 @@
<string>Usage</string> <string>Usage</string>
</tuple> </tuple>
<tuple> <tuple>
<string>installation_status</string> <string>status</string>
<string>Status</string> <string>Status</string>
</tuple> </tuple>
<tuple>
<string>error_reported</string>
<string>Reported Message</string>
</tuple>
</list> </list>
</value> </value>
</item> </item>
......
<?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>default</string>
<string>editable</string>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>listbox_error_reported</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>default</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_string_field</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>Reported Error</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: cell.getAggregateRelatedValue(portal_type="Software Instance").SoftwareInstance_hasReportedError(include_message=True, )</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -60,6 +60,10 @@ ...@@ -60,6 +60,10 @@
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value> </value>
</item> </item>
<item>
<key> <string>display_width</string> </key>
<value> <string></string> </value>
</item>
<item> <item>
<key> <string>field_id</string> </key> <key> <string>field_id</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
...@@ -72,6 +76,10 @@ ...@@ -72,6 +76,10 @@
<key> <string>target</string> </key> <key> <string>target</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
</item> </item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary> </dictionary>
</value> </value>
</item> </item>
...@@ -117,7 +125,7 @@ ...@@ -117,7 +125,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>_text</string> </key> <key> <string>_text</string> </key>
<value> <string>cell/Base_getSoftwareReleaseStateOnComputeNode</string> </value> <value> <string>cell/SoftwareInstallation_getInstallationState</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -60,6 +60,10 @@ ...@@ -60,6 +60,10 @@
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value> </value>
</item> </item>
<item>
<key> <string>display_width</string> </key>
<value> <string></string> </value>
</item>
<item> <item>
<key> <string>field_id</string> </key> <key> <string>field_id</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
...@@ -72,6 +76,10 @@ ...@@ -72,6 +76,10 @@
<key> <string>target</string> </key> <key> <string>target</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
</item> </item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary> </dictionary>
</value> </value>
</item> </item>
...@@ -101,7 +109,7 @@ ...@@ -101,7 +109,7 @@
</item> </item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string>listbox_installation_state</string> </value> <value> <string>listbox_usage</string> </value>
</item> </item>
</dictionary> </dictionary>
</value> </value>
...@@ -117,7 +125,7 @@ ...@@ -117,7 +125,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>_text</string> </key> <key> <string>_text</string> </key>
<value> <string>cell/Base_getSoftwareReleaseUsageOnComputeNode</string> </value> <value> <string>python: cell.getAggregateValue(portal_type="Compute Node").ComputeNode_getSoftwareReleaseUsage(cell.getUrlString())</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
if context.getValidationState() != "validated":
return 'Destroyed'
if context.getSlapState() == 'start_requested':
return 'Installation requested'
else:
return 'Destruction requested'
...@@ -50,11 +50,11 @@ ...@@ -50,11 +50,11 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>software_release_uid</string> </value> <value> <string></string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>ComputeNode_getSoftwareReleaseState</string> </value> <value> <string>SoftwareInstallation_getInstallationState</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
from DateTime import DateTime
portal = context.getPortalObject()
error_style = 'background-color: red; display: block; height: 2em; width: 2em; float: left; margin: 5px;'
access_style = 'background-color: green; display: block; height: 2em; width: 2em; float: left; margin: 5px;'
software_installation = portal.portal_catalog.getResultValue(
portal_type='Software Installation',
validation_state='validated',
url_string=context.getUrlString(),
default_aggregate_uid=compute_node_uid
)
if not software_installation or software_installation.getSlapState() == "destroy_requested":
return '<span" style="%s" title="Information not available"></a>' % error_style
d = software_installation.getAccessStatus()
if d.get("no_data") == 1:
return "<a href='%s' style='%s'></a>" % (software_installation.getRelativeUrl(),
error_style)
result = d['text']
date = DateTime(d['created_at'])
limit_date = DateTime() - 0.084
if result.startswith('#error ') or (date - limit_date) < 0:
access_style = error_style
return "<a href='%s' style='%s' title='%s at %s'></a>" % (
software_installation.getRelativeUrl(),
access_style, result, d['created_at'])
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>compute_node_uid</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SoftwareRelease_getCurrentInstallationStateAsHtml</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
kw['portal_type'] = 'Software Installation' portal = context.getPortalObject()
kw['validation_state'] = 'validated'
kw['url_string'] = context.getUrlString()
software_installation_list = context.portal_catalog(**kw) compute_partition_list = portal.portal_catalog(
compute_node_list = [] software_release_url=context.getUrlString(),
allocation_scope_list = ['open/personal', 'open/public'] free_for_request=1,
for software_installation in software_installation_list: group_by=("parent_uid",)
compute_node = software_installation.getAggregateValue() )
if software_installation.getSlapState() == 'start_requested' and \
compute_node.getAllocationScope() in allocation_scope_list:
compute_node_list.append(compute_node)
return compute_node_list return [c.getParentValue() for c in compute_partition_list]
compute_node_list = []
for si in context.portal_catalog(url_string=context.getUrlString(),
portal_type='Software Installation',
validation_state='validated'):
compute_node = si.getAggregateValue()
if si.getSlapState() == 'start_requested' and \
not compute_node.ComputeNode_getSoftwareReleaseUsage(context.getUrlString()) \
and compute_node.getValidationState() == 'validated':
compute_node_list.append(compute_node)
return compute_node_list
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>**kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SoftwareRelease_getUsableComputeNodeWithoutSInstanceList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -61,6 +61,14 @@ ...@@ -61,6 +61,14 @@
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value> </value>
</item> </item>
<item>
<key> <string>display_width</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </value>
</item>
<item> <item>
<key> <string>field_id</string> </key> <key> <string>field_id</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
...@@ -73,6 +81,10 @@ ...@@ -73,6 +81,10 @@
<key> <string>target</string> </key> <key> <string>target</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
</item> </item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary> </dictionary>
</value> </value>
</item> </item>
...@@ -122,7 +134,7 @@ ...@@ -122,7 +134,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>_text</string> </key> <key> <string>_text</string> </key>
<value> <string>python: cell.Base_getSoftwareReleaseUsageOnComputeNode()</string> </value> <value> <string>python: cell.ComputeNode_getSoftwareReleaseUsage(context.getUrlString())</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -71,8 +71,6 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template): ...@@ -71,8 +71,6 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template):
'slapos_cloud/AlarmTool_checkComputeNodeMigrationConsistency', 'slapos_cloud/AlarmTool_checkComputeNodeMigrationConsistency',
'slapos_cloud/AlarmTool_checkInstanceTreeMigrationConsistency', 'slapos_cloud/AlarmTool_checkInstanceTreeMigrationConsistency',
'slapos_cloud/AlarmTool_checkPredecessorToSuccessorMigrationConsistency', 'slapos_cloud/AlarmTool_checkPredecessorToSuccessorMigrationConsistency',
'slapos_cloud/Base_getSoftwareReleaseStateOnComputeNode',
'slapos_cloud/Base_getSoftwareReleaseUsageOnComputeNode',
'slapos_cloud/ComputeNode_afterClone', 'slapos_cloud/ComputeNode_afterClone',
'slapos_cloud/ComputeNode_applyComputerModel', 'slapos_cloud/ComputeNode_applyComputerModel',
'slapos_cloud/ComputeNode_getBusyComputePartitionList', 'slapos_cloud/ComputeNode_getBusyComputePartitionList',
...@@ -110,6 +108,7 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template): ...@@ -110,6 +108,7 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template):
'slapos_cloud/Project_init', 'slapos_cloud/Project_init',
'slapos_cloud/Resource_zGetTrackingList', 'slapos_cloud/Resource_zGetTrackingList',
'slapos_cloud/SoftwareInstallation_requestDestruction', 'slapos_cloud/SoftwareInstallation_requestDestruction',
'slapos_cloud/SoftwareInstallation_getInstallationState',
'slapos_cloud/SoftwareInstance_afterClone', 'slapos_cloud/SoftwareInstance_afterClone',
'slapos_cloud/SoftwareInstance_checkPredecessorToSuccessorMigrationConsistency', 'slapos_cloud/SoftwareInstance_checkPredecessorToSuccessorMigrationConsistency',
'slapos_cloud/SoftwareInstance_getComputeNodeUrl', 'slapos_cloud/SoftwareInstance_getComputeNodeUrl',
...@@ -118,10 +117,8 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template): ...@@ -118,10 +117,8 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template):
'slapos_cloud/SoftwareInstance_getPartitionUrl', 'slapos_cloud/SoftwareInstance_getPartitionUrl',
'slapos_cloud/SoftwareInstance_init', 'slapos_cloud/SoftwareInstance_init',
'slapos_cloud/SoftwareInstance_renameAndRequestStopAction', 'slapos_cloud/SoftwareInstance_renameAndRequestStopAction',
'slapos_cloud/SoftwareRelease_getCurrentInstallationStateAsHtml',
'slapos_cloud/SoftwareRelease_getRelatedNetworkList', 'slapos_cloud/SoftwareRelease_getRelatedNetworkList',
'slapos_cloud/SoftwareRelease_getUsableComputeNodeList', 'slapos_cloud/SoftwareRelease_getUsableComputeNodeList',
'slapos_cloud/SoftwareRelease_getUsableComputeNodeWithoutSInstanceList',
'slapos_cloud/SoftwareInstance_viewRenameAndRequestDestroyAction', 'slapos_cloud/SoftwareInstance_viewRenameAndRequestDestroyAction',
'slapos_cloud/Base_getSupportRequestInProgress', 'slapos_cloud/Base_getSupportRequestInProgress',
'slapos_cloud/SoftwareInstance_checkDuplicationOnInstanceTreeConsistency', 'slapos_cloud/SoftwareInstance_checkDuplicationOnInstanceTreeConsistency',
......
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