Commit 16b5940f authored by Rafael Monnerat's avatar Rafael Monnerat Committed by Cédric de Saint Martin

Cache hack which dump GET xml into a file in order to share over buildout runs.

This is a quick hack to share cache between the buildout runs, it is
required remove /opt/slapos/cache and /tmp/cache_registerComputerPartition*
after every run otherwise informations will be not updated.

Do not use it or merge this change info master, this is just a hack.
parent 0843bf86
...@@ -33,6 +33,7 @@ __all__ = ["slap", "ComputerPartition", "Computer", "SoftwareRelease", ...@@ -33,6 +33,7 @@ __all__ = ["slap", "ComputerPartition", "Computer", "SoftwareRelease",
from interface import slap as interface from interface import slap as interface
from xml_marshaller import xml_marshaller from xml_marshaller import xml_marshaller
import httplib import httplib
import os
import socket import socket
import ssl import ssl
import urllib import urllib
...@@ -558,7 +559,13 @@ class ConnectionHelper: ...@@ -558,7 +559,13 @@ class ConnectionHelper:
return xml_marshaller.loads(self.response.read()) return xml_marshaller.loads(self.response.read())
def getFullComputerInformation(self, computer_id): def getFullComputerInformation(self, computer_id):
if os.path.exists("/opt/slapos/cache"):
return xml_marshaller.loads(open("/opt/slapos/cache", "r").read())
self.GET('/getFullComputerInformation?computer_id=%s' % computer_id) self.GET('/getFullComputerInformation?computer_id=%s' % computer_id)
if not os.path.exists("/opt/slapos/cache"):
cache = self.response.read()
open("/opt/slapos/cache", "w+").write(cache)
return xml_marshaller.loads(cache)
return xml_marshaller.loads(self.response.read()) return xml_marshaller.loads(self.response.read())
def connect(self): def connect(self):
...@@ -681,10 +688,18 @@ class slap: ...@@ -681,10 +688,18 @@ class slap:
Registers connected representation of computer partition and Registers connected representation of computer partition and
returns Computer Partition class object returns Computer Partition class object
""" """
self._connection_helper.GET('/registerComputerPartition?' \ cache_id = "/tmp/cache_registerComputerPartition%s%s" % (computer_guid, partition_id)
'computer_reference=%s&computer_partition_reference=%s' % ( if os.path.exists(cache_id):
computer_guid, partition_id)) cache = open(cache_id, "r").read()
result = xml_marshaller.loads(self._connection_helper.response.read()) else:
self._connection_helper.GET('/registerComputerPartition?' \
'computer_reference=%s&computer_partition_reference=%s' % (
computer_guid, partition_id))
if not os.path.exists(cache_id):
cache = self._connection_helper.response.read()
open(cache_id, "w+").write(cache)
result = xml_marshaller.loads(cache)
# XXX: dirty hack to make computer partition usable. xml_marshaller is too # XXX: dirty hack to make computer partition usable. xml_marshaller is too
# low-level for our needs here. # low-level for our needs here.
result._connection_helper = self._connection_helper result._connection_helper = self._connection_helper
......
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