[slaptool] Add getComputerPartitionList and getComputerPartitionInformation methods.

parent 40bc7f38
......@@ -425,6 +425,82 @@ class SlapTool(BaseTool):
for software_release in software_release_list
if software_release.getValidationState() == 'published'])
security.declareProtected(Permissions.AccessContentsInformation,
'getComputerPartitionList')
def getComputerPartitionList(self):
"""
Return the list of requested instances.
Actually returns the list of Hosting Subscription owned by user.
"""
# XXX cache
# XXX software_instance.getComputerPartitionList support
from Products.ZSQLCatalog.SQLCatalog import NegatedQuery, Query
portal = context.getPortalObject()
person_uid = portal.ERP5Site_getPropertyFromAuthenticatedMemberPersonValue('uid')
hosting_subscription_list = portal.portal_catalog(
portal_type="Hosting Subscription",
default_destination_section_uid=person_uid,validation_state='validated'
)
# XXX Shouldn't we just return list of slapos.slap.Partition ?
hosting_subscription_list = [{
'partition_reference': hosting_subscription.getTitle(),
'software_release': hosting_subscription.getUrl(),
}]
return xml_marshaller.xml_marshaller.dumps(hosting_subscription_list)
security.declareProtected(Permissions.AccessContentsInformation,
'getComputerPartitionInformation')
def getComputerPartitionInformation(self, partition_reference):
"""
Returns XML representation of corresponding partition with HTTP code 200 OK.
"""
# requested as root, so done by human
person = portal.ERP5Site_getAuthenticatedMemberPersonValue()
key = '_'.join([person.getRelativeUrl(), partition_reference])
value = dict(
hash=str(kw)
)
last_data = self._getLastData(key)
if last_data is not None and type(last_data) == type({}):
requested_software_instance = portal.restrictedTraverse(
last_data.get('request_instance'), None)
if last_data is None or type(last_data) != type(value) or \
last_data.get('hash') != value['hash'] or \
requested_software_instance is None:
person.requestSoftwareInstance(**kw)
requested_software_instance = self.REQUEST.get('request_instance')
if requested_software_instance is not None:
value['request_instance'] = requested_software_instance\
.getRelativeUrl()
self._storeLastData(key, value)
if requested_software_instance is None:
raise SoftwareInstanceNotReady
else:
if not requested_software_instance.getAggregate(portal_type="Computer Partition"):
raise SoftwareInstanceNotReady
else:
parameter_dict = self._getSoftwareInstanceAsParameterDict(requested_software_instance)
# software instance has to define an xml parameter
xml = self._instanceXmlToDict(
parameter_dict.pop('xml'))
connection_xml = self._instanceXmlToDict(
parameter_dict.pop('connection_xml'))
filter_xml = self._instanceXmlToDict(
parameter_dict.pop('filter_xml'))
instance_guid = parameter_dict.pop('instance_guid')
software_instance = SoftwareInstance(**parameter_dict)
software_instance._parameter_dict = xml
software_instance._connection_dict = connection_xml
software_instance._filter_dict = filter_xml
software_instance._requested_state = state
software_instance._instance_guid = instance_guid
return xml_marshaller.xml_marshaller.dumps(software_instance)
####################################################
# Public POST methods
......
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