Commit 7fe0677c authored by Jondy Zhao's avatar Jondy Zhao Committed by Marco Mariani

New feature: get net drive usage report from slave node.

parent f932e38f
......@@ -699,6 +699,64 @@ class SlapTool(BaseTool):
self.REQUEST.response.setBody(result)
return self.REQUEST.response
security.declareProtected(Permissions.AccessContentsInformation,
'reportNetDriveUsageFromXML')
def reportNetDriveUsageFromXML(self, xml):
"Generate sale packing list from net drive usage report"
#We retrieve XSD model
try:
netdrive_usage_model = \
pkg_resources.resource_string(
'slapos.slap',
'doc/netdrive_usage.xsd')
except IOError:
netdrive_usage_model = \
pkg_resources.resource_string(
__name__,
'../../../../slapos/slap/doc/netdrive_usage.xsd')
if not self._validateXML(xml, netdrive_usage_model):
raise NotImplementedError('XML file sent by the node is not valid !')
splm = self.getPortalObject().getDefaultModule('Sale Packing List')
computer_id = ''
# Insert one line
root = etree.XML(xml)
for element in root.iter('item'):
if not computer_id == element[0].text:
computer_id = element[0].text
computer = self._getComputerDocument(computer_id)
domain_account = element[1].text
report_date = element[2].text
usage_amount = element[3].text
# Search sale packing list by domain_account and the month of report_date
year, month, day = report_date.split('-')
reference="NetDriveUsage-%s-%d.%d" % (domain_account, year, month)
spl = splm.searchFolder(reference=reference)
if spl is None:
spl = splm.newContent( portal_type='Sale Packing List',
title='Net Drive Usage - %s' % domain_account,
reference=reference,
source_value = 'Net Drive',
destination_value = domain_account,
start_date=DateTime(year, month, 1),
)
spl.newContent( portal_type='Sale Packing List Line',
resource_value=sequence.get('resource'),
delivery_date=report_date,
resource_value=computer_id,
quantity=usage_amount)
# step through all steps of packing list workflow
# spl.confirm()
# spl.setReady()
# spl.start()
# spl.stop()
# spl.deliver()
return 'Content properly posted.'
####################################################
# Internal methods
####################################################
......
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="report">
<xs:complexType>
<xs:sequence>
<xs:element ref="item" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="item">
<xs:complexType>
<xs:sequence>
<xs:element name="computer" type="xs:string"/>
<xs:element name="account" type="xs:string"/>
<xs:element name="date" type="xs:date"/>
<xs:element name="usage" type="xs:decimal"/>
<xs:element ref="details"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="details">
<xs:complexType>
<xs:element ref="line" minOccurs="0" maxOccurs="unbounded"/>
</xs:complexType>
</xs:element>
<xs:element name="line">
<xs:complexType>
<xs:all>
<xs:element name="drive" type="xs:string"/>
<xs:element name="remote" type="xs:string"/>
<xs:element name="start" type="xs:time"/>
<xs:element name="duration" type="xs:integer"/>
<xs:element name="bytes" type="xs:integer"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
......@@ -345,6 +345,10 @@ class Computer(SlapDocument):
'computer_id': self._computer_id})
return xml_marshaller.loads(xml)
def reportNetDriveUsage(self, xml):
self._connection_helper.POST(
'/reportNetDriveUsageFromXML', { 'xml' : xml })
return self._connection_helper.response.read()
def parsed_error_message(status, body, path):
m = re.search('(Error Value:\n.*)', body, re.MULTILINE)
......
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