Fix (de-)serialization

This commit is contained in:
Anders Ingemann 2014-11-24 23:43:17 +01:00
parent 2b33561b82
commit 3542406b91
5 changed files with 46 additions and 15 deletions

View file

@ -90,6 +90,9 @@ class BootstrapInformation(object):
def __delattr__(self, name):
del self[name]
def __getstate__(self):
return self.__dict__
def set_manifest_vars(obj, data):
"""Runs through the manifest and creates DictClasses for every key
@ -124,3 +127,15 @@ class BootstrapInformation(object):
# They are added last so that they may override previous variables
set_manifest_vars(manifest_vars, additional_vars)
return manifest_vars
def __getstate__(self):
state = self.__dict__.copy()
exclude_keys = ['volume', 'source_lists', 'preference_lists', 'packages']
for key in exclude_keys:
del state[key]
state['__class__'] = 'bootstrapvz.base.bootstrapinfo.BootstrapInformation'
return state
def __setstate__(self, state):
for key in state:
self.__dict__[key] = state[key]

View file

@ -133,5 +133,6 @@ class Manifest(object):
raise ManifestError(message, self.path, data_path)
def __getstate__(self):
return {'path': self.path,
return {'__class__': 'bootstrapvz.base.manifest.Manifest',
'path': self.path,
'data': self.data}

View file

@ -1,15 +1,7 @@
import Pyro4
from threading import Thread
"""Remote module containing methods to bootstrap remotely
"""
import logging
log = logging.getLogger(__name__)
stop = False
def main():
"""Main function for invoking the bootstrap process remotely
"""
@ -27,6 +19,10 @@ def main():
from bootstrapvz.base.main import setup_loggers
setup_loggers(opts)
register_deserialization_handlers()
bootstrap_info = None
from ssh_rpc_manager import SSHRPCManager
manager = SSHRPCManager(build_servers[opts['SERVER']])
try:
@ -41,14 +37,15 @@ def main():
server.set_log_server(log_server)
# Everything has been set up, begin the bootstrapping process
server.run(manifest,
debug=opts['--debug'],
pause_on_error=False,
dry_run=opts['--dry-run'])
bootstrap_info = server.run(manifest,
debug=opts['--debug'],
pause_on_error=False,
dry_run=opts['--dry-run'])
finally:
callback_server.stop()
finally:
manager.stop()
return bootstrap_info
def get_opts():
@ -69,3 +66,21 @@ Options:
-h, --help show this help
"""
return docopt(usage)
def register_deserialization_handlers():
from Pyro4.util import SerializerBase
SerializerBase.register_dict_to_class('bootstrapvz.base.manifest.Manifest', deserialize_manifest)
SerializerBase.register_dict_to_class('bootstrapvz.base.bootstrapinfo.BootstrapInformation', deserialize_bootstrapinfo)
def deserialize_manifest(classname, state):
from bootstrapvz.base.manifest import Manifest
return Manifest(path=state['path'], data=state['data'])
def deserialize_bootstrapinfo(classname, state):
from bootstrapvz.base.bootstrapinfo import BootstrapInformation
bootstrap_info = BootstrapInformation.__new__(BootstrapInformation)
bootstrap_info.__setstate__(state)
return bootstrap_info

View file

@ -2,6 +2,8 @@
def main():
opts = getopts()
from . import register_deserialization_handlers
register_deserialization_handlers()
log_forwarder = setup_logging()
serve(opts, log_forwarder)

View file

@ -21,8 +21,6 @@ class TaskList(object):
:param dict info: The bootstrap information object
:param bool dry_run: Whether to actually run the tasks or simply step through them
"""
logging.getLogger(__name__).debug('test')
return
# Create a list for us to run
task_list = create_list(self.tasks)
# Output the tasklist