Commit 342718e6 authored by Alain Takoudjou's avatar Alain Takoudjou

migrate business template to new format

parent 52d66594
"""
For all software releases, upgrade the Average CPU and Memory Capacity
"""
portal = context.getPortalObject()
portal.portal_catalog.searchAndActivate(
portal_type="Software Release",
method_id="SotftwareRelease_updateCapacityQuantity",
)
...@@ -48,20 +48,6 @@ ...@@ -48,20 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>"""\n
For all software releases, upgrade the Average CPU and Memory Capacity\n
"""\n
\n
portal = context.getPortalObject()\n
\n
portal.portal_catalog.searchAndActivate(\n
portal_type="Software Release",\n
method_id="SotftwareRelease_updateCapacityQuantity",\n
)\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
......
from zExceptions import Unauthorized
if REQUEST is not None:
pass #raise Unauthorized
document = context
portal = document.getPortalObject()
result = []
tioxml_dict = document.ComputerConsumptionTioXMLFile_parseXml()
if tioxml_dict is None:
document.reject(comment="Not usable TioXML data")
else:
packing_list_dict = {}
for movement_dict in tioxml_dict["movement"]:
reference = movement_dict['reference']
if reference in packing_list_dict:
packing_list_dict[reference].append(movement_dict)
else:
packing_list_dict[reference] = [movement_dict]
computer = context.getContributorValue(portal_type="Computer")
for reference, movement_list in packing_list_dict.items():
# Time to create the PL
delivery_template = portal.restrictedTraverse(
portal.portal_preferences.getPreferredInstanceDeliveryTemplate())
delivery = delivery_template.Base_createCloneDocument(batch_mode=1)
# It had been reported for the computer itself so it is pure
# informative.
if computer.getReference() == reference:
person = computer.getSourceAdministrationValue(portal_type="Person")
aggregate_value_list = [computer]
delivery_title = "%s Information Report" % computer.getReference()
else:
if reference.startswith("slapuser"):
reference = reference.replace("slapuser", "slappart")
# Find the partition / software instance / user
partition = portal.portal_catalog.getResultValue(
parent_uid=computer.getUid(),
reference=reference,
portal_type="Computer Partition",
validation_state="validated")
assert partition.getSlapState() == 'busy'
instance = portal.portal_catalog.getResultValue(
default_aggregate_uid=partition.getUid(),
portal_type="Software Instance",
validation_state="validated")
subscription = instance.getSpecialiseValue(
portal_type="Hosting Subscription")
person = subscription.getDestinationSectionValue(
portal_type="Person")
aggregate_value_list = [partition, instance, subscription]
delivery_title = "%s Consumption Usage" % instance.getReference()
delivery.edit(
title=delivery_title,
destination=person.getRelativeUrl(),
destination_decision=person.getRelativeUrl(),
start_date=context.getCreationDate(),
)
result.append(delivery.getRelativeUrl())
for movement in movement_list:
service = portal.restrictedTraverse(movement['resource'])
delivery.newContent(
portal_type="Sale Packing List Line",
title=movement['title'],
quantity=movement['quantity'],
aggregate_value_list=aggregate_value_list,
resource_value=service,
quantity_unit=service.getQuantityUnit(),
)
delivery.confirm(comment="Created from %s" % context.getRelativeUrl())
delivery.start()
delivery.stop()
delivery.deliver()
delivery.startBuilding()
document.share(comment="Created packing list: %s" % result)
return result
...@@ -48,97 +48,6 @@ ...@@ -48,97 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>from zExceptions import Unauthorized\n
if REQUEST is not None:\n
pass #raise Unauthorized\n
\n
document = context\n
portal = document.getPortalObject()\n
result = []\n
\n
tioxml_dict = document.ComputerConsumptionTioXMLFile_parseXml()\n
if tioxml_dict is None:\n
document.reject(comment="Not usable TioXML data")\n
else:\n
packing_list_dict = {}\n
for movement_dict in tioxml_dict["movement"]:\n
reference = movement_dict[\'reference\']\n
if reference in packing_list_dict:\n
packing_list_dict[reference].append(movement_dict)\n
else:\n
packing_list_dict[reference] = [movement_dict]\n
\n
computer = context.getContributorValue(portal_type="Computer")\n
for reference, movement_list in packing_list_dict.items():\n
\n
# Time to create the PL\n
delivery_template = portal.restrictedTraverse(\n
portal.portal_preferences.getPreferredInstanceDeliveryTemplate())\n
delivery = delivery_template.Base_createCloneDocument(batch_mode=1)\n
\n
# It had been reported for the computer itself so it is pure\n
# informative.\n
if computer.getReference() == reference:\n
person = computer.getSourceAdministrationValue(portal_type="Person")\n
aggregate_value_list = [computer]\n
delivery_title = "%s Information Report" % computer.getReference()\n
else:\n
if reference.startswith("slapuser"):\n
reference = reference.replace("slapuser", "slappart") \n
# Find the partition / software instance / user\n
partition = portal.portal_catalog.getResultValue(\n
parent_uid=computer.getUid(),\n
reference=reference,\n
portal_type="Computer Partition",\n
validation_state="validated")\n
assert partition.getSlapState() == \'busy\'\n
\n
instance = portal.portal_catalog.getResultValue(\n
default_aggregate_uid=partition.getUid(),\n
portal_type="Software Instance",\n
validation_state="validated")\n
\n
subscription = instance.getSpecialiseValue(\n
portal_type="Hosting Subscription")\n
\n
person = subscription.getDestinationSectionValue(\n
portal_type="Person")\n
\n
aggregate_value_list = [partition, instance, subscription]\n
delivery_title = "%s Consumption Usage" % instance.getReference()\n
\n
delivery.edit(\n
title=delivery_title,\n
destination=person.getRelativeUrl(),\n
destination_decision=person.getRelativeUrl(),\n
start_date=context.getCreationDate(),\n
)\n
\n
result.append(delivery.getRelativeUrl())\n
\n
for movement in movement_list:\n
service = portal.restrictedTraverse(movement[\'resource\'])\n
delivery.newContent(\n
portal_type="Sale Packing List Line",\n
title=movement[\'title\'],\n
quantity=movement[\'quantity\'],\n
aggregate_value_list=aggregate_value_list,\n
resource_value=service,\n
quantity_unit=service.getQuantityUnit(),\n
)\n
delivery.confirm(comment="Created from %s" % context.getRelativeUrl())\n
delivery.start()\n
delivery.stop()\n
delivery.deliver()\n
delivery.startBuilding()\n
\n
document.share(comment="Created packing list: %s" % result)\n
\n
return result\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value> <value> <string>REQUEST=None</string> </value>
......
if REQUEST is not None:
raise Unauthorized("Unauthorized call script from URL")
portal = context.getPortalObject()
packing_list_line = portal.portal_catalog.getResultValue(
sort_on=("creation_date", "DESC"),
portal_type="Sale Packing List Line",
default_resource_uid = context.service_module.cpu_load_percent.getUid(),
default_aggregate_uid=context.getUid())
if packing_list_line is not None:
return packing_list_line.getQuantity()
return 0.0
...@@ -48,25 +48,6 @@ ...@@ -48,25 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>if REQUEST is not None:\n
raise Unauthorized("Unauthorized call script from URL")\n
\n
portal = context.getPortalObject()\n
\n
packing_list_line = portal.portal_catalog.getResultValue(\n
sort_on=("creation_date", "DESC"),\n
portal_type="Sale Packing List Line",\n
default_resource_uid = context.service_module.cpu_load_percent.getUid(),\n
default_aggregate_uid=context.getUid())\n
\n
if packing_list_line is not None:\n
return packing_list_line.getQuantity()\n
\n
return 0.0\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value> <value> <string>REQUEST=None</string> </value>
......
if REQUEST is not None:
raise Unauthorized("Unauthorized call script from URL")
model_id = context.getWattConsumptionModel("no_model")
######
# Introduce your Consumption Model here
######
def consumption_model_shuttle_ds61_i7(load):
""" Expected consumed watts for the computer load
"""
if load <= 25:
return 21.5 + 1.06*load
else:
return 48 + 0.29*load
def consumption_model_shuttle_nuc_i7(load):
""" Expected consumed watts for the computer load
"""
if load <= 25:
return 8.5 + 0.46*load
else:
return 20 + 0.08*load
def consumption_model_rikomagic_mk802iv(load):
""" Expected consumed watts for the computer load
"""
if load <= 25:
return 2.2 + 0.04*load
else:
return 3.2 + 0.008*load
def no_model(load):
return 0
model_map = {
"shuttle_ds61_i7" : consumption_model_shuttle_ds61_i7,
"rikomagic_mk802iv": consumption_model_rikomagic_mk802iv,
"intel_nuc_i7": consumption_model_shuttle_nuc_i7
}
if cpu_load_percentage is None:
cpu_load_percentage = context.Computer_getLatestCPUPercentLoad()
cpu_load_percentage += partition_increment
return model_map.get(model_id, no_model)(cpu_load_percentage)
...@@ -48,60 +48,6 @@ ...@@ -48,60 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
if REQUEST is not None:\n
raise Unauthorized("Unauthorized call script from URL")\n
\n
model_id = context.getWattConsumptionModel("no_model")\n
\n
######\n
# Introduce your Consumption Model here\n
######\n
def consumption_model_shuttle_ds61_i7(load):\n
""" Expected consumed watts for the computer load\n
"""\n
if load <= 25:\n
return 21.5 + 1.06*load\n
else:\n
return 48 + 0.29*load\n
\n
def consumption_model_shuttle_nuc_i7(load):\n
""" Expected consumed watts for the computer load\n
"""\n
if load <= 25:\n
return 8.5 + 0.46*load\n
else:\n
return 20 + 0.08*load\n
\n
def consumption_model_rikomagic_mk802iv(load):\n
""" Expected consumed watts for the computer load\n
"""\n
if load <= 25:\n
return 2.2 + 0.04*load\n
else:\n
return 3.2 + 0.008*load\n
\n
def no_model(load):\n
return 0\n
\n
model_map = {\n
"shuttle_ds61_i7" : consumption_model_shuttle_ds61_i7,\n
"rikomagic_mk802iv": consumption_model_rikomagic_mk802iv,\n
"intel_nuc_i7": consumption_model_shuttle_nuc_i7\n
}\n
if cpu_load_percentage is None:\n
cpu_load_percentage = context.Computer_getLatestCPUPercentLoad()\n
\n
cpu_load_percentage += partition_increment\n
\n
return model_map.get(model_id, no_model)(cpu_load_percentage)\n
]]></string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>cpu_load_percentage=None, partition_increment=0, REQUEST=None</string> </value> <value> <string>cpu_load_percentage=None, partition_increment=0, REQUEST=None</string> </value>
......
if REQUEST is not None:
raise Unauthorized("Unauthorized call script from URL")
portal = context.getPortalObject()
resource_uid = context.service_module.zero_emission_ratio.getUid()
packing_list_line_list = portal.portal_catalog(
limit=1,
sort_on=("creation_date", "DESC"),
portal_type="Sale Packing List Line",
default_resource_uid = resource_uid,
default_aggregate_uid=context.getUid())
if len(packing_list_line_list):
quantity = packing_list_line_list[0].getQuantity()
if quantity > 0:
return quantity
return 0.0
...@@ -48,34 +48,6 @@ ...@@ -48,34 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
if REQUEST is not None:\n
raise Unauthorized("Unauthorized call script from URL")\n
\n
portal = context.getPortalObject()\n
\n
resource_uid = context.service_module.zero_emission_ratio.getUid()\n
\n
packing_list_line_list = portal.portal_catalog(\n
limit=1,\n
sort_on=("creation_date", "DESC"),\n
portal_type="Sale Packing List Line",\n
default_resource_uid = resource_uid,\n
default_aggregate_uid=context.getUid())\n
\n
if len(packing_list_line_list):\n
quantity = packing_list_line_list[0].getQuantity()\n
if quantity > 0:\n
return quantity\n
\n
return 0.0\n
]]></string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value> <value> <string>REQUEST=None</string> </value>
......
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
computer = context
reference = "TIOCONS-%s-%s" % (computer.getReference(), source_reference)
version = "%s" % context.getPortalObject().portal_ids.generateNewId(
id_group=('slap_tioxml_consumption_reference', reference), default=1)
document = portal.consumption_document_module.newContent(
portal_type="Computer Consumption TioXML File",
source_reference=source_reference,
title="%s consumption (%s)" % (computer.getReference(), source_reference),
reference=reference,
version=version,
data=consumption_xml,
classification="personal",
publication_section="other",
contributor_value=computer,
)
document.submit()
return document.getRelativeUrl()
...@@ -48,34 +48,6 @@ ...@@ -48,34 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>from zExceptions import Unauthorized\n
if REQUEST is not None:\n
raise Unauthorized\n
\n
portal = context.getPortalObject()\n
computer = context\n
\n
reference = "TIOCONS-%s-%s" % (computer.getReference(), source_reference)\n
version = "%s" % context.getPortalObject().portal_ids.generateNewId(\n
id_group=(\'slap_tioxml_consumption_reference\', reference), default=1)\n
\n
document = portal.consumption_document_module.newContent(\n
portal_type="Computer Consumption TioXML File",\n
source_reference=source_reference,\n
title="%s consumption (%s)" % (computer.getReference(), source_reference),\n
reference=reference,\n
version=version,\n
data=consumption_xml,\n
classification="personal",\n
publication_section="other",\n
contributor_value=computer,\n
)\n
document.submit()\n
return document.getRelativeUrl()\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>source_reference, consumption_xml, REQUEST=None</string> </value> <value> <string>source_reference, consumption_xml, REQUEST=None</string> </value>
......
instance, delta_co2 = context.HostingSubscription_getMostEcoEfficientSoftwareInstance()
if instance is None:
return None
master_node = instance.SoftwareInstance_getResilientMasterNode()
if master_node is None:
return None
if instance.getRelativeUrl() != master_node.getRelativeUrl():
master_delta_co2 = master_node.SoftwareInstance_getFutureDeltaCO2()
saving_ratio = (master_delta_co2-delta_co2)/master_delta_co2
return "Improve Power efficiency in %s%% by using %s instance as Main Node. We recommend you to a take over." % (int(saving_ratio*100), instance.getTitle())
return None
...@@ -48,27 +48,6 @@ ...@@ -48,27 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>instance, delta_co2 = context.HostingSubscription_getMostEcoEfficientSoftwareInstance()\n
\n
if instance is None:\n
return None \n
\n
master_node = instance.SoftwareInstance_getResilientMasterNode()\n
\n
if master_node is None:\n
return None \n
\n
if instance.getRelativeUrl() != master_node.getRelativeUrl():\n
master_delta_co2 = master_node.SoftwareInstance_getFutureDeltaCO2()\n
saving_ratio = (master_delta_co2-delta_co2)/master_delta_co2\n
return "Improve Power efficiency in %s%% by using %s instance as Main Node. We recommend you to a take over." % (int(saving_ratio*100), instance.getTitle())\n
\n
\n
return None\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
......
partition_co2_dict = {}
min_delta_co2 = 2000
minimal_candidate = None
for software_instance in context.getSpecialiseRelatedValueList(portal_type="Software Instance"):
delta_co2 = software_instance.SoftwareInstance_getFutureDeltaCO2()
if delta_co2 != "Not Applicable":
if delta_co2 < min_delta_co2:
minimal_candidate = software_instance
min_delta_co2 = delta_co2
elif (delta_co2 == min_delta_co2) and \
(software_instance.getTitle() in ["kvm0", "runner0"]):
minimal_candidate = software_instance
return minimal_candidate, min_delta_co2
...@@ -48,29 +48,6 @@ ...@@ -48,29 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
partition_co2_dict = {}\n
min_delta_co2 = 2000\n
minimal_candidate = None\n
\n
for software_instance in context.getSpecialiseRelatedValueList(portal_type="Software Instance"):\n
delta_co2 = software_instance.SoftwareInstance_getFutureDeltaCO2() \n
if delta_co2 != "Not Applicable":\n
if delta_co2 < min_delta_co2:\n
minimal_candidate = software_instance\n
min_delta_co2 = delta_co2\n
elif (delta_co2 == min_delta_co2) and \\\n
(software_instance.getTitle() in ["kvm0", "runner0"]):\n
minimal_candidate = software_instance\n
\n
return minimal_candidate, min_delta_co2\n
]]></string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
......
import random
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, ComplexQuery
person = context
computer_partition = None
query_kw = {
'software_release_url': software_release_url,
'portal_type': 'Computer Partition',
}
if software_instance_portal_type == "Slave Instance":
query_kw['free_for_request'] = 0
query_kw['software_type'] = software_type
elif software_instance_portal_type == "Software Instance":
query_kw['free_for_request'] = 1
else:
raise NotImplementedError("Unknown portal type %s"%
software_instance_portal_type)
# support SLA
# Explicit location
explicit_location = False
if "computer_guid" in filter_kw:
explicit_location = True
query_kw["parent_reference"] = SimpleQuery(parent_reference=filter_kw.pop("computer_guid"))
if "instance_guid" in filter_kw:
explicit_location = True
portal = context.getPortalObject()
instance_guid = filter_kw.pop("instance_guid")
query_kw["aggregate_related_reference"] = SimpleQuery(aggregate_related_reference=instance_guid)
if 'network_guid' in filter_kw:
network_guid = filter_kw.pop('network_guid')
query_kw["default_subordination_reference"] = SimpleQuery(default_subordination_reference=network_guid)
if computer_network_query:
if query_kw.get("default_subordination_reference"):
query_kw["default_subordination_reference"] = ComplexQuery(
query_kw["default_subordination_reference"],
computer_network_query
)
else:
query_kw["default_subordination_reference"] = computer_network_query
if "retention_delay" in filter_kw:
filter_kw.pop("retention_delay")
computer_base_category_list = [
'group',
'cpu_core',
'cpu_frequency',
'cpu_type',
'local_area_network_type',
'region',
'memory_size',
'memory_type',
'storage_capacity',
'storage_interface',
'storage_redundancy',
]
for base_category in computer_base_category_list:
if base_category in filter_kw:
category_relative_url = "%s" % filter_kw.pop(base_category)
# XXX Small protection to prevent entering strange strings
category = context.getPortalObject().portal_categories[base_category].restrictedTraverse(str(category_relative_url), None)
if category is None:
query_kw["uid"] = "-1"
else:
query_kw["%s_uid" % base_category] = category.getUid()
query_kw["capacity_scope_uid"] = context.getPortalObject().portal_categories.capacity_scope.open.getUid()
# if not explicit_location:
# # Only allocation on public computer
# query_kw["allocation_scope_uid"] = context.getPortalObject().portal_categories.allocation_scope.open.public.getUid()
if filter_kw.keys():
# XXX Drop all unexpected keys
query_kw["uid"] = "-1"
if test_mode:
return bool(len(context.portal_catalog(limit=1, **query_kw)))
# Get only one computer_partition per computer
computer_partition_list = context.portal_catalog(group_by="parent_uid", **query_kw)
software_release_list = context.portal_catalog(
portal_type="Software Release",
url_string=software_release_url
)
if len(software_release_list) == 0:
# Forbid to allocate partitions without an existing Software Release Document.
raise KeyError(len(software_release_list))
delta_co2_contribution_list = software_release_list[0].SoftwareRelease_getDeltaCO2List(computer_partition_list)
isTransitionPossible = context.getPortalObject().portal_workflow.isTransitionPossible
while len(delta_co2_contribution_list):
partition_candidate_list = delta_co2_contribution_list.pop(min(delta_co2_contribution_list))
for computer_partition_candidate in partition_candidate_list:
computer_partition_candidate = computer_partition_candidate.getObject()
if software_instance_portal_type == "Software Instance":
# Check if the computer partition can be marked as busy
if isTransitionPossible(computer_partition_candidate, 'mark_busy'):
computer_partition = computer_partition_candidate
computer_partition.markBusy()
break
elif computer_partition_candidate.getSlapState() == "busy":
# Only assign slave instance on busy partition
computer_partition = computer_partition_candidate
break
if computer_partition is None:
raise ValueError('It was not possible to find free Computer Partition')
# lock computer partition
computer_partition.serialize()
return computer_partition.getRelativeUrl()
...@@ -48,132 +48,6 @@ ...@@ -48,132 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>import random\n
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, ComplexQuery\n
person = context\n
\n
computer_partition = None\n
query_kw = {\n
\'software_release_url\': software_release_url,\n
\'portal_type\': \'Computer Partition\',\n
}\n
if software_instance_portal_type == "Slave Instance":\n
query_kw[\'free_for_request\'] = 0\n
query_kw[\'software_type\'] = software_type\n
elif software_instance_portal_type == "Software Instance":\n
query_kw[\'free_for_request\'] = 1\n
else:\n
raise NotImplementedError("Unknown portal type %s"%\n
software_instance_portal_type)\n
\n
# support SLA\n
\n
# Explicit location\n
explicit_location = False\n
if "computer_guid" in filter_kw:\n
explicit_location = True\n
query_kw["parent_reference"] = SimpleQuery(parent_reference=filter_kw.pop("computer_guid"))\n
\n
if "instance_guid" in filter_kw:\n
explicit_location = True\n
portal = context.getPortalObject()\n
instance_guid = filter_kw.pop("instance_guid")\n
query_kw["aggregate_related_reference"] = SimpleQuery(aggregate_related_reference=instance_guid)\n
\n
if \'network_guid\' in filter_kw:\n
network_guid = filter_kw.pop(\'network_guid\')\n
query_kw["default_subordination_reference"] = SimpleQuery(default_subordination_reference=network_guid)\n
\n
if computer_network_query:\n
if query_kw.get("default_subordination_reference"):\n
query_kw["default_subordination_reference"] = ComplexQuery(\n
query_kw["default_subordination_reference"],\n
computer_network_query\n
)\n
else:\n
query_kw["default_subordination_reference"] = computer_network_query\n
\n
if "retention_delay" in filter_kw:\n
filter_kw.pop("retention_delay")\n
\n
computer_base_category_list = [\n
\'group\',\n
\'cpu_core\',\n
\'cpu_frequency\',\n
\'cpu_type\',\n
\'local_area_network_type\',\n
\'region\',\n
\'memory_size\',\n
\'memory_type\',\n
\'storage_capacity\',\n
\'storage_interface\',\n
\'storage_redundancy\',\n
]\n
for base_category in computer_base_category_list:\n
if base_category in filter_kw:\n
category_relative_url = "%s" % filter_kw.pop(base_category)\n
# XXX Small protection to prevent entering strange strings\n
category = context.getPortalObject().portal_categories[base_category].restrictedTraverse(str(category_relative_url), None)\n
if category is None:\n
query_kw["uid"] = "-1"\n
else:\n
query_kw["%s_uid" % base_category] = category.getUid()\n
\n
query_kw["capacity_scope_uid"] = context.getPortalObject().portal_categories.capacity_scope.open.getUid()\n
# if not explicit_location:\n
# # Only allocation on public computer\n
# query_kw["allocation_scope_uid"] = context.getPortalObject().portal_categories.allocation_scope.open.public.getUid()\n
\n
if filter_kw.keys():\n
# XXX Drop all unexpected keys\n
query_kw["uid"] = "-1"\n
\n
if test_mode:\n
return bool(len(context.portal_catalog(limit=1, **query_kw)))\n
\n
# Get only one computer_partition per computer\n
computer_partition_list = context.portal_catalog(group_by="parent_uid", **query_kw)\n
\n
software_release_list = context.portal_catalog(\n
portal_type="Software Release",\n
url_string=software_release_url\n
) \n
\n
if len(software_release_list) == 0:\n
# Forbid to allocate partitions without an existing Software Release Document.\n
raise KeyError(len(software_release_list))\n
\n
delta_co2_contribution_list = software_release_list[0].SoftwareRelease_getDeltaCO2List(computer_partition_list)\n
\n
isTransitionPossible = context.getPortalObject().portal_workflow.isTransitionPossible\n
\n
while len(delta_co2_contribution_list):\n
partition_candidate_list = delta_co2_contribution_list.pop(min(delta_co2_contribution_list))\n
\n
for computer_partition_candidate in partition_candidate_list:\n
computer_partition_candidate = computer_partition_candidate.getObject()\n
if software_instance_portal_type == "Software Instance":\n
# Check if the computer partition can be marked as busy\n
if isTransitionPossible(computer_partition_candidate, \'mark_busy\'):\n
computer_partition = computer_partition_candidate\n
computer_partition.markBusy()\n
break\n
elif computer_partition_candidate.getSlapState() == "busy":\n
# Only assign slave instance on busy partition\n
computer_partition = computer_partition_candidate\n
break\n
\n
if computer_partition is None:\n
raise ValueError(\'It was not possible to find free Computer Partition\')\n
\n
# lock computer partition\n
computer_partition.serialize()\n
\n
return computer_partition.getRelativeUrl()\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>software_release_url, software_type, software_instance_portal_type, filter_kw, computer_network_query=None, test_mode=False</string> </value> <value> <string>software_release_url, software_type, software_instance_portal_type, filter_kw, computer_network_query=None, test_mode=False</string> </value>
......
portal = context.getPortalObject()
software_release_url = context.getUrlString()
resource_uid = context.service_module.cpu_load_percent.getUid()
# Select all software instances from a certain Software Release
packing_list_line_list = portal.portal_catalog(
limit=20,
sort_on=("creation_date", "DESC"),
portal_type="Sale Packing List Line",
default_resource_uid = resource_uid,
default_aggregate_uid=[context.getUid()]
)
if len(packing_list_line_list):
# Remove the /8 and update the value on the clients.
return sum([i.getQuantity() for i in packing_list_line_list])/len(packing_list_line_list)
return 0.0
...@@ -48,30 +48,6 @@ ...@@ -48,30 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n
\n
software_release_url = context.getUrlString()\n
\n
resource_uid = context.service_module.cpu_load_percent.getUid()\n
\n
# Select all software instances from a certain Software Release\n
packing_list_line_list = portal.portal_catalog(\n
limit=20,\n
sort_on=("creation_date", "DESC"),\n
portal_type="Sale Packing List Line",\n
default_resource_uid = resource_uid,\n
default_aggregate_uid=[context.getUid()]\n
)\n
\n
if len(packing_list_line_list):\n
# Remove the /8 and update the value on the clients.\n
return sum([i.getQuantity() for i in packing_list_line_list])/len(packing_list_line_list)\n
\n
return 0.0\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
......
if REQUEST is not None:
raise Unauthorized
computer_partition_list = context.getAggregateValueList(portal_type="Computer Partition")
current_watt = context.SoftwareRelease_getDeltaCO2List(
computer_partition_list, context.SoftwareInstance_getAverageCPULoad()
)
return current_watt.keys()[0]
...@@ -48,20 +48,6 @@ ...@@ -48,20 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>if REQUEST is not None:\n
raise Unauthorized\n
\n
computer_partition_list = context.getAggregateValueList(portal_type="Computer Partition")\n
\n
current_watt = context.SoftwareRelease_getDeltaCO2List(\n
computer_partition_list, context.SoftwareInstance_getAverageCPULoad()\n
)\n
\n
return current_watt.keys()[0]\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value> <value> <string>REQUEST=None</string> </value>
......
if REQUEST is not None:
raise Unauthorized
computer_partition_list = context.getAggregateValueList(portal_type="Computer Partition")
future_watt = "Not Applicable"
master_node = context.SoftwareInstance_getResilientMasterNode()
if master_node is not None:
future_watt = context.SoftwareRelease_getDeltaCO2List(
computer_partition_list, master_node.SoftwareInstance_getAverageCPULoad()
)
future_watt = future_watt.keys()[0]
return future_watt
...@@ -48,25 +48,6 @@ ...@@ -48,25 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>if REQUEST is not None:\n
raise Unauthorized\n
\n
computer_partition_list = context.getAggregateValueList(portal_type="Computer Partition")\n
\n
future_watt = "Not Applicable"\n
\n
master_node = context.SoftwareInstance_getResilientMasterNode()\n
if master_node is not None:\n
future_watt = context.SoftwareRelease_getDeltaCO2List(\n
computer_partition_list, master_node.SoftwareInstance_getAverageCPULoad()\n
)\n
future_watt = future_watt.keys()[0]\n
\n
return future_watt\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value> <value> <string>REQUEST=None</string> </value>
......
portal = context.getPortalObject()
packing_list_line = portal.portal_catalog.getResultValue(
sort_on=("creation_date", "DESC"),
portal_type="Sale Packing List Line",
default_resource_uid = context.service_module.cpu_load_percent.getUid(),
default_aggregate_uid=context.getUid())
if packing_list_line is not None:
return packing_list_line.getQuantity()
return 0.0
...@@ -48,22 +48,6 @@ ...@@ -48,22 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n
\n
packing_list_line = portal.portal_catalog.getResultValue(\n
sort_on=("creation_date", "DESC"),\n
portal_type="Sale Packing List Line",\n
default_resource_uid = context.service_module.cpu_load_percent.getUid(),\n
default_aggregate_uid=context.getUid())\n
\n
if packing_list_line is not None:\n
return packing_list_line.getQuantity()\n
\n
return 0.0\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
......
"""
This script may contains specific prototyping code for
get master done for resilience.
"""
title = context.getTitle()
if not (title.startswith("kvm") or title.startswith("runner")):
# This instance is not a clone from resilience
return None
hosting_subscription = context.getSpecialiseValue()
for instance in hosting_subscription.getSpecialiseRelatedValueList(
portal_type="Software Instance"):
if instance.getTitle() in ["kvm0", "runner0"]:
return instance
return None
...@@ -48,29 +48,6 @@ ...@@ -48,29 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>"""\n
This script may contains specific prototyping code for \n
get master done for resilience.\n
"""\n
\n
title = context.getTitle()\n
\n
if not (title.startswith("kvm") or title.startswith("runner")):\n
# This instance is not a clone from resilience\n
return None \n
\n
hosting_subscription = context.getSpecialiseValue()\n
\n
for instance in hosting_subscription.getSpecialiseRelatedValueList(\n
portal_type="Software Instance"):\n
if instance.getTitle() in ["kvm0", "runner0"]:\n
return instance\n
\n
return None\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
......
computer_partition_list = context.getAggregateValueList(portal_type="Computer Partition")
master_node = context.SoftwareInstance_getResilientMasterNode()
current_watt = context.SoftwareRelease_getDeltaCO2List(
computer_partition_list, context.SoftwareInstance_getAverageCPULoad()
)
current_watt = current_watt.keys()
master_node = context.SoftwareInstance_getResilientMasterNode()
if master_node is not None:
future_watt = context.SoftwareRelease_getDeltaCO2List(
computer_partition_list, master_node.SoftwareInstance_getAverageCPULoad()
)
future_watt = future_watt.keys()[0]
return current_watt, future_watt
...@@ -48,27 +48,6 @@ ...@@ -48,27 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>computer_partition_list = context.getAggregateValueList(portal_type="Computer Partition")\n
\n
master_node = context.SoftwareInstance_getResilientMasterNode()\n
\n
current_watt = context.SoftwareRelease_getDeltaCO2List(\n
computer_partition_list, context.SoftwareInstance_getAverageCPULoad()\n
)\n
current_watt = current_watt.keys()\n
\n
master_node = context.SoftwareInstance_getResilientMasterNode()\n
if master_node is not None:\n
future_watt = context.SoftwareRelease_getDeltaCO2List(\n
computer_partition_list, master_node.SoftwareInstance_getAverageCPULoad()\n
)\n
future_watt = future_watt.keys()[0]\n
\n
return current_watt, future_watt\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
......
portal = context.getPortalObject()
software_release_url = context.getUrlString()
resource_uid = context.service_module.cpu_load_percent.getUid()
# Select all software instances from a certain Software Release
software_instance_list = portal.portal_catalog(
portal_type="Software Instance",
limit=100,
url_string=software_release_url)
packing_list_line_list = portal.portal_catalog(
limit=100,
sort_on=("creation_date", "DESC"),
portal_type="Sale Packing List Line",
default_resource_uid = resource_uid,
default_aggregate_uid=[i.getUid() for i in software_instance_list]
)
if len(packing_list_line_list):
return sum([i.getQuantity() for i in packing_list_line_list])/len(packing_list_line_list)
return 0.0
...@@ -48,34 +48,6 @@ ...@@ -48,34 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n
\n
software_release_url = context.getUrlString()\n
\n
resource_uid = context.service_module.cpu_load_percent.getUid()\n
\n
# Select all software instances from a certain Software Release\n
software_instance_list = portal.portal_catalog(\n
portal_type="Software Instance",\n
limit=100,\n
url_string=software_release_url)\n
\n
packing_list_line_list = portal.portal_catalog(\n
limit=100,\n
sort_on=("creation_date", "DESC"),\n
portal_type="Sale Packing List Line",\n
default_resource_uid = resource_uid,\n
default_aggregate_uid=[i.getUid() for i in software_instance_list]\n
)\n
\n
if len(packing_list_line_list):\n
return sum([i.getQuantity() for i in packing_list_line_list])/len(packing_list_line_list)\n
\n
return 0.0\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
......
portal = context.getPortalObject()
software_release_url = context.getUrlString()
resource_uid = context.service_module.memory_used.getUid()
# Select all software instances from a certain Software Release
software_instance_list = portal.portal_catalog(
portal_type="Software Instance",
limit=100,
url_string=software_release_url)
packing_list_line_list = portal.portal_catalog(
limit=100,
sort_on=("creation_date", "DESC"),
portal_type="Sale Packing List Line",
default_resource_uid = resource_uid,
default_aggregate_uid=[i.getUid() for i in software_instance_list]
)
if len(packing_list_line_list):
return sum([i.getQuantity() for i in packing_list_line_list])/len(packing_list_line_list)
return 0.0
...@@ -48,34 +48,6 @@ ...@@ -48,34 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>portal = context.getPortalObject()\n
\n
software_release_url = context.getUrlString()\n
\n
resource_uid = context.service_module.memory_used.getUid()\n
\n
# Select all software instances from a certain Software Release\n
software_instance_list = portal.portal_catalog(\n
portal_type="Software Instance",\n
limit=100,\n
url_string=software_release_url)\n
\n
packing_list_line_list = portal.portal_catalog(\n
limit=100,\n
sort_on=("creation_date", "DESC"),\n
portal_type="Sale Packing List Line",\n
default_resource_uid = resource_uid,\n
default_aggregate_uid=[i.getUid() for i in software_instance_list]\n
)\n
\n
if len(packing_list_line_list):\n
return sum([i.getQuantity() for i in packing_list_line_list])/len(packing_list_line_list)\n
\n
return 0.0\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
......
"""
Make a list with delta CO2 values
"""
if simulated_cpu_load is not None:
partition_average_cpu_load = simulated_cpu_load
else:
partition_average_cpu_load = context.getCpuCapacityQuantity()
partition_delta_co2_dict = {}
for computer_partition in computer_partition_list:
computer = computer_partition.getParentValue()
computer_zero_emission_ratio = computer.Computer_getZeroEmissionRatio()
computer_cpu_load_percentage = computer.Computer_getLatestCPUPercentLoad()
computer_watt = computer.Computer_getWattConsumption(computer_cpu_load_percentage)
partition_watt = computer.Computer_getWattConsumption(
computer_cpu_load_percentage + partition_average_cpu_load)
delta_watt = (partition_watt-computer_watt)
delta_co2 = delta_watt - delta_watt*(computer_zero_emission_ratio/100)
if delta_co2 in partition_delta_co2_dict:
partition_delta_co2_dict[delta_co2].append(computer_partition)
else:
partition_delta_co2_dict[delta_co2] = [computer_partition]
return partition_delta_co2_dict
...@@ -48,40 +48,6 @@ ...@@ -48,40 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>"""\n
Make a list with delta CO2 values\n
"""\n
\n
if simulated_cpu_load is not None:\n
partition_average_cpu_load = simulated_cpu_load\n
else:\n
partition_average_cpu_load = context.getCpuCapacityQuantity()\n
\n
partition_delta_co2_dict = {} \n
\n
for computer_partition in computer_partition_list:\n
computer = computer_partition.getParentValue()\n
computer_zero_emission_ratio = computer.Computer_getZeroEmissionRatio()\n
computer_cpu_load_percentage = computer.Computer_getLatestCPUPercentLoad()\n
computer_watt = computer.Computer_getWattConsumption(computer_cpu_load_percentage)\n
\n
partition_watt = computer.Computer_getWattConsumption(\n
computer_cpu_load_percentage + partition_average_cpu_load)\n
\n
delta_watt = (partition_watt-computer_watt)\n
\n
delta_co2 = delta_watt - delta_watt*(computer_zero_emission_ratio/100)\n
\n
if delta_co2 in partition_delta_co2_dict:\n
partition_delta_co2_dict[delta_co2].append(computer_partition)\n
else:\n
partition_delta_co2_dict[delta_co2] = [computer_partition]\n
\n
return partition_delta_co2_dict\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>computer_partition_list, simulated_cpu_load=None</string> </value> <value> <string>computer_partition_list, simulated_cpu_load=None</string> </value>
......
"""
"""
edit_kw = {}
average_cpu_load = context.SoftwareRelease_getAverageConsumedCPULoad()
average_memory_usage = context.SoftwareRelease_getAverageConsumedMemory()
if average_cpu_load != context.getCpuCapacityQuantity():
edit_kw["cpu_capacity_quantity"] = average_cpu_load
if average_memory_usage != context.getMemoryCapacityQuantity():
edit_kw["memory_capacity_quantity"] = average_memory_usage
if len(edit_kw) > 0:
context.edit(**edit_kw)
...@@ -48,29 +48,6 @@ ...@@ -48,29 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
"""\n
"""\n
edit_kw = {}\n
average_cpu_load = context.SoftwareRelease_getAverageConsumedCPULoad()\n
average_memory_usage = context.SoftwareRelease_getAverageConsumedMemory()\n
\n
\n
if average_cpu_load != context.getCpuCapacityQuantity():\n
edit_kw["cpu_capacity_quantity"] = average_cpu_load\n
\n
if average_memory_usage != context.getMemoryCapacityQuantity(): \n
edit_kw["memory_capacity_quantity"] = average_memory_usage\n
\n
if len(edit_kw) > 0:\n
context.edit(**edit_kw)\n
]]></string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
......
...@@ -32,211 +32,6 @@ ...@@ -32,211 +32,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_text</string> </key>
<value> <unicode encoding="cdata"><![CDATA[
<!-- Tested with chromium 12 and --ignore-certificate-errors --disable-translate --disable-web-security options -->\n
<html xmlns:tal="http://xml.zope.org/namespaces/tal"\n
xmlns:metal="http://xml.zope.org/namespaces/metal">\n
<head>\n
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\n
<title>Test KVM</title>\n
</head>\n
<body>\n
<table cellpadding="1" cellspacing="1" border="1">\n
<thead>\n
<tr><td rowspan="1" colspan="3">testkvm</td></tr>\n
</thead><tbody>\n
<tal:block metal:use-macro="container/Zuite_vifib_instanciation_macro_library/macros/init_environment" />\n
<tr>\n
<td>phantomRender</td>\n
<td>webrequest1.png</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>assertElementPresent</td>\n
<td>link=Order a KVM now</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>clickAndWait</td>\n
<td>link=Order a KVM now</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>phantomRender</td>\n
<td>webrequest2.png</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>assertElementPresent</td>\n
<td>//div[text()="Your instance is under creation. Please wait few minutes for partitions to appear."]</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>storeLocation</td>\n
<td>hosting_subscription_url</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>echo</td>\n
<td>${hosting_subscription_url}</td>\n
<td></td>\n
</tr>\n
<!--\n
Unfortunately there is currently now way to do good client-server waiting for reindexation\n
of Software Instance, so just wait 60s.\n
\n
It shall be maximum of reindexation.\n
\n
-->\n
<tr>\n
<td>pause</td>\n
<td>60000</td>\n
<td></td>\n
</tr>\n
\n
<tr>\n
<td>open</td>\n
<td>${hosting_subscription_url}</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>assertElementPresent</td>\n
<td>link=Vifib KVM*</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>clickAndWait</td>\n
<td>link=Vifib KVM*</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>storeLocation</td>\n
<td>software_instance_url</td>\n
<td></td>\n
</tr>\n
<!-- Allows to fetch clean instance status -->\n
<tr>\n
<td>storeEval</td>\n
<td>window.location.pathname</td>\n
<td>software_instance_path</td>\n
</tr>\n
<tr>\n
<td>echo</td>\n
<td>${software_instance_path}</td>\n
<td></td>\n
</tr>\n
\n
<!-- Hackish, but there is no other way to fetch software instance status -->\n
<!-- XXX: It is hammering server, needs to make it a bit nicer -->\n
<!--tr>\n
<td>waitForCondition</td>\n
<td>new\n
Ajax.Request(\'${software_instance_path}/SoftwareInstance_getStatus\',\n
{asynchronous: false}).transport.responseText === "Started"; var i;\n
for (i = 0; i < 10000000; i++) { };</td>\n
<td>600000</td>\n
</tr-->\n
<tr>\n
<td>pause</td>\n
<td>5400000</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>open</td>\n
<td>${software_instance_url}</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>assertElementPresent</td>\n
<td>css=span:contains("Started")</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>assertElementPresent</td>\n
<td>css=td:contains("url")</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>assertElementPresent</td>\n
<td>css=td:contains("password")</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>storeText</td>\n
<td>css=td:contains(\'url\') + td</td>\n
<td>ip</td>\n
</tr>\n
<tr>\n
<td>storeText</td>\n
<td>css=td:contains(\'password\') + td</td>\n
<td>password</td>\n
</tr>\n
<!--tr>\n
<td>openAndWait</td>\n
<td>${ip}</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>pause</td>\n
<td>2000</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>assertElementPresent</td>\n
<td>id=password_input</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>type</td>\n
<td>id=password_input</td>\n
<td>${password}</td>\n
</tr>\n
<tr>\n
<td>keyPress</td>\n
<td>id=password_input</td>\n
<td>13</td>\n
</tr>\n
<tr>\n
<td>pause</td>\n
<td>1000</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>submit</td>\n
<td>//input[@id=&quot;password_input&quot;]/..</td>\n
<td>\\13</td>\n
</tr>\n
<tr>\n
<td>pause</td>\n
<td>10000</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>assertTextPresent</td>\n
<td>Connected (encrypted) to</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>phantomRender</td>\n
<td>webrequest9.png</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>openAndWait</td>\n
<td>${software_instance_url}</td>\n
<td></td>\n
</tr-->\n
<!--span metal:use-macro="container/Zuite_vifib_instanciation_macro_library/macros/destroy_instance" /-->\n
</tbody>\n
</table>\n
</body>\n
</html>
]]></unicode> </value>
</item>
<item> <item>
<key> <string>content_type</string> </key> <key> <string>content_type</string> </key>
<value> <string>text/html</string> </value> <value> <string>text/html</string> </value>
......
<!-- Tested with chromium 12 and --ignore-certificate-errors --disable-translate --disable-web-security options -->
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test KVM</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">testkvm</td></tr>
</thead><tbody>
<tal:block metal:use-macro="container/Zuite_vifib_instanciation_macro_library/macros/init_environment" />
<tr>
<td>phantomRender</td>
<td>webrequest1.png</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>link=Order a KVM now</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Order a KVM now</td>
<td></td>
</tr>
<tr>
<td>phantomRender</td>
<td>webrequest2.png</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[text()="Your instance is under creation. Please wait few minutes for partitions to appear."]</td>
<td></td>
</tr>
<tr>
<td>storeLocation</td>
<td>hosting_subscription_url</td>
<td></td>
</tr>
<tr>
<td>echo</td>
<td>${hosting_subscription_url}</td>
<td></td>
</tr>
<!--
Unfortunately there is currently now way to do good client-server waiting for reindexation
of Software Instance, so just wait 60s.
It shall be maximum of reindexation.
-->
<tr>
<td>pause</td>
<td>60000</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>${hosting_subscription_url}</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>link=Vifib KVM*</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>link=Vifib KVM*</td>
<td></td>
</tr>
<tr>
<td>storeLocation</td>
<td>software_instance_url</td>
<td></td>
</tr>
<!-- Allows to fetch clean instance status -->
<tr>
<td>storeEval</td>
<td>window.location.pathname</td>
<td>software_instance_path</td>
</tr>
<tr>
<td>echo</td>
<td>${software_instance_path}</td>
<td></td>
</tr>
<!-- Hackish, but there is no other way to fetch software instance status -->
<!-- XXX: It is hammering server, needs to make it a bit nicer -->
<!--tr>
<td>waitForCondition</td>
<td>new
Ajax.Request('${software_instance_path}/SoftwareInstance_getStatus',
{asynchronous: false}).transport.responseText === "Started"; var i;
for (i = 0; i < 10000000; i++) { };</td>
<td>600000</td>
</tr-->
<tr>
<td>pause</td>
<td>5400000</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>${software_instance_url}</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>css=span:contains("Started")</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>css=td:contains("url")</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>css=td:contains("password")</td>
<td></td>
</tr>
<tr>
<td>storeText</td>
<td>css=td:contains('url') + td</td>
<td>ip</td>
</tr>
<tr>
<td>storeText</td>
<td>css=td:contains('password') + td</td>
<td>password</td>
</tr>
<!--tr>
<td>openAndWait</td>
<td>${ip}</td>
<td></td>
</tr>
<tr>
<td>pause</td>
<td>2000</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>id=password_input</td>
<td></td>
</tr>
<tr>
<td>type</td>
<td>id=password_input</td>
<td>${password}</td>
</tr>
<tr>
<td>keyPress</td>
<td>id=password_input</td>
<td>13</td>
</tr>
<tr>
<td>pause</td>
<td>1000</td>
<td></td>
</tr>
<tr>
<td>submit</td>
<td>//input[@id=&quot;password_input&quot;]/..</td>
<td>\13</td>
</tr>
<tr>
<td>pause</td>
<td>10000</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Connected (encrypted) to</td>
<td></td>
</tr>
<tr>
<td>phantomRender</td>
<td>webrequest9.png</td>
<td></td>
</tr>
<tr>
<td>openAndWait</td>
<td>${software_instance_url}</td>
<td></td>
</tr-->
<!--span metal:use-macro="container/Zuite_vifib_instanciation_macro_library/macros/destroy_instance" /-->
</tbody>
</table>
</body>
</html>
\ No newline at end of file
from Products.CMFActivity.ActiveResult import ActiveResult
# XXX rafael: Hardcoded value is a convention on Vifib.
vifib = context.organisation_module['vifib_internet']
year = DateTime().year()
start_date = '%s/01/01' % year
stop_date = '%s/12/31' % (year + 1)
accounting_period = context.portal_catalog.getResultValue(
portal_type='Accounting Period',
parent_uid=vifib.getUid(),
simulation_state='started',
**{'delivery.start_date': start_date,
'delivery.stop_date': stop_date
}
)
if accounting_period is None and fixit:
accounting_period = vifib.newContent(portal_type='Accounting Period',
start_date=start_date, stop_date=stop_date)
accounting_period.start()
if accounting_period is None:
summary = "Unable to find Accounting Plan for the current year."
if fixit:
summary += ", fixed."
severity = 0
else:
severity = 1
detail = "Period %s to %s" % (start_date, stop_date)
else:
severity = 0
summary = "Nothing to do."
detail = ""
active_result = ActiveResult()
active_result.edit(
summary=summary,
severity=severity,
detail=detail)
context.newActiveProcess().postResult(active_result)
...@@ -48,53 +48,6 @@ ...@@ -48,53 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>from Products.CMFActivity.ActiveResult import ActiveResult\n
\n
# XXX rafael: Hardcoded value is a convention on Vifib.\n
vifib = context.organisation_module[\'vifib_internet\']\n
\n
year = DateTime().year()\n
start_date = \'%s/01/01\' % year\n
stop_date = \'%s/12/31\' % (year + 1)\n
\n
accounting_period = context.portal_catalog.getResultValue(\n
portal_type=\'Accounting Period\',\n
parent_uid=vifib.getUid(),\n
simulation_state=\'started\',\n
**{\'delivery.start_date\': start_date,\n
\'delivery.stop_date\': stop_date\n
}\n
)\n
\n
if accounting_period is None and fixit:\n
accounting_period = vifib.newContent(portal_type=\'Accounting Period\',\n
start_date=start_date, stop_date=stop_date)\n
accounting_period.start()\n
\n
if accounting_period is None:\n
summary = "Unable to find Accounting Plan for the current year."\n
if fixit:\n
summary += ", fixed."\n
severity = 0\n
else:\n
severity = 1\n
detail = "Period %s to %s" % (start_date, stop_date)\n
else:\n
severity = 0\n
summary = "Nothing to do."\n
detail = ""\n
\n
active_result = ActiveResult()\n
active_result.edit(\n
summary=summary, \n
severity=severity,\n
detail=detail)\n
\n
context.newActiveProcess().postResult(active_result)\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>tag, fixit=False, **kw</string> </value> <value> <string>tag, fixit=False, **kw</string> </value>
......
...@@ -48,11 +48,6 @@ ...@@ -48,11 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>context.activeSense(fixit=1)\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
......
from Products.ZSQLCatalog.SQLCatalog import NegatedQuery, Query
portal = context.getPortalObject()
person = portal.restrictedTraverse('person_module/20120411-A56ED', None)
if person is None:
return
person_reference = person.getReference()
setup_service = portal.restrictedTraverse(portal.portal_preferences.getPreferredInstanceSetupResource())
# XXX Owner column should not be used to fetch the list!
# Data model of hosting subscription should be fixed to allow direct query
portal.portal_catalog.searchAndActivate(
portal_type="Hosting Subscription",
owner=person_reference,
validation_state="validated",
method_id='HostingSubcription_requestDestructionSeleniumTester',
method_kw={'tag': tag},
activate_kw={'tag': tag},
)
context.activate(after_tag=tag).getId()
...@@ -48,32 +48,6 @@ ...@@ -48,32 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>from Products.ZSQLCatalog.SQLCatalog import NegatedQuery, Query\n
\n
portal = context.getPortalObject()\n
person = portal.restrictedTraverse(\'person_module/20120411-A56ED\', None)\n
if person is None:\n
return\n
person_reference = person.getReference()\n
\n
setup_service = portal.restrictedTraverse(portal.portal_preferences.getPreferredInstanceSetupResource())\n
\n
# XXX Owner column should not be used to fetch the list!\n
# Data model of hosting subscription should be fixed to allow direct query\n
portal.portal_catalog.searchAndActivate(\n
portal_type="Hosting Subscription",\n
owner=person_reference,\n
validation_state="validated",\n
method_id=\'HostingSubcription_requestDestructionSeleniumTester\',\n
method_kw={\'tag\': tag},\n
activate_kw={\'tag\': tag},\n
)\n
\n
context.activate(after_tag=tag).getId()\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>tag, fixit, params</string> </value> <value> <string>tag, fixit, params</string> </value>
......
portal_catalog = context.getPortalObject().portal_catalog
from DateTime import DateTime
method_kw = {}
method_kw.update(
maximum_balance=context.portal_preferences.getPreferredMaximumBalance(),
maximum_due_date=(DateTime() - context.portal_preferences.getPreferredMaximumDueDay()).Date(),
simulation_state=context.getPortalCurrentInventoryStateList() + context.getPortalTransitInventoryStateList(),
ongoing_simulation_state=context.getPortalFutureInventoryStateList() + context.getPortalReservedInventoryStateList(),
section_uid=context.restrictedTraverse('organisation_module/vifib_internet').getUid(),
operation='lock'
)
portal_catalog.searchAndActivate(
method_id='Person_manageLockByBalance',
payment_state='!= locked',
portal_type='Person',
activate_kw={'tag': tag},
method_kw=method_kw
)
...@@ -48,28 +48,6 @@ ...@@ -48,28 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>portal_catalog = context.getPortalObject().portal_catalog\n
from DateTime import DateTime\n
method_kw = {}\n
method_kw.update(\n
maximum_balance=context.portal_preferences.getPreferredMaximumBalance(),\n
maximum_due_date=(DateTime() - context.portal_preferences.getPreferredMaximumDueDay()).Date(),\n
simulation_state=context.getPortalCurrentInventoryStateList() + context.getPortalTransitInventoryStateList(),\n
ongoing_simulation_state=context.getPortalFutureInventoryStateList() + context.getPortalReservedInventoryStateList(),\n
section_uid=context.restrictedTraverse(\'organisation_module/vifib_internet\').getUid(),\n
operation=\'lock\'\n
)\n
portal_catalog.searchAndActivate(\n
method_id=\'Person_manageLockByBalance\',\n
payment_state=\'!= locked\',\n
portal_type=\'Person\',\n
activate_kw={\'tag\': tag},\n
method_kw=method_kw\n
)\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>tag, fixit, params</string> </value> <value> <string>tag, fixit, params</string> </value>
......
portal_catalog = context.getPortalObject().portal_catalog
portal_catalog.searchAndActivate(
method_id='SoftwareInstance_lockForLockedPerson',
portal_type=('Software Instance', 'Slave Instance'),
payment_state='!= locked',
activate_kw={'tag': tag}
)
...@@ -48,18 +48,6 @@ ...@@ -48,18 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>portal_catalog = context.getPortalObject().portal_catalog\n
\n
portal_catalog.searchAndActivate(\n
method_id=\'SoftwareInstance_lockForLockedPerson\',\n
portal_type=(\'Software Instance\', \'Slave Instance\'),\n
payment_state=\'!= locked\',\n
activate_kw={\'tag\': tag}\n
)\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>tag, fixit, params</string> </value> <value> <string>tag, fixit, params</string> </value>
......
context.z_set_priority_one_message_table()
context.z_set_priority_one_message_queue_table()
...@@ -48,12 +48,6 @@ ...@@ -48,12 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>context.z_set_priority_one_message_table()\n
context.z_set_priority_one_message_queue_table()\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
......
portal_catalog = context.getPortalObject().portal_catalog
from DateTime import DateTime
method_kw = {}
method_kw.update(
maximum_balance=context.portal_preferences.getPreferredMaximumBalance(),
maximum_due_date=(DateTime() - context.portal_preferences.getPreferredMaximumDueDay()).Date(),
simulation_state=context.getPortalCurrentInventoryStateList() + context.getPortalTransitInventoryStateList(),
ongoing_simulation_state=context.getPortalFutureInventoryStateList() + context.getPortalReservedInventoryStateList(),
section_uid=context.restrictedTraverse('organisation_module/vifib_internet').getUid(),
operation='unlock'
)
portal_catalog.searchAndActivate(
method_id='Person_manageLockByBalance',
payment_state='locked',
portal_type='Person',
activate_kw={'tag': tag},
method_kw=method_kw
)
...@@ -48,28 +48,6 @@ ...@@ -48,28 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>portal_catalog = context.getPortalObject().portal_catalog\n
from DateTime import DateTime\n
method_kw = {}\n
method_kw.update(\n
maximum_balance=context.portal_preferences.getPreferredMaximumBalance(),\n
maximum_due_date=(DateTime() - context.portal_preferences.getPreferredMaximumDueDay()).Date(),\n
simulation_state=context.getPortalCurrentInventoryStateList() + context.getPortalTransitInventoryStateList(),\n
ongoing_simulation_state=context.getPortalFutureInventoryStateList() + context.getPortalReservedInventoryStateList(),\n
section_uid=context.restrictedTraverse(\'organisation_module/vifib_internet\').getUid(),\n
operation=\'unlock\'\n
)\n
portal_catalog.searchAndActivate(\n
method_id=\'Person_manageLockByBalance\',\n
payment_state=\'locked\',\n
portal_type=\'Person\',\n
activate_kw={\'tag\': tag},\n
method_kw=method_kw\n
)\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>tag, fixit, params</string> </value> <value> <string>tag, fixit, params</string> </value>
......
portal_catalog = context.getPortalObject().portal_catalog
portal_catalog.searchAndActivate(
method_id='SoftwareInstance_unlockForUnlockedPerson',
portal_type=('Software Instance', 'Slave Instance'),
payment_state='locked',
activate_kw={'tag': tag}
)
...@@ -48,18 +48,6 @@ ...@@ -48,18 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>portal_catalog = context.getPortalObject().portal_catalog\n
\n
portal_catalog.searchAndActivate(\n
method_id=\'SoftwareInstance_unlockForUnlockedPerson\',\n
portal_type=(\'Software Instance\', \'Slave Instance\'),\n
payment_state=\'locked\',\n
activate_kw={\'tag\': tag}\n
)\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>tag, fixit, params</string> </value> <value> <string>tag, fixit, params</string> </value>
......
from Products.ERP5Type.Constraint import PropertyTypeValidity
from Products.CMFActivity.ActiveResult import ActiveResult
if context.getId().startswith('template_'):
return
constraint_message_list = []
if context.providesIConstraint():
# it is not possible to checkConsistency of Constraint itself, as method
# of this name implement consistency checking on object
return constraint_message_list
traverse = context.getPortalObject().restrictedTraverse
property_type_validity = PropertyTypeValidity(id='type_check', description='Type Validity Check')
if fixit:
constraint_message_list.extend(context.fixConsistency())
constraint_message_list.extend(property_type_validity.fixConsistency(context))
else:
constraint_message_list.extend(context.checkConsistency(fixit=fixit))
constraint_message_list.extend(property_type_validity.checkConsistency(context, fixit=fixit))
if constraint_message_list:
traverse(active_process).postResult(ActiveResult(severity=100,
constraint_message_list=constraint_message_list))
...@@ -48,36 +48,6 @@ ...@@ -48,36 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>from Products.ERP5Type.Constraint import PropertyTypeValidity\n
from Products.CMFActivity.ActiveResult import ActiveResult\n
\n
if context.getId().startswith(\'template_\'):\n
return\n
\n
constraint_message_list = []\n
\n
if context.providesIConstraint():\n
# it is not possible to checkConsistency of Constraint itself, as method\n
# of this name implement consistency checking on object\n
return constraint_message_list\n
\n
traverse = context.getPortalObject().restrictedTraverse\n
property_type_validity = PropertyTypeValidity(id=\'type_check\', description=\'Type Validity Check\')\n
\n
if fixit:\n
constraint_message_list.extend(context.fixConsistency())\n
constraint_message_list.extend(property_type_validity.fixConsistency(context))\n
else:\n
constraint_message_list.extend(context.checkConsistency(fixit=fixit))\n
constraint_message_list.extend(property_type_validity.checkConsistency(context, fixit=fixit))\n
\n
if constraint_message_list:\n
traverse(active_process).postResult(ActiveResult(severity=100,\n
constraint_message_list=constraint_message_list))\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>fixit, active_process</string> </value> <value> <string>fixit, active_process</string> </value>
......
# try to find, if needed create and publish
portal = context.getPortalObject()
software_release_document = portal.portal_catalog.getResultValue(portal_type='Software Release',
url_string=software_release_url)
if software_release_document is None:
digest = context.Base_getSha512Hexdiest(software_release_url)
tag = '%s_inProgress' % digest
if portal.portal_activities.countMessageWithTag(tag) == 0:
# can create new one
software_release_document = portal.software_release_module.newContent(
portal_type='Software Release',
reference=digest,
version=digest,
url_string=software_release_url,
language='en',
activate_kw={'tag': tag}
)
software_release_document.publish(comment='Automatically created.')
return software_release_document
...@@ -48,29 +48,6 @@ ...@@ -48,29 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string># try to find, if needed create and publish\n
portal = context.getPortalObject()\n
software_release_document = portal.portal_catalog.getResultValue(portal_type=\'Software Release\',\n
url_string=software_release_url)\n
if software_release_document is None:\n
digest = context.Base_getSha512Hexdiest(software_release_url)\n
tag = \'%s_inProgress\' % digest\n
if portal.portal_activities.countMessageWithTag(tag) == 0:\n
# can create new one\n
software_release_document = portal.software_release_module.newContent(\n
portal_type=\'Software Release\',\n
reference=digest,\n
version=digest,\n
url_string=software_release_url,\n
language=\'en\',\n
activate_kw={\'tag\': tag}\n
)\n
software_release_document.publish(comment=\'Automatically created.\')\n
return software_release_document\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>software_release_url</string> </value> <value> <string>software_release_url</string> </value>
......
# XXX: Convert to preference?
portal = context.getPortalObject()
usage_report_service_reference = 'usage_report'
catalog_result = portal.portal_catalog(
portal_type=portal.getPortalServiceTypeList(),
reference=usage_report_service_reference
)
if len(catalog_result) == 1:
return catalog_result[0].getObject()
return None
...@@ -48,20 +48,6 @@ ...@@ -48,20 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string># XXX: Convert to preference?\n
portal = context.getPortalObject()\n
usage_report_service_reference = \'usage_report\'\n
catalog_result = portal.portal_catalog(\n
portal_type=portal.getPortalServiceTypeList(),\n
reference=usage_report_service_reference\n
)\n
if len(catalog_result) == 1:\n
return catalog_result[0].getObject()\n
return None\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
......
if context.getPortalType() != 'Computer':
raise TypeError('%s is not Computer' % context.getPath())
isTransitionPossible = context.getPortalObject().portal_workflow.isTransitionPossible
def updatePartitionList(computer, partition_list):
existing_partition_dict = {}
for c in context.contentValues():
existing_partition_dict[c.getReference()] = c
for partition_dict in partition_list:
partition = existing_partition_dict.get(partition_dict['title'])
if partition is None:
partition = computer.newContent(portal_type='Computer Partition', reference=partition_dict['title'])
if isTransitionPossible(partition, 'validate'):
partition.validate()
if isTransitionPossible(partition, 'mark_free'):
partition.markFree()
if partition.getDefaultNetworkAddressIpAddress() != partition_dict['public_ip']:
partition.setDefaultNetworkAddressIpAddress(partition_dict['public_ip'])
if partition.getDefaultNetworkAddressNetworkInterface() != partition_dict['tap_interface']:
partition.setDefaultNetworkAddressNetworkInterface(partition_dict['tap_interface'])
to_delete_list = []
private_set = False
for address in partition.contentValues(portal_type='Internet Protocol Address'):
if address.getIpAddress() == partition_dict['public_ip']:
continue
if not private_set and address.getIpAddress() == partition_dict['private_ip']:
if address.getNetworkInterface() != partition_dict['tap_interface']:
address.setNetworkInterface(partition_dict['tap_interface'])
private_set = True
continue
to_delete_list.append(address)
if not private_set:
if len(to_delete_list):
address = to_delete_list.pop()
else:
address = partition.newContent(portal_type='Internet Protocol Address')
address.setIpAddress(partition_dict['private_ip'])
address.setNetworkInterface(partition_dict['tap_interface'])
partition.deleteContent([q.getId() for q in to_delete_list])
def updateSoftwareList(computer, software_list):
for software_dict in software_list:
status = software_dict['status']
try:
if status == 'installed':
computer.stopSoftwareReleaseInstallation(software_release_url=software_dict['software_release'], comment=software_dict['log'])
elif status == 'uninstalled':
computer.cleanupSoftwareReleaseInstallation(software_release_url=software_dict['software_release'], comment=software_dict['log'])
elif status == 'error':
computer.reportSoftwareReleaseInstallationError(software_release_url=software_dict['software_release'], comment=software_dict['log'])
except ValueError:
# BBB: Underlying code is state based, does not support multiple information
pass
if 'partition' in computer_json:
updatePartitionList(context, computer_json['partition'])
if 'software' in computer_json:
updateSoftwareList(context, computer_json['software'])
...@@ -48,69 +48,6 @@ ...@@ -48,69 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>if context.getPortalType() != \'Computer\':\n
raise TypeError(\'%s is not Computer\' % context.getPath())\n
\n
isTransitionPossible = context.getPortalObject().portal_workflow.isTransitionPossible\n
def updatePartitionList(computer, partition_list):\n
existing_partition_dict = {}\n
for c in context.contentValues():\n
existing_partition_dict[c.getReference()] = c\n
for partition_dict in partition_list:\n
partition = existing_partition_dict.get(partition_dict[\'title\'])\n
if partition is None:\n
partition = computer.newContent(portal_type=\'Computer Partition\', reference=partition_dict[\'title\'])\n
if isTransitionPossible(partition, \'validate\'):\n
partition.validate()\n
if isTransitionPossible(partition, \'mark_free\'):\n
partition.markFree()\n
if partition.getDefaultNetworkAddressIpAddress() != partition_dict[\'public_ip\']:\n
partition.setDefaultNetworkAddressIpAddress(partition_dict[\'public_ip\'])\n
if partition.getDefaultNetworkAddressNetworkInterface() != partition_dict[\'tap_interface\']:\n
partition.setDefaultNetworkAddressNetworkInterface(partition_dict[\'tap_interface\'])\n
to_delete_list = []\n
private_set = False\n
for address in partition.contentValues(portal_type=\'Internet Protocol Address\'):\n
if address.getIpAddress() == partition_dict[\'public_ip\']:\n
continue\n
if not private_set and address.getIpAddress() == partition_dict[\'private_ip\']:\n
if address.getNetworkInterface() != partition_dict[\'tap_interface\']:\n
address.setNetworkInterface(partition_dict[\'tap_interface\'])\n
private_set = True\n
continue\n
to_delete_list.append(address)\n
if not private_set:\n
if len(to_delete_list):\n
address = to_delete_list.pop()\n
else:\n
address = partition.newContent(portal_type=\'Internet Protocol Address\')\n
address.setIpAddress(partition_dict[\'private_ip\'])\n
address.setNetworkInterface(partition_dict[\'tap_interface\'])\n
partition.deleteContent([q.getId() for q in to_delete_list])\n
\n
def updateSoftwareList(computer, software_list):\n
for software_dict in software_list:\n
status = software_dict[\'status\']\n
try:\n
if status == \'installed\':\n
computer.stopSoftwareReleaseInstallation(software_release_url=software_dict[\'software_release\'], comment=software_dict[\'log\'])\n
elif status == \'uninstalled\':\n
computer.cleanupSoftwareReleaseInstallation(software_release_url=software_dict[\'software_release\'], comment=software_dict[\'log\'])\n
elif status == \'error\':\n
computer.reportSoftwareReleaseInstallationError(software_release_url=software_dict[\'software_release\'], comment=software_dict[\'log\'])\n
except ValueError:\n
# BBB: Underlying code is state based, does not support multiple information\n
pass\n
\n
if \'partition\' in computer_json:\n
updatePartitionList(context, computer_json[\'partition\'])\n
\n
if \'software\' in computer_json:\n
updateSoftwareList(context, computer_json[\'software\'])\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>computer_json</string> </value> <value> <string>computer_json</string> </value>
......
from DateTime import DateTime
portal = context.getPortalObject()
hosting_subscription = context
now = DateTime()
if hosting_subscription.getDestinationSectionValue().getReference() == 'seleniumtester' and \
hosting_subscription.getModificationDate() < (now - 1):
person = hosting_subscription.getDestinationSectionValue(portal_type="Person")
person.requestSoftwareInstance(
software_release=hosting_subscription.getUrlString(),
instance_xml=hosting_subscription.getTextContent(),
software_type=hosting_subscription.getSourceReference(),
sla_xml=hosting_subscription.getSlaXml(),
shared=hosting_subscription.getRootSlave(),
state="destroyed",
software_title=hosting_subscription.getTitle(),
comment='Requested by clenaup alarm',
activate_kw={'tag': tag}
)
...@@ -48,35 +48,6 @@ ...@@ -48,35 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
from DateTime import DateTime\n
portal = context.getPortalObject()\n
hosting_subscription = context\n
\n
now = DateTime()\n
\n
if hosting_subscription.getDestinationSectionValue().getReference() == \'seleniumtester\' and \\\n
hosting_subscription.getModificationDate() < (now - 1):\n
\n
person = hosting_subscription.getDestinationSectionValue(portal_type="Person")\n
person.requestSoftwareInstance(\n
software_release=hosting_subscription.getUrlString(),\n
instance_xml=hosting_subscription.getTextContent(),\n
software_type=hosting_subscription.getSourceReference(),\n
sla_xml=hosting_subscription.getSlaXml(),\n
shared=hosting_subscription.getRootSlave(),\n
state="destroyed",\n
software_title=hosting_subscription.getTitle(),\n
comment=\'Requested by clenaup alarm\', \n
activate_kw={\'tag\': tag}\n
)\n
]]></string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>tag</string> </value> <value> <string>tag</string> </value>
......
#We extract informations from SPL
packing_list_dict = {'packing_list_title': context.getTitle()}
#We extract informations from SPLL
sale_packing_list_line_list = [line for line in context.objectValues(
portal_type='Sale Packing List Line')
]
xml_head = ""
xml_movements = ""
xml_foot = ""
xml_head = "<?xml version='1.0' encoding='utf-8'?>" \
"<journal>" \
"<transaction type=\"Sale Packing List\">" \
"<title>%(packing_list_title)s</title>" \
"<start_date></start_date>" \
"<stop_date></stop_date>" \
"<reference></reference>" \
"<currency></currency>" \
"<payment_mode></payment_mode>" \
"<category></category>" \
"<arrow type=\"Administration\">" \
"<source></source>" \
"<destination></destination>" \
"</arrow>" \
% packing_list_dict
for sale_packing_list_line in sale_packing_list_line_list:
packing_list_line_dict = {'packing_list_line_title': sale_packing_list_line.getTitle(),
'packing_list_line_resource': sale_packing_list_line.getResourceTitle(),
'packing_list_line_reference': sale_packing_list_line.getAggregateValue().getTitle(),
'packing_list_line_quantity': sale_packing_list_line.getQuantity(),
}
xml_movements += "<movement>" \
"<resource>%(packing_list_line_resource)s</resource>" \
"<title>%(packing_list_line_title)s</title>" \
"<reference>%(packing_list_line_reference)s</reference>" \
"<quantity>%(packing_list_line_quantity)s</quantity>" \
"<price>0.00</price>" \
"<VAT>None</VAT>" \
"<category>None</category>" \
"</movement>" \
% packing_list_line_dict
xml_foot = "</transaction>" \
"</journal>"
xml = xml_head + xml_movements + xml_foot
return xml
...@@ -48,66 +48,6 @@ ...@@ -48,66 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
#We extract informations from SPL\n
packing_list_dict = {\'packing_list_title\': context.getTitle()}\n
\n
#We extract informations from SPLL\n
sale_packing_list_line_list = [line for line in context.objectValues(\n
portal_type=\'Sale Packing List Line\')\n
]\n
\n
xml_head = ""\n
xml_movements = ""\n
xml_foot = ""\n
\n
xml_head = "<?xml version=\'1.0\' encoding=\'utf-8\'?>" \\\n
"<journal>" \\\n
"<transaction type=\\"Sale Packing List\\">" \\\n
"<title>%(packing_list_title)s</title>" \\\n
"<start_date></start_date>" \\\n
"<stop_date></stop_date>" \\\n
"<reference></reference>" \\\n
"<currency></currency>" \\\n
"<payment_mode></payment_mode>" \\\n
"<category></category>" \\\n
"<arrow type=\\"Administration\\">" \\\n
"<source></source>" \\\n
"<destination></destination>" \\\n
"</arrow>" \\\n
% packing_list_dict\n
\n
for sale_packing_list_line in sale_packing_list_line_list:\n
\n
packing_list_line_dict = {\'packing_list_line_title\': sale_packing_list_line.getTitle(),\n
\'packing_list_line_resource\': sale_packing_list_line.getResourceTitle(),\n
\'packing_list_line_reference\': sale_packing_list_line.getAggregateValue().getTitle(),\n
\'packing_list_line_quantity\': sale_packing_list_line.getQuantity(),\n
}\n
\n
xml_movements += "<movement>" \\\n
"<resource>%(packing_list_line_resource)s</resource>" \\\n
"<title>%(packing_list_line_title)s</title>" \\\n
"<reference>%(packing_list_line_reference)s</reference>" \\\n
"<quantity>%(packing_list_line_quantity)s</quantity>" \\\n
"<price>0.00</price>" \\\n
"<VAT>None</VAT>" \\\n
"<category>None</category>" \\\n
"</movement>" \\\n
% packing_list_line_dict\n
\n
xml_foot = "</transaction>" \\\n
"</journal>"\n
\n
xml = xml_head + xml_movements + xml_foot\n
return xml\n
]]></string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
......
locked = context.getSlapState() == 'locked'
customer_uid = context.getUid()
balance = context.portal_simulation.getInventoryAssetPrice(
node_category='account_type/asset/receivable',
simulation_state=simulation_state,
section_uid=section_uid,
mirror_section_uid=customer_uid)
if maximum_balance > balance:
# customer reached his balance, shall be locked
if not locked and operation == 'lock':
context.lock(comment="Balance value is %s" % balance)
return
# check ongoing payments and check that date if is acceptable, if not lock
if context.portal_simulation.getInventoryAssetPrice(
parent_portal_type='Payment Transaction',
node_category='account_type/asset/receivable',
simulation_state=ongoing_simulation_state,
section_uid=section_uid,
mirror_section_uid=customer_uid,
at_date=maximum_due_date,
) > 0:
# there are ongoing old payments, shall be locked
if not locked and operation == 'lock':
context.lock(comment="Payment transaction not paid for more than %s days" % maximum_due_date)
elif balance >= 0.0:
# there are no ongoing payments and customer owns nothing
if locked and operation == 'unlock':
context.unlock()
...@@ -48,44 +48,6 @@ ...@@ -48,44 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
locked = context.getSlapState() == \'locked\'\n
customer_uid = context.getUid()\n
balance = context.portal_simulation.getInventoryAssetPrice(\n
node_category=\'account_type/asset/receivable\',\n
simulation_state=simulation_state,\n
section_uid=section_uid,\n
mirror_section_uid=customer_uid)\n
\n
if maximum_balance > balance:\n
# customer reached his balance, shall be locked\n
if not locked and operation == \'lock\':\n
context.lock(comment="Balance value is %s" % balance)\n
return\n
\n
# check ongoing payments and check that date if is acceptable, if not lock\n
if context.portal_simulation.getInventoryAssetPrice(\n
parent_portal_type=\'Payment Transaction\',\n
node_category=\'account_type/asset/receivable\',\n
simulation_state=ongoing_simulation_state,\n
section_uid=section_uid,\n
mirror_section_uid=customer_uid,\n
at_date=maximum_due_date,\n
) > 0:\n
# there are ongoing old payments, shall be locked\n
if not locked and operation == \'lock\':\n
context.lock(comment="Payment transaction not paid for more than %s days" % maximum_due_date)\n
elif balance >= 0.0:\n
# there are no ongoing payments and customer owns nothing\n
if locked and operation == \'unlock\':\n
context.unlock()\n
]]></string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>maximum_balance, maximum_due_date, simulation_state, section_uid, ongoing_simulation_state, operation</string> </value> <value> <string>maximum_balance, maximum_due_date, simulation_state, section_uid, ongoing_simulation_state, operation</string> </value>
......
software_instance = context
if software_instance.getSlapState() == 'locked':
return
if software_instance.SoftwareInstance_getStatus() == 'destroyed':
return
try:
packing_list_line = software_instance.Item_getInstancePackingListLine()
except ValueError:
return
person = packing_list_line.getDestinationValue()
if person.getSlapState() == 'locked':
software_instance.lock()
...@@ -48,24 +48,6 @@ ...@@ -48,24 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>software_instance = context\n
if software_instance.getSlapState() == \'locked\':\n
return\n
if software_instance.SoftwareInstance_getStatus() == \'destroyed\':\n
return\n
\n
try:\n
packing_list_line = software_instance.Item_getInstancePackingListLine()\n
except ValueError:\n
return\n
person = packing_list_line.getDestinationValue()\n
\n
if person.getSlapState() == \'locked\':\n
software_instance.lock()\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
......
software_instance = context
if software_instance.getSlapState() != 'locked':
return
if software_instance.SoftwareInstance_getStatus() == 'destroyed':
return
try:
packing_list_line = software_instance.Item_getInstancePackingListLine()
except ValueError:
return
person = packing_list_line.getDestinationValue()
if person.getSlapState() != 'locked':
software_instance.unlock()
...@@ -48,24 +48,6 @@ ...@@ -48,24 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>software_instance = context\n
if software_instance.getSlapState() != \'locked\':\n
return\n
if software_instance.SoftwareInstance_getStatus() == \'destroyed\':\n
return\n
\n
try:\n
packing_list_line = software_instance.Item_getInstancePackingListLine()\n
except ValueError:\n
return\n
person = packing_list_line.getDestinationValue()\n
\n
if person.getSlapState() != \'locked\':\n
software_instance.unlock()\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<ZopeData> <ZopeData>
<record id="1" aka="AAAAAAAAAAE="> <record id="1" aka="AAAAAAAAAAE=">
<pickle> <pickle>
<global name="ERP5Form" module="Products.ERP5Form.Form"/> <global name="ERP5 Form" module="erp5.portal_type"/>
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
......
update message_queue set priority = 1 where processing_node in (0, -1) and priority > 1
\ No newline at end of file
...@@ -24,14 +24,6 @@ ...@@ -24,14 +24,6 @@
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>z_set_priority_one_message_queue_table</string> </value> <value> <string>z_set_priority_one_message_queue_table</string> </value>
</item> </item>
<item>
<key> <string>src</string> </key>
<value> <string encoding="cdata"><![CDATA[
update message_queue set priority = 1 where processing_node in (0, -1) and priority > 1
]]></string> </value>
</item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
......
update message set priority = 1 where processing_node in (0, -1) and priority > 1
\ No newline at end of file
...@@ -24,14 +24,6 @@ ...@@ -24,14 +24,6 @@
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>z_set_priority_one_message_table</string> </value> <value> <string>z_set_priority_one_message_table</string> </value>
</item> </item>
<item>
<key> <string>src</string> </key>
<value> <string encoding="cdata"><![CDATA[
update message set priority = 1 where processing_node in (0, -1) and priority > 1
]]></string> </value>
</item>
<item> <item>
<key> <string>title</string> </key> <key> <string>title</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
......
"""
This script generate a usage report test sample for one or two partitions
"""
# First we check the number of partition to invoice
if number in [1, 2]:
# We build movements
movement = """
<movement>
<resource>%s</resource>
<title>%s</title>
<reference>%s</reference>
<quantity>%s</quantity>
<price>0.00</price>
<VAT>None</VAT>
<category>None</category>
</movement>"""
# Then, we create two movements for each partition, one for the CPU consumption, and the other for the memory
movements = ""
for nb in range(number):
if nb == 0:
movements += movement % ('CPU Consumption', 'Title Sale Packing List Line 1', 'slappart0', '42.42')
movements += movement % ('Memory Consumption', 'Title Sale Packing List Line 2', 'slappart0', '42.42')
else:
movements += movement % ('CPU Consumption', 'Title Sale Packing List Line 1', 'slappart1', '46.46')
movements += movement % ('Memory Consumption', 'Title Sale Packing List Line 2', 'slappart1', '46.46')
# Finally, we build the XML usage report
xml = """<?xml version='1.0' encoding='utf-8'?>
<journal>
<transaction type="Sale Packing List">
<title>Resource consumptions</title>
<start_date></start_date>
<stop_date></stop_date>
<reference></reference>
<currency></currency>
<payment_mode></payment_mode>
<category></category>
<arrow type="Administration">
<source></source>
<destination></destination>
</arrow>""" + movements + """
</transaction>
</journal>"""
return xml
else:
return 'This script can generate movements for one or two partitions maximum'
...@@ -48,65 +48,6 @@ ...@@ -48,65 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
""" \n
This script generate a usage report test sample for one or two partitions\n
"""\n
\n
# First we check the number of partition to invoice\n
if number in [1, 2]:\n
\n
# We build movements\n
movement = """\n
<movement>\n
<resource>%s</resource>\n
<title>%s</title>\n
<reference>%s</reference> \n
<quantity>%s</quantity>\n
<price>0.00</price> \n
<VAT>None</VAT>\n
<category>None</category>\n
</movement>"""\n
\n
# Then, we create two movements for each partition, one for the CPU consumption, and the other for the memory\n
movements = ""\n
for nb in range(number):\n
if nb == 0:\n
movements += movement % (\'CPU Consumption\', \'Title Sale Packing List Line 1\', \'slappart0\', \'42.42\')\n
movements += movement % (\'Memory Consumption\', \'Title Sale Packing List Line 2\', \'slappart0\', \'42.42\')\n
else:\n
movements += movement % (\'CPU Consumption\', \'Title Sale Packing List Line 1\', \'slappart1\', \'46.46\')\n
movements += movement % (\'Memory Consumption\', \'Title Sale Packing List Line 2\', \'slappart1\', \'46.46\')\n
\n
# Finally, we build the XML usage report\n
xml = """<?xml version=\'1.0\' encoding=\'utf-8\'?>\n
<journal>\n
<transaction type="Sale Packing List">\n
<title>Resource consumptions</title>\n
<start_date></start_date>\n
<stop_date></stop_date>\n
<reference></reference>\n
<currency></currency>\n
<payment_mode></payment_mode>\n
<category></category>\n
<arrow type="Administration">\n
<source></source>\n
<destination></destination>\n
</arrow>""" + movements + """\n
</transaction>\n
</journal>"""\n
\n
return xml\n
\n
else:\n
return \'This script can generate movements for one or two partitions maximum\'\n
]]></string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>number</string> </value> <value> <string>number</string> </value>
......
"""
Storage for the login and password of the test user
"""
return {'test_user_login' :'test_customer_vifib_web',
'test_user_password': 'testuser'}
...@@ -48,16 +48,6 @@ ...@@ -48,16 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>"""\n
Storage for the login and password of the test user\n
"""\n
\n
return {\'test_user_login\' :\'test_customer_vifib_web\',\n
\'test_user_password\': \'testuser\'}\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
......
...@@ -32,60 +32,6 @@ ...@@ -32,60 +32,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_text</string> </key>
<value> <unicode encoding="cdata"><![CDATA[
<tal:block metal:define-macro="init_environment">\n
<!-- Initialize test environment -->\n
<tr>\n
<td>setTimeout</td>\n
<td>120000</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>store</td>\n
<td tal:content="python:\n
context.REQUEST.get(\'URL\')[0:here.REQUEST.get(\'URL\').find(\'/portal_tests/\')]">erp5</td>\n
<td>base_url</td>\n
</tr>\n
<tr>\n
<td>openAndWait</td>\n
<td>${base_url}/web_site_module/hosting</td>\n
<td></td>\n
</tr>\n
</tal:block>\n
\n
<tal:block metal:define-macro="destroy_instance">\n
<!-- Order the destruction of the instance and check for it -->\n
<tr>\n
<td>assertElementPresent</td>\n
<td>name=SoftwareInstance_requestDestroy:method</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>clickAndWait</td>\n
<td>name=SoftwareInstance_requestDestroy:method</td>\n
<td></td>\n
</tr>\n
<tr>\n
<td>waitForCondition</td>\n
<!-- XXX-Cedric : should be "Destroyed". -->\n
<td>new\n
Ajax.Request(\'${software_instance_path}/SoftwareInstance_getStatus\',\n
{asynchronous: false}).transport.responseText === "Destruction in progress"; var\n
i; for (i = 0; i < 10000000; i++){};</td>\n
<td>600000</td>\n
</tr>\n
<tr>\n
<td>openAndWait</td>\n
<td>${address}</td>\n
<td></td>\n
</tr>\n
</tal:block>
]]></unicode> </value>
</item>
<item> <item>
<key> <string>content_type</string> </key> <key> <string>content_type</string> </key>
<value> <string>text/html</string> </value> <value> <string>text/html</string> </value>
......
<tal:block metal:define-macro="init_environment">
<!-- Initialize test environment -->
<tr>
<td>setTimeout</td>
<td>120000</td>
<td></td>
</tr>
<tr>
<td>store</td>
<td tal:content="python:
context.REQUEST.get('URL')[0:here.REQUEST.get('URL').find('/portal_tests/')]">erp5</td>
<td>base_url</td>
</tr>
<tr>
<td>openAndWait</td>
<td>${base_url}/web_site_module/hosting</td>
<td></td>
</tr>
</tal:block>
<tal:block metal:define-macro="destroy_instance">
<!-- Order the destruction of the instance and check for it -->
<tr>
<td>assertElementPresent</td>
<td>name=SoftwareInstance_requestDestroy:method</td>
<td></td>
</tr>
<tr>
<td>clickAndWait</td>
<td>name=SoftwareInstance_requestDestroy:method</td>
<td></td>
</tr>
<tr>
<td>waitForCondition</td>
<!-- XXX-Cedric : should be "Destroyed". -->
<td>new
Ajax.Request('${software_instance_path}/SoftwareInstance_getStatus',
{asynchronous: false}).transport.responseText === "Destruction in progress"; var
i; for (i = 0; i < 10000000; i++){};</td>
<td>600000</td>
</tr>
<tr>
<td>openAndWait</td>
<td>${address}</td>
<td></td>
</tr>
</tal:block>
\ No newline at end of file
Business Process
Business Process Module
\ No newline at end of file
<registered_skin_selection> <registered_skin_selection>
<skin_folder_selection> <skin_folder_selection>
<skin_folder>slapos_hal_json_style</skin_folder> <skin_folder>slapos_hal_json_style</skin_folder>
<skin_selection>HalRestricted,Hal</skin_selection> <skin_selection>Hal,HalRestricted</skin_selection>
</skin_folder_selection> </skin_folder_selection>
</registered_skin_selection> </registered_skin_selection>
\ No newline at end of file
if REQUEST.other['method'] != "POST":
response.setStatus(405)
return ""
computer = context
computer.requestSoftwareRelease(software_release_url=software_release, state='available')
return context.REQUEST.get('software_installation_url').Base_redirect()
...@@ -48,18 +48,6 @@ ...@@ -48,18 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>if REQUEST.other[\'method\'] != "POST":\n
response.setStatus(405)\n
return ""\n
\n
computer = context\n
computer.requestSoftwareRelease(software_release_url=software_release, state=\'available\')\n
\n
return context.REQUEST.get(\'software_installation_url\').Base_redirect()\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>software_release, REQUEST=None</string> </value> <value> <string>software_release, REQUEST=None</string> </value>
......
if REQUEST.other['method'] != "POST":
response.setStatus(405)
return ""
import json
computer = context
request = context.REQUEST
response = REQUEST.RESPONSE
context.Base_prepareCorsResponse(RESPONSE=response)
computer.generateCertificate()
return json.dumps({
'certificate': request.get('computer_certificate'),
'key': request.get('computer_key')
}, indent=2)
...@@ -48,28 +48,6 @@ ...@@ -48,28 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>if REQUEST.other[\'method\'] != "POST":\n
response.setStatus(405)\n
return ""\n
\n
import json\n
\n
computer = context\n
request = context.REQUEST\n
response = REQUEST.RESPONSE\n
\n
context.Base_prepareCorsResponse(RESPONSE=response)\n
\n
computer.generateCertificate()\n
\n
return json.dumps({\n
\'certificate\': request.get(\'computer_certificate\'),\n
\'key\': request.get(\'computer_key\')\n
}, indent=2)\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value> <value> <string>REQUEST=None</string> </value>
......
if REQUEST.other['method'] != "POST":
response.setStatus(405)
return ""
computer = context
response = REQUEST.RESPONSE
context.Base_prepareCorsResponse(RESPONSE=response)
computer.revokeCertificate()
return ""
...@@ -48,21 +48,6 @@ ...@@ -48,21 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>if REQUEST.other[\'method\'] != "POST":\n
response.setStatus(405)\n
return ""\n
\n
computer = context\n
response = REQUEST.RESPONSE\n
context.Base_prepareCorsResponse(RESPONSE=response)\n
\n
computer.revokeCertificate()\n
\n
return ""\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value> <value> <string>REQUEST=None</string> </value>
......
if REQUEST.other['method'] != "POST":
response.setStatus(405)
return ""
portal = context.getPortalObject()
computer = context
response = REQUEST.RESPONSE
context.Base_prepareCorsResponse(RESPONSE=response)
if allocation_scope == 'open/public':
# Public computer capacity is handle by an alarm
capacity_scope = 'close'
elif allocation_scope.startswith('open'):
# Capacity is not handled for 'private' computers
capacity_scope = 'open'
else:
capacity_scope = 'close'
edit_kw = {
'allocation_scope': allocation_scope,
'capacity_scope': capacity_scope,
}
self_person = computer.getSourceAdministrationValue(portal_type="Person")
self_email = self_person.getDefaultEmailCoordinateText()
if allocation_scope == 'open/public':
# reset friends and update in place
edit_kw['subject_list'] = ['']
edit_kw['destination_section'] = None
elif allocation_scope == 'open/personal':
# reset friends to self and update in place
edit_kw['subject_list'] = [self_email]
edit_kw['destination_section_value'] = self_person
else:
if self_email not in subject_list:
# add self as friend
subject_list.append(self_email)
edit_kw['subject_list'] = subject_list
computer.edit(**edit_kw)
return ""
...@@ -48,53 +48,6 @@ ...@@ -48,53 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>if REQUEST.other[\'method\'] != "POST":\n
response.setStatus(405)\n
return ""\n
\n
portal = context.getPortalObject()\n
computer = context\n
response = REQUEST.RESPONSE\n
\n
context.Base_prepareCorsResponse(RESPONSE=response)\n
\n
if allocation_scope == \'open/public\':\n
# Public computer capacity is handle by an alarm\n
capacity_scope = \'close\'\n
elif allocation_scope.startswith(\'open\'):\n
# Capacity is not handled for \'private\' computers\n
capacity_scope = \'open\'\n
else:\n
capacity_scope = \'close\'\n
\n
edit_kw = {\n
\'allocation_scope\': allocation_scope,\n
\'capacity_scope\': capacity_scope,\n
}\n
\n
self_person = computer.getSourceAdministrationValue(portal_type="Person")\n
self_email = self_person.getDefaultEmailCoordinateText()\n
if allocation_scope == \'open/public\':\n
# reset friends and update in place\n
edit_kw[\'subject_list\'] = [\'\']\n
edit_kw[\'destination_section\'] = None\n
elif allocation_scope == \'open/personal\':\n
# reset friends to self and update in place\n
edit_kw[\'subject_list\'] = [self_email]\n
edit_kw[\'destination_section_value\'] = self_person\n
else:\n
if self_email not in subject_list:\n
# add self as friend\n
subject_list.append(self_email)\n
edit_kw[\'subject_list\'] = subject_list\n
\n
computer.edit(**edit_kw)\n
\n
return ""\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>allocation_scope, subject_list, REQUEST=None</string> </value> <value> <string>allocation_scope, subject_list, REQUEST=None</string> </value>
......
from zExceptions import Unauthorized
from AccessControl import getSecurityManager
from ZTUtils import make_query
from Products.ZSQLCatalog.SQLCatalog import Query, NegatedQuery
import json
if REQUEST is None:
REQUEST = context.REQUEST
# raise Unauthorized
if response is None:
response = REQUEST.RESPONSE
url_template_dict = {
"form_action": "%(traversed_document_url)s/%(action_id)s",
"traverse_template": "%(root_url)s/%(script_id)s?mode=traverse" + \
"{&relative_url,view}",
"search_template": "%(root_url)s/%(script_id)s?mode=search" + \
"{&query,select_list*,limit*}",
"new_content_action": "%(root_url)s/%(script_id)s?mode=newContent",
# XXX View is set by default to empty
"document_hal": "%(root_url)s/%(script_id)s?mode=traverse" + \
"&relative_url=%(relative_url)s",
"jio_get_template": "urn:jio:get:%(relative_url)s",
"jio_search_template": "urn:jio:allDocs?%(query)s",
}
default_document_uri_template = url_template_dict["jio_get_template"]
def getFormRelativeUrl(form):
return portal.portal_catalog(
portal_type="ERP5 Form",
uid=form.getUid(),
id=form.getId(),
limit=1,
select_dict={'relative_url': None}
)[0].relative_url
def renderField(field, meta_type=None):
if meta_type is None:
meta_type = field.meta_type
if meta_type == "ProxyField":
result = renderField(field, meta_type=field.getRecursiveTemplateField().meta_type)
elif meta_type in ("ListField", "ParallelListField", "MultiListField"):
result = {
"type": meta_type,
"key": field.generate_field_key(),
"default": field.get_value("default"),
"editable": field.get_value("editable"),
"css_class": field.get_value("css_class"),
"hidden": field.get_value("hidden"),
"description": field.get_value("description"),
"title": field.get_value("title"),
"required": field.get_value("required"),
# XXX Message can not be converted to json as is
"items": field.get_value("items"),
}
elif meta_type in ("StringField", "FloatField", "RelationStringField",
"MultiRelationStringField", "EmailField", "TextAreaField",
"LinesField", "ImageField", "FileField", "IntegerField",
"PasswordField"):
result = {
"type": meta_type,
"key": field.generate_field_key(),
"default": field.get_value("default"),
"editable": field.get_value("editable"),
"css_class": field.get_value("css_class"),
"hidden": field.get_value("hidden"),
"description": field.get_value("description"),
"title": field.get_value("title"),
"required": field.get_value("required"),
}
elif meta_type == "ListBox":
# XXX Not implemented
columns = field.get_value("columns")
# XXX
# list_method = getattr(traversed_document, traversed_document.Listbox_getListMethodName(field))
# portal_types = [x[1] for x in field.get_value('portal_types')]
portal_types = field.get_value('portal_types')
default_params = dict(field.get_value('default_params'))
# How to implement pagination?
# default_params.update(REQUEST.form)
lines = field.get_value('lines')
list_method_name = traversed_document.Listbox_getListMethodName(field)
list_method_query_dict = dict(
portal_type=[x[1] for x in portal_types], **default_params
)
if (list_method_name == "portal_catalog"):
pass
elif (list_method_name in ("searchFolder", "objectValues")):
list_method_query_dict["parent_uid"] = traversed_document.getUid()
# XXX How to handle script queries?
# else:
# raise NotImplementedError("Unsupported list method %s" % list_method_name)
# row_list = list_method(limit=lines, portal_type=portal_types,
# **default_params)
# line_list = []
# for row in row_list:
# document = row.getObject()
# line = {
# "url": url_template_dict["document_hal"] % {
# "root_url": site_root.absolute_url(),
# "relative_url": document.getRelativeUrl(),
# "script_id": script.id
# }
# }
# for property, title in columns:
# prop = document.getProperty(property)
# if same_type(prop, DateTime()):
# prop = "XXX Serialize DateTime"
# line[title] = prop
# line["_relative_url"] = document.getRelativeUrl()
# line_list.append(line)
result = {
"type": meta_type,
# "column_list": [x[1] for x in columns],
"column_list": columns,
# "line_list": line_list,
"title": field.get_value("title"),
"key": field.generate_field_key(),
"portal_type": portal_types,
"lines": lines,
"default_params": default_params,
"list_method": list_method_name,
"query": url_template_dict["jio_search_template"] % {
"query": make_query({"query": sql_catalog.buildQuery(
list_method_query_dict
).asSearchTextExpression(sql_catalog)})
}
}
else:
# XXX Not implemented
result = {
"type": meta_type,
"_debug": "Unsupported field type",
"title": field.get_value("title"),
"key": field.generate_field_key(),
}
return result
def renderForm(form, response_dict):
REQUEST.set('here', traversed_document)
# Form action
response_dict['_actions'] = {
'put': {
"href": url_template_dict["form_action"] % {
"traversed_document_url": traversed_document.absolute_url(),
"action_id": form.action
},
"method": form.method,
}
}
# Form traversed_document
response_dict['_links']['traversed_document'] = {
"href": default_document_uri_template % {
"root_url": site_root.absolute_url(),
"relative_url": traversed_document.getRelativeUrl(),
"script_id": script.id
},
"name": traversed_document.getRelativeUrl(),
"title": traversed_document.getTitle()
}
response_dict['_links']['form_definition'] = {
# "href": default_document_uri_template % {
# "root_url": site_root.absolute_url(),
# "script_id": script.id,
# "relative_url": getFormRelativeUrl(form)
# },
"href": default_document_uri_template % {
"relative_url": getFormRelativeUrl(form)
},
'name': form.id
}
group_list = []
for group in form.Form_getGroupTitleAndId():
if group['gid'].find('hidden') < 0:
# field_list = []
for field in form.get_fields_in_group(group['goid']):
# field_list.append((field.id, renderRawField(field)))
if field.get_value("enabled"):
response_dict[field.id] = renderField(field)
# for field_group in field.form.get_groups():
# traversed_document.log("Field group: " + field_group)
# traversed_document.log(field_group)
# for field_property in field.form.get_fields_in_group(field_group):
# # traversed_document.log("Field attribute: " + field_property.id)
# # field.get_value(field_property.id)
# traversed_document.log(field_property)
# group_list.append((group['gid'], field_list))
response_dict["form_id"] = {
"type": "StringField",
"key": "form_id",
"default": form.id,
"editable": 0,
"css_class": "",
"hidden": 1,
"description": "",
"title": "form_id",
"required": 1,
}
# response_dict["group_list"] = group_list
# rendered_response_dict["_embedded"] = {
# "form": raw_response_dict
# }
# XXX form action update, etc
def renderRawField(field):
meta_type = field.meta_type
return {
"meta_type": field.meta_type
}
if meta_type == "MethodField":
result = {
"meta_type": field.meta_type
}
else:
result = {
"meta_type": field.meta_type,
"_values": field.values,
# XXX TALES expression is not JSON serializable by default
# "_tales": field.tales
"_overrides": field.overrides
}
if meta_type == "ProxyField":
result['_delegated_list'] = field.delegated_list
# try:
# result['_delegated_list'].pop('list_method')
# except KeyError:
# pass
# XXX ListMethod is not JSON serialized by default
try:
result['_values'].pop('list_method')
except KeyError:
pass
try:
result['_overrides'].pop('list_method')
except KeyError:
pass
return result
def renderFormDefinition(form, response_dict):
group_list = []
for group in form.Form_getGroupTitleAndId():
if group['gid'].find('hidden') < 0:
field_list = []
for field in form.get_fields_in_group(group['goid']):
field_list.append((field.id, renderRawField(field)))
group_list.append((group['gid'], field_list))
response_dict["group_list"] = group_list
context.Base_prepareCorsResponse(RESPONSE=response)
mime_type = 'application/hal+json'
portal = context.getPortalObject()
sql_catalog = portal.portal_catalog.getSQLCatalog()
# Calculate the site root to prevent unexpected browsing
is_web_mode = (context.REQUEST.get('current_web_section', None) is not None) or context.isWebMode()
# is_web_mode = traversed_document.isWebMode()
if is_web_mode:
site_root = context.getWebSiteValue()
else:
site_root = portal
# Check if traversed_document is the site_root
if relative_url:
traversed_document = site_root.restrictedTraverse(relative_url)
else:
traversed_document = context
is_site_root = (traversed_document.getPath() == site_root.getPath())
is_portal = (traversed_document.getPath() == portal.getPath())
result_dict = {
'_debug': mode,
'_links': {
"self": {
# XXX Include query parameters
"href": traversed_document.Base_getRequestUrl()
},
# Always inform about site root
"site_root": {
"href": default_document_uri_template % {
"root_url": site_root.absolute_url(),
"relative_url": site_root.getRelativeUrl(),
"script_id": script.id
},
"name": site_root.getTitle(),
},
# Always inform about portal
"portal": {
"href": default_document_uri_template % {
"root_url": portal.absolute_url(),
# XXX the portal has an empty getRelativeUrl. Make it still compatible
# with restrictedTraverse
"relative_url": portal.getId(),
"script_id": script.id
},
"name": portal.getTitle(),
}
}
}
if mime_type != traversed_document.Base_handleAcceptHeader([mime_type]):
response.setStatus(406)
return ""
elif (mode == 'root') or (mode == 'traverse'):
#################################################
# Raw document
#################################################
if REQUEST.other['method'] != "GET":
response.setStatus(405)
return ""
# Default properties shared by all ERP5 Document and Site
action_dict = {}
# result_dict['_relative_url'] = traversed_document.getRelativeUrl()
# Add a link to the portal type if possible
if not is_portal:
result_dict['_links']['type'] = {
"href": default_document_uri_template % {
"root_url": site_root.absolute_url(),
"relative_url": portal.portal_types[traversed_document.getPortalType()]\
.getRelativeUrl(),
"script_id": script.id
},
"name": traversed_document.getPortalType(),
}
# XXX Loop on form rendering
erp5_action_dict = portal.Base_filterDuplicateActions(
portal.portal_actions.listFilteredActionsFor(traversed_document))
embedded_url = None
embedded_action_key = None
# XXX See ERP5Type.getDefaultViewFor
for erp5_action_key in erp5_action_dict.keys():
erp5_action_list = []
for view_action in erp5_action_dict[erp5_action_key]:
# Action condition is probably checked in Base_filterDuplicateActions
erp5_action_list.append({
'href': '%s' % view_action['url'],
'name': view_action['id'],
'title': view_action['title']
})
# Try to embed the form in the result
if (view == view_action['id']):
embedded_url = '%s' % view_action['url']
embedded_action_key = "action_" + erp5_action_key
if erp5_action_list:
if len(erp5_action_list) == 1:
erp5_action_list = erp5_action_list[0]
# XXX Put a prefix to prevent conflict
result_dict['_links']["action_" + erp5_action_key] = erp5_action_list
# for view_action in erp5_action_dict.get('object_view', []):
# traversed_document.log(view_action)
# # XXX Check the action condition
# # if (view is None) or (view != view_action['name']):
# object_view_list.append({
# 'href': '%s' % view_action['url'],
# 'name': view_action['name']
# })
# # XXX Check that traversed_document is not the portal
# if (traversed_document.getRelativeUrl() != portal.getRelativeUrl()) and (traversed_document.getRelativeUrl() != site_root.getRelativeUrl()):
# parent = traversed_document.getParentValue()
# if (is_web_mode and (parent.getRelativeUrl() != portal.getRelativeUrl())):
# result_dict['_links']['parent'] = {
# 'href': '%s' % parent.absolute_url(),
# 'name': parent.getTitle()
# }
#
# if (renderer_form is not None):
# traversed_document_property_dict, renderer_form_json = traversed_document.Base_renderFormAsSomething(renderer_form)
# result_dict['_embedded'] = {
# 'object_view': renderer_form_json
# }
# result_dict.update(traversed_document_property_dict)
# XXX XXX XXX XXX
if (embedded_url is not None):
# XXX Try to fetch the form in the traversed_document of the document
# Of course, this code will completely crash in many cases (page template
# instead of form, unexpected action TALES expression). Happy debugging.
# renderer_form_relative_url = view_action['url'][len(portal.absolute_url()):]
form_id = embedded_url.split('?', 1)[0].split("/")[-1]
# XXX Drop (or do something else...) all query parameters (?reset:int=1)
# renderer_form = traversed_document.restrictedTraverse(form_id, None)
# XXX Proxy field are not correctly handled in traversed_document of web site
renderer_form = getattr(traversed_document, form_id)
# traversed_document.log(form_id)
if (renderer_form is not None):
embedded_dict = {
'_links': {
'self': {
'href': embedded_url
}
}
}
renderForm(renderer_form, embedded_dict)
result_dict['_embedded'] = {
'_view': embedded_dict
# embedded_action_key: embedded_dict
}
# result_dict['_links']["_view"] = {"href": embedded_url}
# Include properties in document JSON
# XXX Extract from renderer form?
for group in renderer_form.Form_getGroupTitleAndId():
for field in renderer_form.get_fields_in_group(group['goid']):
field_id = field.id
# traversed_document.log(field_id)
if field_id.startswith('my_'):
property_name = field_id[len('my_'):]
# traversed_document.log(property_name)
property_value = traversed_document.getProperty(property_name, d=None)
if (property_value is not None):
if same_type(property_value, DateTime()):
# Serialize DateTime
property_value = rfc822()
result_dict[property_name] = property_value
##############
# XXX Custom slapos code
##############
if is_site_root:
# Global action users for the jIO plugin
# XXX Would be better to not hardcode them but put them as portal type
# "actions" (search could be on portal_catalog document, traverse on all
# documents, newContent on all, etc)
# result_dict['_links']['object_search'] = {
# 'href': '%s/ERP5Site_viewSearchForm?portal_skin=Hal' % absolute_url,
# 'name': 'Global Search'
# }
result_dict['_links']['raw_search'] = {
"href": url_template_dict["search_template"] % {
"root_url": site_root.absolute_url(),
"script_id": script.id
},
'name': 'Raw Search',
'templated': True
}
result_dict['_links']['traverse'] = {
"href": url_template_dict["traverse_template"] % {
"root_url": site_root.absolute_url(),
"script_id": script.id
},
'name': 'Traverse',
'templated': True
}
action_dict['add'] = {
"href": url_template_dict["new_content_action"] % {
"root_url": site_root.absolute_url(),
"script_id": script.id
},
'method': 'POST',
'name': 'New Content',
}
# Handle also other kind of users: instance, computer, master
person = portal.ERP5Site_getAuthenticatedMemberPersonValue()
if person is not None:
result_dict['_links']['me'] = {
"href": default_document_uri_template % {
"root_url": site_root.absolute_url(),
"relative_url": person.getRelativeUrl(),
"script_id": script.id
},
# '_relative_url': person.getRelativeUrl()
}
query = sql_catalog.buildQuery({
"portal_type": "Software Product",
"validation_state": 'published'
}).asSearchTextExpression(sql_catalog)
http_query = make_query({
"mode": "search",
"query": query
})
result_dict['_links']['slapos_jump'] = {
"href": "%s/%s?%s" % (site_root.absolute_url(), script.id, http_query),
'_query': query,
'name': 'public_software_product'
}
else:
traversed_document_portal_type = traversed_document.getPortalType()
if traversed_document_portal_type == "Person":
query = sql_catalog.buildQuery({
"portal_type": "Hosting Subscription",
"default_destination_section_uid": traversed_document.getUid(),
"validation_state": 'validated'
}).asSearchTextExpression(sql_catalog)
http_query = make_query({
"mode": "search",
"query": query
})
result_dict['_links']['slapos_jump'] = [{
"href": "%s/%s?%s" % (site_root.absolute_url(), script.id, http_query),
'name': 'current_hosting_subscription',
'_query': query
}]
# List of validated computers
query = sql_catalog.buildQuery({
"portal_type": "Computer",
"local_roles": "Assignee",
"default_strict_allocation_scope_uid": "!=%s" % traversed_document.getPortalObject().portal_categories.allocation_scope.close.forever.getUid(),
"validation_state": 'validated'
}).asSearchTextExpression(sql_catalog)
http_query = make_query({
"mode": "search",
"query": query
})
result_dict['_links']['slapos_jump'].append({
"href": "%s/%s?%s" % (site_root.absolute_url(), script.id, http_query),
'name': 'current_computer',
'_query': query
})
# List of networks
query = sql_catalog.buildQuery({
"portal_type": "Computer Network",
"local_roles": "Assignee"
}).asSearchTextExpression(sql_catalog)
http_query = make_query({
"mode": "search",
"query": query
})
result_dict['_links']['slapos_jump'].append({
"href": "%s/%s?%s" % (site_root.absolute_url(), script.id, http_query),
'name': 'current_network',
'_query': query
})
# List of invoices
query = sql_catalog.buildQuery({
"portal_type": "Sale Invoice Transaction",
"default_destination_section_uid": traversed_document.getUid(),
"query": NegatedQuery(Query(title="Reversal Transaction for %")),
}).asSearchTextExpression(sql_catalog)
http_query = make_query({
"mode": "search",
"query": query
})
result_dict['_links']['slapos_jump'].append({
"href": "%s/%s?%s" % (site_root.absolute_url(), script.id, http_query),
'name': 'current_invoice',
'_query': query
})
# List of tickets
query = sql_catalog.buildQuery({
"portal_type": ["Support Request", "Regularisation Request"],
"default_destination_decision_uid": traversed_document.getUid(),
}).asSearchTextExpression(sql_catalog)
http_query = make_query({
"mode": "search",
"query": query
})
result_dict['_links']['slapos_jump'].append({
"href": "%s/%s?%s" % (site_root.absolute_url(), script.id, http_query),
'name': 'current_ticket',
'_query': query
})
action_dict['request'] = {
'href': "%s/Person_requestInstanceFromJio" % traversed_document.absolute_url(),
'method': 'POST'
}
action_dict['request_computer'] = {
'href': "%s/Person_requestComputerFromJio" % traversed_document.absolute_url(),
'method': 'POST'
}
action_dict['request_computer_network'] = {
'href': "%s/Person_requestComputerNetworkFromJio" % traversed_document.absolute_url(),
'method': 'POST'
}
action_dict['request_ticket'] = {
'href': "%s/Person_requestTicketFromJio" % traversed_document.absolute_url(),
'method': 'POST'
}
elif traversed_document_portal_type == "Hosting Subscription":
# Link to all ongoing Hosting Subscriptions
query = sql_catalog.buildQuery({
"portal_type": ["Software Instance", "Slave Instance"],
"default_specialise_uid": traversed_document.getUid(),
"validation_state": 'validated'
}).asSearchTextExpression(sql_catalog)
http_query = make_query({
"mode": "search",
"query": query
})
result_dict['_links']['slapos_jump'] = {
"href": "%s/%s?%s" % (site_root.absolute_url(), script.id, http_query),
'name': 'related_instance',
'_query': query
}
# Actions to modify the hosting subscription
action_dict['start'] = {
'href': "%s/HostingSubscription_changeRequestedStateFromJio?action=started" % traversed_document.absolute_url(),
'method': 'POST'
}
action_dict['stop'] = {
'href': "%s/HostingSubscription_changeRequestedStateFromJio?action=stopped" % traversed_document.absolute_url(),
'method': 'POST'
}
action_dict['destroy'] = {
'href': "%s/HostingSubscription_changeRequestedStateFromJio?action=destroyed" % traversed_document.absolute_url(),
'method': 'POST'
}
elif traversed_document_portal_type == "Software Installation":
action_dict['destroy'] = {
'href': "%s/SoftwareInstallation_destroyFromJio" % traversed_document.absolute_url(),
'method': 'POST'
}
elif traversed_document_portal_type == "Software Product":
# Link to all Software Releases
query = sql_catalog.buildQuery({
"portal_type": "Software Release",
"default_aggregate_uid": traversed_document.getUid(),
"validation_state": ["shared", "shared_alive", "released", "released_alive", "published", "published_alive"]
}).asSearchTextExpression(sql_catalog)
http_query = make_query({
"mode": "search",
"query": query
})
result_dict['_links']['slapos_jump'] = {
"href": "%s/%s?%s" % (site_root.absolute_url(), script.id, http_query),
'name': 'related_software_release',
'_query': query
}
elif traversed_document_portal_type == "Computer":
# Link to related Software Installation
query = sql_catalog.buildQuery({
"portal_type": "Software Installation",
"default_aggregate_uid": traversed_document.getUid(),
"validation_state": "validated"
}).asSearchTextExpression(sql_catalog)
http_query = make_query({
"mode": "search",
"query": query
})
result_dict['_links']['slapos_jump'] = {
"href": "%s/%s?%s" % (site_root.absolute_url(), script.id, http_query),
'name': 'related_software_installation',
'_query': query
}
action_dict['update_allocation_scope'] = {
'href': "%s/Computer_updateAllocationScopeFromJio" % traversed_document.absolute_url(),
'method': 'POST'
}
action_dict['generate_certificate'] = {
'href': "%s/Computer_requestNewComputerCertificateFromJio" % traversed_document.absolute_url(),
'method': 'POST'
}
action_dict['revoke_certificate'] = {
'href': "%s/Computer_revokeComputerCertificateFromJio" % traversed_document.absolute_url(),
'method': 'POST'
}
action_dict['request_installation'] = {
'href': "%s/Computer_requestInstallationFromJio" % traversed_document.absolute_url(),
'method': 'POST'
}
elif traversed_document_portal_type == "Sale Invoice Transaction":
result_dict['_links']['slapos_jump'] = {
"href": "%s/SaleInvoiceTransaction_viewSlapOSPrintout" % traversed_document.absolute_url(),
'name': 'current_printout',
}
elif traversed_document_portal_type in ["Support Request", "Regularisation Request"]:
# Link to all Events
query = sql_catalog.buildQuery({
"default_follow_up_uid": traversed_document.getUid(),
}).asSearchTextExpression(sql_catalog)
http_query = make_query({
"mode": "search",
"query": query
})
result_dict['_links']['slapos_jump'] = {
"href": "%s/%s?%s" % (site_root.absolute_url(), script.id, http_query),
'name': 'related_event',
'_query': query
}
action_dict['update'] = {
'href': "%s/Ticket_updateFromJio" % traversed_document.absolute_url(),
'method': 'POST'
}
elif traversed_document_portal_type == "ERP5 Form":
renderFormDefinition(traversed_document, result_dict)
# Define document action
if action_dict:
result_dict['_actions'] = action_dict
elif mode == 'search':
#################################################
# Portal catalog search
#################################################
if REQUEST.other['method'] != "GET":
response.setStatus(405)
return ""
if query == "__root__":
# XXX Hardcoded behaviour to get root object with jIO
sql_list = [site_root]
elif query == "__portal__":
# XXX Hardcoded behaviour to get portal object with jIO
sql_list = [portal]
# document = site_root
# document_result = {
# # '_relative_url': site_root.getRelativeUrl(),
# '_links': {
# 'self': {
# "href": default_document_uri_template % {
# "root_url": site_root.absolute_url(),
# "relative_url": document.getRelativeUrl(),
# "script_id": script.id
# },
# },
# }
# }
# for select in select_list:
# document_result[select] = document.getProperty(select, d=None)
# result_dict['_embedded'] = {"contents": [document_result]}
else:
# raise NotImplementedError("Unsupported query: %s" % query)
# # XXX
# length = len('/%s/' % portal.getId())
# # context.log(portal.portal_catalog(full_text=query, limit=limit, src__=1))
# context.log(query)
if query:
sql_list = portal.portal_catalog(full_text=query, limit=limit)
else:
sql_list = portal.portal_catalog(limit=limit)
result_list = []
# if (select_list is None):
# # Only include links
# for sql_document in sql_list:
# document = sql_document.getObject()
# result_list.append({
# "href": default_document_uri_template % {
# "root_url": site_root.absolute_url(),
# "relative_url": document.getRelativeUrl(),
# "script_id": script.id
# },
# })
# result_dict['_links']['contents'] = result_list
#
# else:
# Cast to list if only one element is provided
if same_type(select_list, ""):
select_list = [select_list]
for sql_document in sql_list:
try:
document = sql_document.getObject()
except AttributeError:
# XXX ERP5 Site is not an ERP5 document
document = sql_document
document_result = {
# '_relative_url': sql_document.path[length:],
'_links': {
'self': {
"href": default_document_uri_template % {
"root_url": site_root.absolute_url(),
# XXX ERP5 Site is not an ERP5 document
"relative_url": document.getRelativeUrl() or document.getId(),
"script_id": script.id
},
},
}
}
for select in select_list:
property_value = document.getProperty(select, d=None)
if property_value is not None:
document_result[select] = property_value
result_list.append(document_result)
result_dict['_embedded'] = {"contents": result_list}
result_dict['_query'] = query
result_dict['_limit'] = limit
result_dict['_select_list'] = select_list
elif mode == 'newContent':
#################################################
# Create new document
#################################################
if REQUEST.other['method'] != "POST":
response.setStatus(405)
return ""
portal_type = REQUEST.form["portal_type"]
module = portal.getDefaultModule(portal_type=portal_type)
document = module.newContent(
portal_type=portal_type
)
# http://en.wikipedia.org/wiki/Post/Redirect/Get
response.setStatus(201)
response.setHeader("X-Location",
default_document_uri_template % {
"root_url": site_root.absolute_url(),
"relative_url": document.getRelativeUrl(),
"script_id": script.id
})
return ''
elif mode == 'form':
#################################################
# Calculate form value
#################################################
if REQUEST.other['method'] != "GET":
response.setStatus(405)
return ""
renderForm(form, result_dict)
# elif mode == 'form_definition':
# #################################################
# # Get raw form definitions
# #################################################
# if REQUEST.other['method'] != "GET":
# response.setStatus(405)
# return ""
#
# form = getattr(portal, skin_id)
# renderFormDefinition(form, result_dict)
else:
raise NotImplementedError, "Unsupported mode %s" % mode
response.setHeader('Content-Type', mime_type)
return json.dumps(result_dict, indent=2)
...@@ -48,893 +48,6 @@ ...@@ -48,893 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
from zExceptions import Unauthorized\n
from AccessControl import getSecurityManager\n
from ZTUtils import make_query\n
from Products.ZSQLCatalog.SQLCatalog import Query, NegatedQuery\n
import json\n
if REQUEST is None:\n
REQUEST = context.REQUEST\n
# raise Unauthorized\n
if response is None:\n
response = REQUEST.RESPONSE\n
\n
url_template_dict = {\n
"form_action": "%(traversed_document_url)s/%(action_id)s",\n
"traverse_template": "%(root_url)s/%(script_id)s?mode=traverse" + \\\n
"{&relative_url,view}",\n
"search_template": "%(root_url)s/%(script_id)s?mode=search" + \\\n
"{&query,select_list*,limit*}",\n
"new_content_action": "%(root_url)s/%(script_id)s?mode=newContent",\n
# XXX View is set by default to empty\n
"document_hal": "%(root_url)s/%(script_id)s?mode=traverse" + \\\n
"&relative_url=%(relative_url)s",\n
"jio_get_template": "urn:jio:get:%(relative_url)s",\n
"jio_search_template": "urn:jio:allDocs?%(query)s",\n
}\n
\n
default_document_uri_template = url_template_dict["jio_get_template"]\n
\n
def getFormRelativeUrl(form):\n
return portal.portal_catalog(\n
portal_type="ERP5 Form",\n
uid=form.getUid(),\n
id=form.getId(),\n
limit=1,\n
select_dict={\'relative_url\': None}\n
)[0].relative_url\n
\n
def renderField(field, meta_type=None):\n
if meta_type is None:\n
meta_type = field.meta_type\n
\n
if meta_type == "ProxyField":\n
result = renderField(field, meta_type=field.getRecursiveTemplateField().meta_type)\n
elif meta_type in ("ListField", "ParallelListField", "MultiListField"):\n
result = {\n
"type": meta_type,\n
"key": field.generate_field_key(),\n
"default": field.get_value("default"),\n
"editable": field.get_value("editable"),\n
"css_class": field.get_value("css_class"),\n
"hidden": field.get_value("hidden"),\n
"description": field.get_value("description"),\n
"title": field.get_value("title"),\n
"required": field.get_value("required"),\n
# XXX Message can not be converted to json as is\n
"items": field.get_value("items"),\n
}\n
elif meta_type in ("StringField", "FloatField", "RelationStringField",\n
"MultiRelationStringField", "EmailField", "TextAreaField",\n
"LinesField", "ImageField", "FileField", "IntegerField",\n
"PasswordField"):\n
result = {\n
"type": meta_type,\n
"key": field.generate_field_key(),\n
"default": field.get_value("default"),\n
"editable": field.get_value("editable"),\n
"css_class": field.get_value("css_class"),\n
"hidden": field.get_value("hidden"),\n
"description": field.get_value("description"),\n
"title": field.get_value("title"),\n
"required": field.get_value("required"),\n
}\n
elif meta_type == "ListBox":\n
# XXX Not implemented\n
columns = field.get_value("columns")\n
\n
# XXX \n
# list_method = getattr(traversed_document, traversed_document.Listbox_getListMethodName(field))\n
# portal_types = [x[1] for x in field.get_value(\'portal_types\')]\n
portal_types = field.get_value(\'portal_types\')\n
default_params = dict(field.get_value(\'default_params\'))\n
# How to implement pagination?\n
# default_params.update(REQUEST.form)\n
lines = field.get_value(\'lines\')\n
list_method_name = traversed_document.Listbox_getListMethodName(field)\n
list_method_query_dict = dict(\n
portal_type=[x[1] for x in portal_types], **default_params\n
)\n
\n
if (list_method_name == "portal_catalog"):\n
pass\n
elif (list_method_name in ("searchFolder", "objectValues")):\n
list_method_query_dict["parent_uid"] = traversed_document.getUid()\n
# XXX How to handle script queries?\n
# else:\n
# raise NotImplementedError("Unsupported list method %s" % list_method_name)\n
\n
\n
\n
# row_list = list_method(limit=lines, portal_type=portal_types,\n
# **default_params)\n
# line_list = []\n
# for row in row_list:\n
# document = row.getObject()\n
# line = {\n
# "url": url_template_dict["document_hal"] % {\n
# "root_url": site_root.absolute_url(),\n
# "relative_url": document.getRelativeUrl(),\n
# "script_id": script.id\n
# }\n
# }\n
# for property, title in columns:\n
# prop = document.getProperty(property)\n
# if same_type(prop, DateTime()):\n
# prop = "XXX Serialize DateTime" \n
# line[title] = prop\n
# line["_relative_url"] = document.getRelativeUrl()\n
# line_list.append(line)\n
\n
result = {\n
"type": meta_type,\n
# "column_list": [x[1] for x in columns],\n
"column_list": columns,\n
# "line_list": line_list,\n
"title": field.get_value("title"),\n
"key": field.generate_field_key(),\n
"portal_type": portal_types,\n
"lines": lines,\n
"default_params": default_params,\n
"list_method": list_method_name,\n
"query": url_template_dict["jio_search_template"] % {\n
"query": make_query({"query": sql_catalog.buildQuery(\n
list_method_query_dict\n
).asSearchTextExpression(sql_catalog)})\n
}\n
}\n
else:\n
# XXX Not implemented\n
result = {\n
"type": meta_type,\n
"_debug": "Unsupported field type",\n
"title": field.get_value("title"),\n
"key": field.generate_field_key(),\n
}\n
return result\n
\n
\n
def renderForm(form, response_dict):\n
REQUEST.set(\'here\', traversed_document)\n
\n
# Form action\n
response_dict[\'_actions\'] = {\n
\'put\': {\n
"href": url_template_dict["form_action"] % {\n
"traversed_document_url": traversed_document.absolute_url(),\n
"action_id": form.action\n
},\n
"method": form.method,\n
}\n
}\n
# Form traversed_document\n
response_dict[\'_links\'][\'traversed_document\'] = {\n
"href": default_document_uri_template % {\n
"root_url": site_root.absolute_url(),\n
"relative_url": traversed_document.getRelativeUrl(),\n
"script_id": script.id\n
},\n
"name": traversed_document.getRelativeUrl(),\n
"title": traversed_document.getTitle()\n
}\n
\n
response_dict[\'_links\'][\'form_definition\'] = {\n
# "href": default_document_uri_template % {\n
# "root_url": site_root.absolute_url(),\n
# "script_id": script.id,\n
# "relative_url": getFormRelativeUrl(form)\n
# },\n
"href": default_document_uri_template % {\n
"relative_url": getFormRelativeUrl(form)\n
},\n
\'name\': form.id\n
}\n
\n
group_list = []\n
for group in form.Form_getGroupTitleAndId():\n
\n
if group[\'gid\'].find(\'hidden\') < 0:\n
# field_list = []\n
for field in form.get_fields_in_group(group[\'goid\']):\n
# field_list.append((field.id, renderRawField(field)))\n
if field.get_value("enabled"):\n
response_dict[field.id] = renderField(field)\n
\n
# for field_group in field.form.get_groups():\n
# traversed_document.log("Field group: " + field_group)\n
# traversed_document.log(field_group)\n
# for field_property in field.form.get_fields_in_group(field_group):\n
# # traversed_document.log("Field attribute: " + field_property.id)\n
# # field.get_value(field_property.id)\n
# traversed_document.log(field_property)\n
\n
# group_list.append((group[\'gid\'], field_list))\n
\n
response_dict["form_id"] = {\n
"type": "StringField",\n
"key": "form_id",\n
"default": form.id,\n
"editable": 0,\n
"css_class": "",\n
"hidden": 1,\n
"description": "",\n
"title": "form_id",\n
"required": 1,\n
}\n
\n
# response_dict["group_list"] = group_list\n
# rendered_response_dict["_embedded"] = {\n
# "form": raw_response_dict\n
# }\n
\n
\n
# XXX form action update, etc\n
def renderRawField(field):\n
meta_type = field.meta_type\n
\n
return {\n
"meta_type": field.meta_type\n
}\n
\n
\n
if meta_type == "MethodField":\n
result = {\n
"meta_type": field.meta_type\n
}\n
else:\n
result = {\n
"meta_type": field.meta_type,\n
"_values": field.values,\n
# XXX TALES expression is not JSON serializable by default\n
# "_tales": field.tales\n
"_overrides": field.overrides\n
}\n
if meta_type == "ProxyField":\n
result[\'_delegated_list\'] = field.delegated_list\n
# try:\n
# result[\'_delegated_list\'].pop(\'list_method\')\n
# except KeyError:\n
# pass\n
\n
# XXX ListMethod is not JSON serialized by default\n
try:\n
result[\'_values\'].pop(\'list_method\')\n
except KeyError:\n
pass\n
try:\n
result[\'_overrides\'].pop(\'list_method\')\n
except KeyError:\n
pass\n
return result\n
\n
\n
def renderFormDefinition(form, response_dict):\n
group_list = []\n
for group in form.Form_getGroupTitleAndId():\n
\n
if group[\'gid\'].find(\'hidden\') < 0:\n
field_list = []\n
\n
for field in form.get_fields_in_group(group[\'goid\']):\n
field_list.append((field.id, renderRawField(field)))\n
\n
group_list.append((group[\'gid\'], field_list))\n
response_dict["group_list"] = group_list\n
\n
\n
context.Base_prepareCorsResponse(RESPONSE=response)\n
\n
mime_type = \'application/hal+json\'\n
portal = context.getPortalObject()\n
sql_catalog = portal.portal_catalog.getSQLCatalog()\n
\n
# Calculate the site root to prevent unexpected browsing\n
is_web_mode = (context.REQUEST.get(\'current_web_section\', None) is not None) or context.isWebMode()\n
# is_web_mode = traversed_document.isWebMode()\n
if is_web_mode:\n
site_root = context.getWebSiteValue()\n
else:\n
site_root = portal\n
\n
# Check if traversed_document is the site_root\n
if relative_url:\n
traversed_document = site_root.restrictedTraverse(relative_url)\n
else:\n
traversed_document = context\n
is_site_root = (traversed_document.getPath() == site_root.getPath())\n
is_portal = (traversed_document.getPath() == portal.getPath())\n
\n
result_dict = {\n
\'_debug\': mode,\n
\'_links\': {\n
"self": {\n
# XXX Include query parameters\n
"href": traversed_document.Base_getRequestUrl()\n
},\n
# Always inform about site root\n
"site_root": {\n
"href": default_document_uri_template % {\n
"root_url": site_root.absolute_url(),\n
"relative_url": site_root.getRelativeUrl(),\n
"script_id": script.id\n
},\n
"name": site_root.getTitle(),\n
},\n
# Always inform about portal\n
"portal": {\n
"href": default_document_uri_template % {\n
"root_url": portal.absolute_url(),\n
# XXX the portal has an empty getRelativeUrl. Make it still compatible\n
# with restrictedTraverse\n
"relative_url": portal.getId(),\n
"script_id": script.id\n
},\n
"name": portal.getTitle(),\n
}\n
}\n
}\n
\n
\n
if mime_type != traversed_document.Base_handleAcceptHeader([mime_type]):\n
response.setStatus(406)\n
return ""\n
\n
\n
elif (mode == \'root\') or (mode == \'traverse\'):\n
#################################################\n
# Raw document\n
#################################################\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
# Default properties shared by all ERP5 Document and Site\n
action_dict = {}\n
# result_dict[\'_relative_url\'] = traversed_document.getRelativeUrl()\n
\n
# Add a link to the portal type if possible\n
if not is_portal:\n
result_dict[\'_links\'][\'type\'] = {\n
"href": default_document_uri_template % {\n
"root_url": site_root.absolute_url(),\n
"relative_url": portal.portal_types[traversed_document.getPortalType()]\\\n
.getRelativeUrl(), \n
"script_id": script.id\n
},\n
"name": traversed_document.getPortalType(),\n
}\n
\n
# XXX Loop on form rendering\n
erp5_action_dict = portal.Base_filterDuplicateActions(\n
portal.portal_actions.listFilteredActionsFor(traversed_document))\n
\n
embedded_url = None\n
embedded_action_key = None\n
# XXX See ERP5Type.getDefaultViewFor\n
for erp5_action_key in erp5_action_dict.keys():\n
erp5_action_list = []\n
for view_action in erp5_action_dict[erp5_action_key]:\n
# Action condition is probably checked in Base_filterDuplicateActions\n
erp5_action_list.append({\n
\'href\': \'%s\' % view_action[\'url\'],\n
\'name\': view_action[\'id\'],\n
\'title\': view_action[\'title\']\n
})\n
# Try to embed the form in the result\n
if (view == view_action[\'id\']):\n
embedded_url = \'%s\' % view_action[\'url\']\n
embedded_action_key = "action_" + erp5_action_key\n
\n
if erp5_action_list:\n
if len(erp5_action_list) == 1:\n
erp5_action_list = erp5_action_list[0]\n
# XXX Put a prefix to prevent conflict\n
result_dict[\'_links\']["action_" + erp5_action_key] = erp5_action_list\n
\n
# for view_action in erp5_action_dict.get(\'object_view\', []):\n
# traversed_document.log(view_action)\n
# # XXX Check the action condition\n
# # if (view is None) or (view != view_action[\'name\']):\n
# object_view_list.append({\n
# \'href\': \'%s\' % view_action[\'url\'],\n
# \'name\': view_action[\'name\']\n
# })\n
\n
# # XXX Check that traversed_document is not the portal\n
# if (traversed_document.getRelativeUrl() != portal.getRelativeUrl()) and (traversed_document.getRelativeUrl() != site_root.getRelativeUrl()):\n
# parent = traversed_document.getParentValue()\n
# if (is_web_mode and (parent.getRelativeUrl() != portal.getRelativeUrl())):\n
# result_dict[\'_links\'][\'parent\'] = {\n
# \'href\': \'%s\' % parent.absolute_url(),\n
# \'name\': parent.getTitle()\n
# }\n
# \n
# if (renderer_form is not None):\n
# traversed_document_property_dict, renderer_form_json = traversed_document.Base_renderFormAsSomething(renderer_form)\n
# result_dict[\'_embedded\'] = {\n
# \'object_view\': renderer_form_json\n
# }\n
# result_dict.update(traversed_document_property_dict)\n
\n
# XXX XXX XXX XXX\n
if (embedded_url is not None):\n
# XXX Try to fetch the form in the traversed_document of the document\n
# Of course, this code will completely crash in many cases (page template\n
# instead of form, unexpected action TALES expression). Happy debugging.\n
# renderer_form_relative_url = view_action[\'url\'][len(portal.absolute_url()):]\n
form_id = embedded_url.split(\'?\', 1)[0].split("/")[-1]\n
# XXX Drop (or do something else...) all query parameters (?reset:int=1)\n
# renderer_form = traversed_document.restrictedTraverse(form_id, None)\n
# XXX Proxy field are not correctly handled in traversed_document of web site\n
renderer_form = getattr(traversed_document, form_id)\n
# traversed_document.log(form_id)\n
if (renderer_form is not None):\n
embedded_dict = {\n
\'_links\': {\n
\'self\': {\n
\'href\': embedded_url\n
}\n
}\n
}\n
renderForm(renderer_form, embedded_dict)\n
result_dict[\'_embedded\'] = {\n
\'_view\': embedded_dict\n
# embedded_action_key: embedded_dict\n
}\n
# result_dict[\'_links\']["_view"] = {"href": embedded_url}\n
\n
# Include properties in document JSON\n
# XXX Extract from renderer form?\n
for group in renderer_form.Form_getGroupTitleAndId():\n
for field in renderer_form.get_fields_in_group(group[\'goid\']):\n
field_id = field.id\n
# traversed_document.log(field_id)\n
if field_id.startswith(\'my_\'):\n
property_name = field_id[len(\'my_\'):]\n
# traversed_document.log(property_name)\n
property_value = traversed_document.getProperty(property_name, d=None)\n
if (property_value is not None):\n
if same_type(property_value, DateTime()):\n
# Serialize DateTime\n
property_value = rfc822()\n
result_dict[property_name] = property_value \n
\n
##############\n
# XXX Custom slapos code\n
##############\n
if is_site_root:\n
# Global action users for the jIO plugin\n
# XXX Would be better to not hardcode them but put them as portal type\n
# "actions" (search could be on portal_catalog document, traverse on all\n
# documents, newContent on all, etc)\n
# result_dict[\'_links\'][\'object_search\'] = {\n
# \'href\': \'%s/ERP5Site_viewSearchForm?portal_skin=Hal\' % absolute_url,\n
# \'name\': \'Global Search\'\n
# }\n
result_dict[\'_links\'][\'raw_search\'] = {\n
"href": url_template_dict["search_template"] % {\n
"root_url": site_root.absolute_url(),\n
"script_id": script.id\n
},\n
\'name\': \'Raw Search\',\n
\'templated\': True\n
}\n
result_dict[\'_links\'][\'traverse\'] = {\n
"href": url_template_dict["traverse_template"] % {\n
"root_url": site_root.absolute_url(),\n
"script_id": script.id\n
},\n
\'name\': \'Traverse\',\n
\'templated\': True\n
}\n
action_dict[\'add\'] = {\n
"href": url_template_dict["new_content_action"] % {\n
"root_url": site_root.absolute_url(),\n
"script_id": script.id\n
},\n
\'method\': \'POST\',\n
\'name\': \'New Content\',\n
}\n
\n
# Handle also other kind of users: instance, computer, master\n
person = portal.ERP5Site_getAuthenticatedMemberPersonValue()\n
if person is not None:\n
result_dict[\'_links\'][\'me\'] = {\n
"href": default_document_uri_template % {\n
"root_url": site_root.absolute_url(),\n
"relative_url": person.getRelativeUrl(), \n
"script_id": script.id\n
},\n
# \'_relative_url\': person.getRelativeUrl()\n
}\n
\n
query = sql_catalog.buildQuery({\n
"portal_type": "Software Product",\n
"validation_state": \'published\'\n
}).asSearchTextExpression(sql_catalog)\n
http_query = make_query({\n
"mode": "search",\n
"query": query\n
})\n
result_dict[\'_links\'][\'slapos_jump\'] = {\n
"href": "%s/%s?%s" % (site_root.absolute_url(), script.id, http_query),\n
\'_query\': query,\n
\'name\': \'public_software_product\'\n
}\n
\n
else:\n
traversed_document_portal_type = traversed_document.getPortalType()\n
if traversed_document_portal_type == "Person":\n
query = sql_catalog.buildQuery({\n
"portal_type": "Hosting Subscription",\n
"default_destination_section_uid": traversed_document.getUid(),\n
"validation_state": \'validated\'\n
}).asSearchTextExpression(sql_catalog)\n
http_query = make_query({\n
"mode": "search",\n
"query": query\n
})\n
result_dict[\'_links\'][\'slapos_jump\'] = [{\n
"href": "%s/%s?%s" % (site_root.absolute_url(), script.id, http_query),\n
\'name\': \'current_hosting_subscription\',\n
\'_query\': query\n
}]\n
\n
# List of validated computers\n
query = sql_catalog.buildQuery({\n
"portal_type": "Computer",\n
"local_roles": "Assignee",\n
"default_strict_allocation_scope_uid": "!=%s" % traversed_document.getPortalObject().portal_categories.allocation_scope.close.forever.getUid(),\n
"validation_state": \'validated\'\n
}).asSearchTextExpression(sql_catalog)\n
http_query = make_query({\n
"mode": "search",\n
"query": query\n
})\n
result_dict[\'_links\'][\'slapos_jump\'].append({\n
"href": "%s/%s?%s" % (site_root.absolute_url(), script.id, http_query),\n
\'name\': \'current_computer\',\n
\'_query\': query\n
})\n
\n
# List of networks\n
query = sql_catalog.buildQuery({\n
"portal_type": "Computer Network",\n
"local_roles": "Assignee"\n
}).asSearchTextExpression(sql_catalog)\n
http_query = make_query({\n
"mode": "search",\n
"query": query\n
})\n
result_dict[\'_links\'][\'slapos_jump\'].append({\n
"href": "%s/%s?%s" % (site_root.absolute_url(), script.id, http_query),\n
\'name\': \'current_network\',\n
\'_query\': query\n
})\n
\n
# List of invoices\n
query = sql_catalog.buildQuery({\n
"portal_type": "Sale Invoice Transaction",\n
"default_destination_section_uid": traversed_document.getUid(),\n
"query": NegatedQuery(Query(title="Reversal Transaction for %")),\n
}).asSearchTextExpression(sql_catalog)\n
http_query = make_query({\n
"mode": "search",\n
"query": query\n
})\n
result_dict[\'_links\'][\'slapos_jump\'].append({\n
"href": "%s/%s?%s" % (site_root.absolute_url(), script.id, http_query),\n
\'name\': \'current_invoice\',\n
\'_query\': query\n
})\n
\n
# List of tickets\n
query = sql_catalog.buildQuery({\n
"portal_type": ["Support Request", "Regularisation Request"],\n
"default_destination_decision_uid": traversed_document.getUid(),\n
}).asSearchTextExpression(sql_catalog)\n
http_query = make_query({\n
"mode": "search",\n
"query": query\n
})\n
result_dict[\'_links\'][\'slapos_jump\'].append({\n
"href": "%s/%s?%s" % (site_root.absolute_url(), script.id, http_query),\n
\'name\': \'current_ticket\',\n
\'_query\': query\n
})\n
\n
action_dict[\'request\'] = {\n
\'href\': "%s/Person_requestInstanceFromJio" % traversed_document.absolute_url(),\n
\'method\': \'POST\'\n
}\n
action_dict[\'request_computer\'] = {\n
\'href\': "%s/Person_requestComputerFromJio" % traversed_document.absolute_url(),\n
\'method\': \'POST\'\n
}\n
action_dict[\'request_computer_network\'] = {\n
\'href\': "%s/Person_requestComputerNetworkFromJio" % traversed_document.absolute_url(),\n
\'method\': \'POST\'\n
}\n
action_dict[\'request_ticket\'] = {\n
\'href\': "%s/Person_requestTicketFromJio" % traversed_document.absolute_url(),\n
\'method\': \'POST\'\n
}\n
\n
elif traversed_document_portal_type == "Hosting Subscription":\n
# Link to all ongoing Hosting Subscriptions\n
query = sql_catalog.buildQuery({\n
"portal_type": ["Software Instance", "Slave Instance"],\n
"default_specialise_uid": traversed_document.getUid(),\n
"validation_state": \'validated\'\n
}).asSearchTextExpression(sql_catalog)\n
http_query = make_query({\n
"mode": "search",\n
"query": query\n
})\n
result_dict[\'_links\'][\'slapos_jump\'] = {\n
"href": "%s/%s?%s" % (site_root.absolute_url(), script.id, http_query),\n
\'name\': \'related_instance\',\n
\'_query\': query\n
}\n
\n
# Actions to modify the hosting subscription\n
action_dict[\'start\'] = {\n
\'href\': "%s/HostingSubscription_changeRequestedStateFromJio?action=started" % traversed_document.absolute_url(),\n
\'method\': \'POST\'\n
}\n
action_dict[\'stop\'] = {\n
\'href\': "%s/HostingSubscription_changeRequestedStateFromJio?action=stopped" % traversed_document.absolute_url(),\n
\'method\': \'POST\'\n
}\n
action_dict[\'destroy\'] = {\n
\'href\': "%s/HostingSubscription_changeRequestedStateFromJio?action=destroyed" % traversed_document.absolute_url(),\n
\'method\': \'POST\'\n
}\n
\n
elif traversed_document_portal_type == "Software Installation":\n
action_dict[\'destroy\'] = {\n
\'href\': "%s/SoftwareInstallation_destroyFromJio" % traversed_document.absolute_url(),\n
\'method\': \'POST\'\n
}\n
\n
elif traversed_document_portal_type == "Software Product":\n
# Link to all Software Releases\n
query = sql_catalog.buildQuery({\n
"portal_type": "Software Release",\n
"default_aggregate_uid": traversed_document.getUid(),\n
"validation_state": ["shared", "shared_alive", "released", "released_alive", "published", "published_alive"]\n
}).asSearchTextExpression(sql_catalog)\n
http_query = make_query({\n
"mode": "search",\n
"query": query\n
})\n
result_dict[\'_links\'][\'slapos_jump\'] = {\n
"href": "%s/%s?%s" % (site_root.absolute_url(), script.id, http_query),\n
\'name\': \'related_software_release\',\n
\'_query\': query\n
}\n
\n
elif traversed_document_portal_type == "Computer":\n
# Link to related Software Installation\n
query = sql_catalog.buildQuery({\n
"portal_type": "Software Installation",\n
"default_aggregate_uid": traversed_document.getUid(),\n
"validation_state": "validated"\n
}).asSearchTextExpression(sql_catalog)\n
http_query = make_query({\n
"mode": "search",\n
"query": query\n
})\n
result_dict[\'_links\'][\'slapos_jump\'] = {\n
"href": "%s/%s?%s" % (site_root.absolute_url(), script.id, http_query),\n
\'name\': \'related_software_installation\',\n
\'_query\': query\n
}\n
\n
action_dict[\'update_allocation_scope\'] = {\n
\'href\': "%s/Computer_updateAllocationScopeFromJio" % traversed_document.absolute_url(),\n
\'method\': \'POST\'\n
}\n
action_dict[\'generate_certificate\'] = {\n
\'href\': "%s/Computer_requestNewComputerCertificateFromJio" % traversed_document.absolute_url(),\n
\'method\': \'POST\'\n
}\n
action_dict[\'revoke_certificate\'] = {\n
\'href\': "%s/Computer_revokeComputerCertificateFromJio" % traversed_document.absolute_url(),\n
\'method\': \'POST\'\n
}\n
action_dict[\'request_installation\'] = {\n
\'href\': "%s/Computer_requestInstallationFromJio" % traversed_document.absolute_url(),\n
\'method\': \'POST\'\n
}\n
\n
elif traversed_document_portal_type == "Sale Invoice Transaction":\n
result_dict[\'_links\'][\'slapos_jump\'] = {\n
"href": "%s/SaleInvoiceTransaction_viewSlapOSPrintout" % traversed_document.absolute_url(),\n
\'name\': \'current_printout\',\n
}\n
\n
elif traversed_document_portal_type in ["Support Request", "Regularisation Request"]:\n
# Link to all Events\n
query = sql_catalog.buildQuery({\n
"default_follow_up_uid": traversed_document.getUid(),\n
}).asSearchTextExpression(sql_catalog)\n
http_query = make_query({\n
"mode": "search",\n
"query": query\n
})\n
result_dict[\'_links\'][\'slapos_jump\'] = {\n
"href": "%s/%s?%s" % (site_root.absolute_url(), script.id, http_query),\n
\'name\': \'related_event\',\n
\'_query\': query\n
}\n
\n
action_dict[\'update\'] = {\n
\'href\': "%s/Ticket_updateFromJio" % traversed_document.absolute_url(),\n
\'method\': \'POST\'\n
}\n
\n
elif traversed_document_portal_type == "ERP5 Form":\n
renderFormDefinition(traversed_document, result_dict)\n
\n
# Define document action\n
if action_dict:\n
result_dict[\'_actions\'] = action_dict\n
\n
\n
elif mode == \'search\':\n
#################################################\n
# Portal catalog search\n
#################################################\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
\n
if query == "__root__":\n
# XXX Hardcoded behaviour to get root object with jIO\n
sql_list = [site_root]\n
\n
elif query == "__portal__":\n
# XXX Hardcoded behaviour to get portal object with jIO\n
sql_list = [portal]\n
\n
# document = site_root\n
# document_result = {\n
# # \'_relative_url\': site_root.getRelativeUrl(),\n
# \'_links\': {\n
# \'self\': {\n
# "href": default_document_uri_template % {\n
# "root_url": site_root.absolute_url(),\n
# "relative_url": document.getRelativeUrl(), \n
# "script_id": script.id\n
# },\n
# },\n
# }\n
# }\n
# for select in select_list:\n
# document_result[select] = document.getProperty(select, d=None)\n
# result_dict[\'_embedded\'] = {"contents": [document_result]}\n
else:\n
# raise NotImplementedError("Unsupported query: %s" % query)\n
\n
\n
# # XXX\n
# length = len(\'/%s/\' % portal.getId())\n
# # context.log(portal.portal_catalog(full_text=query, limit=limit, src__=1))\n
# context.log(query)\n
if query:\n
sql_list = portal.portal_catalog(full_text=query, limit=limit)\n
else:\n
sql_list = portal.portal_catalog(limit=limit)\n
\n
result_list = []\n
\n
# if (select_list is None):\n
# # Only include links\n
# for sql_document in sql_list:\n
# document = sql_document.getObject()\n
# result_list.append({\n
# "href": default_document_uri_template % {\n
# "root_url": site_root.absolute_url(),\n
# "relative_url": document.getRelativeUrl(), \n
# "script_id": script.id\n
# },\n
# })\n
# result_dict[\'_links\'][\'contents\'] = result_list\n
# \n
# else:\n
\n
# Cast to list if only one element is provided\n
if same_type(select_list, ""):\n
select_list = [select_list]\n
\n
for sql_document in sql_list:\n
try:\n
document = sql_document.getObject()\n
except AttributeError:\n
# XXX ERP5 Site is not an ERP5 document\n
document = sql_document\n
document_result = {\n
# \'_relative_url\': sql_document.path[length:],\n
\'_links\': {\n
\'self\': {\n
"href": default_document_uri_template % {\n
"root_url": site_root.absolute_url(),\n
# XXX ERP5 Site is not an ERP5 document\n
"relative_url": document.getRelativeUrl() or document.getId(), \n
"script_id": script.id\n
},\n
},\n
}\n
}\n
for select in select_list:\n
property_value = document.getProperty(select, d=None)\n
if property_value is not None:\n
document_result[select] = property_value\n
result_list.append(document_result)\n
result_dict[\'_embedded\'] = {"contents": result_list}\n
\n
result_dict[\'_query\'] = query\n
result_dict[\'_limit\'] = limit\n
result_dict[\'_select_list\'] = select_list\n
\n
\n
elif mode == \'newContent\':\n
#################################################\n
# Create new document\n
#################################################\n
if REQUEST.other[\'method\'] != "POST":\n
response.setStatus(405)\n
return ""\n
portal_type = REQUEST.form["portal_type"]\n
module = portal.getDefaultModule(portal_type=portal_type)\n
document = module.newContent(\n
portal_type=portal_type\n
)\n
# http://en.wikipedia.org/wiki/Post/Redirect/Get\n
response.setStatus(201)\n
response.setHeader("X-Location",\n
default_document_uri_template % {\n
"root_url": site_root.absolute_url(),\n
"relative_url": document.getRelativeUrl(),\n
"script_id": script.id\n
})\n
return \'\'\n
\n
elif mode == \'form\':\n
#################################################\n
# Calculate form value\n
#################################################\n
if REQUEST.other[\'method\'] != "GET":\n
response.setStatus(405)\n
return ""\n
\n
renderForm(form, result_dict)\n
\n
\n
# elif mode == \'form_definition\':\n
# #################################################\n
# # Get raw form definitions\n
# #################################################\n
# if REQUEST.other[\'method\'] != "GET":\n
# response.setStatus(405)\n
# return ""\n
# \n
# form = getattr(portal, skin_id)\n
# renderFormDefinition(form, result_dict)\n
\n
else:\n
raise NotImplementedError, "Unsupported mode %s" % mode\n
\n
response.setHeader(\'Content-Type\', mime_type)\n
return json.dumps(result_dict, indent=2)\n
]]></string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=None, form=None, relative_url=None</string> </value> <value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=None, form=None, relative_url=None</string> </value>
......
if REQUEST.other['method'] != "POST":
response.setStatus(405)
return ""
if action not in ("started", "stopped", "destroyed"):
raise NotImplementedError, "Unknown action %s" % action
person = context.getDestinationSectionValue()
person.requestSoftwareInstance(
state=action,
software_release=context.getUrlString(),
software_title=context.getTitle(),
software_type=context.getSourceReference(),
instance_xml=context.getTextContent(),
sla_xml=context.getSlaXml(),
shared=context.isRootSlave()
)
context.Base_redirect()
...@@ -48,29 +48,6 @@ ...@@ -48,29 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>if REQUEST.other[\'method\'] != "POST":\n
response.setStatus(405)\n
return ""\n
\n
if action not in ("started", "stopped", "destroyed"):\n
raise NotImplementedError, "Unknown action %s" % action\n
\n
person = context.getDestinationSectionValue()\n
person.requestSoftwareInstance(\n
state=action,\n
software_release=context.getUrlString(),\n
software_title=context.getTitle(),\n
software_type=context.getSourceReference(),\n
instance_xml=context.getTextContent(),\n
sla_xml=context.getSlaXml(),\n
shared=context.isRootSlave()\n
)\n
\n
context.Base_redirect()\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>action, REQUEST=None</string> </value> <value> <string>action, REQUEST=None</string> </value>
......
if REQUEST.other['method'] != "POST":
response.setStatus(405)
return ""
person = context
person.requestComputer(computer_title=computer_title)
return context.getPortalObject().restrictedTraverse(context.REQUEST.get('computer')).Base_redirect()
...@@ -48,18 +48,6 @@ ...@@ -48,18 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>if REQUEST.other[\'method\'] != "POST":\n
response.setStatus(405)\n
return ""\n
\n
person = context\n
\n
person.requestComputer(computer_title=computer_title)\n
return context.getPortalObject().restrictedTraverse(context.REQUEST.get(\'computer\')).Base_redirect()\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>computer_title, REQUEST=None</string> </value> <value> <string>computer_title, REQUEST=None</string> </value>
......
if REQUEST.other['method'] != "POST":
response.setStatus(405)
return ""
portal = context.getPortalObject()
network_portal_type = "Computer Network"
reference = "NET-%s" % portal.portal_ids.generateNewId(
id_group='slap_network_reference',
id_generator='uid')
module = portal.getDefaultModule(portal_type=network_portal_type)
network = module.newContent(
portal_type=network_portal_type,
title=title,
reference=reference,
source_administration=context.getRelativeUrl()
)
network.Base_redirect()
network.validate()
...@@ -48,33 +48,6 @@ ...@@ -48,33 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>if REQUEST.other[\'method\'] != "POST":\n
response.setStatus(405)\n
return ""\n
\n
portal = context.getPortalObject()\n
\n
network_portal_type = "Computer Network"\n
\n
reference = "NET-%s" % portal.portal_ids.generateNewId(\n
id_group=\'slap_network_reference\',\n
id_generator=\'uid\')\n
\n
module = portal.getDefaultModule(portal_type=network_portal_type)\n
network = module.newContent(\n
portal_type=network_portal_type,\n
title=title,\n
reference=reference,\n
source_administration=context.getRelativeUrl()\n
)\n
\n
\n
network.Base_redirect()\n
network.validate()\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>title, REQUEST=None</string> </value> <value> <string>title, REQUEST=None</string> </value>
......
if REQUEST.other['method'] != "POST":
response.setStatus(405)
return ""
person = context
person.requestSoftwareInstance(
state=state,
software_release=software_release,
software_title=software_title,
software_type=software_type,
instance_xml=instance_xml,
sla_xml=sla_xml,
shared=int(shared)
)
return context.REQUEST.get('request_hosting_subscription').Base_redirect()
...@@ -48,26 +48,6 @@ ...@@ -48,26 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>if REQUEST.other[\'method\'] != "POST":\n
response.setStatus(405)\n
return ""\n
\n
person = context\n
person.requestSoftwareInstance(\n
state=state,\n
software_release=software_release,\n
software_title=software_title,\n
software_type=software_type,\n
instance_xml=instance_xml,\n
sla_xml=sla_xml,\n
shared=int(shared)\n
)\n
\n
return context.REQUEST.get(\'request_hosting_subscription\').Base_redirect()\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>state, software_release, software_title, software_type, instance_xml, sla_xml, shared, REQUEST=None</string> </value> <value> <string>state, software_release, software_title, software_type, instance_xml, sla_xml, shared, REQUEST=None</string> </value>
......
if REQUEST.other['method'] != "POST":
response.setStatus(405)
return ""
person = context
portal = person.getPortalObject()
support_request_template = portal.restrictedTraverse(
portal.portal_preferences.getPreferredSupportRequestTemplate())
support_request = support_request_template.Base_createCloneDocument(batch_mode=1)
support_request.edit(
title=title,
destination_decision_value=person,
resource=resource,
start_date=DateTime(),
)
support_request.validate(comment="Submitted from the web site contact form")
web_message_template = portal.restrictedTraverse(
portal.portal_preferences.getPreferredWebMessageTemplate())
web_message = web_message_template.Base_createCloneDocument(batch_mode=1)
# XXX init script is not called when cloning?
web_message.Event_init()
web_message.edit(
title=title,
content_type="text/plain",
text_content=description,
source_value=person,
resource=resource,
start_date=DateTime(),
follow_up_value=support_request,
)
web_message.stop(comment="Submitted from the web site contact form")
return support_request.Base_redirect()
...@@ -48,46 +48,6 @@ ...@@ -48,46 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>if REQUEST.other[\'method\'] != "POST":\n
response.setStatus(405)\n
return ""\n
\n
person = context\n
portal = person.getPortalObject()\n
\n
support_request_template = portal.restrictedTraverse(\n
portal.portal_preferences.getPreferredSupportRequestTemplate())\n
support_request = support_request_template.Base_createCloneDocument(batch_mode=1)\n
\n
support_request.edit(\n
title=title,\n
destination_decision_value=person,\n
resource=resource,\n
start_date=DateTime(),\n
)\n
support_request.validate(comment="Submitted from the web site contact form")\n
\n
web_message_template = portal.restrictedTraverse(\n
portal.portal_preferences.getPreferredWebMessageTemplate())\n
web_message = web_message_template.Base_createCloneDocument(batch_mode=1)\n
# XXX init script is not called when cloning?\n
web_message.Event_init()\n
web_message.edit(\n
title=title,\n
content_type="text/plain",\n
text_content=description,\n
source_value=person,\n
resource=resource,\n
start_date=DateTime(),\n
follow_up_value=support_request,\n
)\n
web_message.stop(comment="Submitted from the web site contact form")\n
\n
return support_request.Base_redirect()\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>title, resource, description, REQUEST=None</string> </value> <value> <string>title, resource, description, REQUEST=None</string> </value>
......
if REQUEST.other['method'] != "POST":
response.setStatus(405)
return ""
context.getAggregateValue(portal_type='Computer').requestSoftwareRelease(software_release_url=context.getUrlString(), state='destroyed')
return ""
...@@ -48,17 +48,6 @@ ...@@ -48,17 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>if REQUEST.other[\'method\'] != "POST":\n
response.setStatus(405)\n
return ""\n
\n
context.getAggregateValue(portal_type=\'Computer\').requestSoftwareRelease(software_release_url=context.getUrlString(), state=\'destroyed\')\n
\n
return ""\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None</string> </value> <value> <string>REQUEST=None</string> </value>
......
if REQUEST.other['method'] != "POST":
response.setStatus(405)
return ""
ticket = context
portal = ticket.getPortalObject()
person = ticket.getDestinationDecisionValue()
web_message_template = portal.restrictedTraverse(
portal.portal_preferences.getPreferredWebMessageTemplate())
web_message = web_message_template.Base_createCloneDocument(batch_mode=1)
# XXX init script is not called when cloning?
web_message.Event_init()
web_message.edit(
title="Re: %s" % context.getTitle(),
content_type="text/plain",
text_content=description,
source_value=person,
resource=ticket.getResource(),
start_date=DateTime(),
follow_up_value=ticket,
)
web_message.stop(comment="Submitted from the web site contact form")
if portal.portal_workflow.isTransitionPossible(context, "validate"):
context.validate(comment="See %s" % web_message.getRelativeUrl())
return ""
...@@ -48,37 +48,6 @@ ...@@ -48,37 +48,6 @@
</object> </object>
</value> </value>
</item> </item>
<item>
<key> <string>_body</string> </key>
<value> <string>if REQUEST.other[\'method\'] != "POST":\n
response.setStatus(405)\n
return ""\n
\n
ticket = context\n
portal = ticket.getPortalObject()\n
person = ticket.getDestinationDecisionValue()\n
\n
web_message_template = portal.restrictedTraverse(\n
portal.portal_preferences.getPreferredWebMessageTemplate())\n
web_message = web_message_template.Base_createCloneDocument(batch_mode=1)\n
# XXX init script is not called when cloning?\n
web_message.Event_init()\n
web_message.edit(\n
title="Re: %s" % context.getTitle(),\n
content_type="text/plain",\n
text_content=description,\n
source_value=person,\n
resource=ticket.getResource(),\n
start_date=DateTime(),\n
follow_up_value=ticket,\n
)\n
web_message.stop(comment="Submitted from the web site contact form")\n
if portal.portal_workflow.isTransitionPossible(context, "validate"):\n
context.validate(comment="See %s" % web_message.getRelativeUrl())\n
\n
return ""\n
</string> </value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>description, REQUEST=None</string> </value> <value> <string>description, REQUEST=None</string> </value>
......
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