Resilient pbs recipe: rewrite.

Completely rewrite the wrappers generation so that one is able to understand it...
... without spending hours.
parent ee2aec8d
...@@ -86,12 +86,14 @@ class Recipe(GenericSlapRecipe, Notify, Callback): ...@@ -86,12 +86,14 @@ class Recipe(GenericSlapRecipe, Notify, Callback):
url = entry.get('url') url = entry.get('url')
if not url: if not url:
raise ValueError('Missing URL parameter for PBS recipe') raise ValueError('Missing URL parameter for PBS recipe')
parsed_url = urlparse.urlparse(url)
slave_id = entry['notification-id'] slave_id = entry['notification-id']
slave_type = entry['type']
if not slave_type in ['pull', 'push']:
raise ValueError('type parameter must be either pull or push.')
promise_path = os.path.join(self.options['promises-directory'], promise_path = os.path.join(self.options['promises-directory'], slave_id)
slave_id)
parsed_url = urlparse.urlparse(url)
promise_dict = self.promise_base_dict.copy() promise_dict = self.promise_base_dict.copy()
promise_dict.update(user=parsed_url.username, promise_dict.update(user=parsed_url.username,
host=parsed_url.hostname, host=parsed_url.hostname,
...@@ -104,65 +106,57 @@ class Recipe(GenericSlapRecipe, Notify, Callback): ...@@ -104,65 +106,57 @@ class Recipe(GenericSlapRecipe, Notify, Callback):
host = parsed_url.hostname host = parsed_url.hostname
known_hosts_file[host] = entry['server-key'] known_hosts_file[host] = entry['server-key']
notifier_path = os.path.join(self.options['wrappers-directory'], slave_id)
rdiff_path = notifier_path + '_raw'
# Create the rdiff-backup wrapper
# It is useful to separate it from the notifier so that we can run it
# Manually.
rdiff_parameter_list = []
# XXX use -y because the host might not yet be in the # XXX use -y because the host might not yet be in the
# trusted hosts file until the next time slapgrid is run. # trusted hosts file until the next time slapgrid is run.
remote_schema = '%(ssh)s -y -p %%s %(user)s@%(host)s' % \ rdiff_parameter_list.extend([
{ '--remote-schema', '%(ssh)s -y -p %%s %(user)s@%(host)s' % {
'ssh': self.options['sshclient-binary'], 'ssh': self.options['sshclient-binary'],
'user': parsed_url.username, 'user': parsed_url.username,
'host': parsed_url.hostname, 'host': parsed_url.hostname,
} }])
if slave_type == 'push':
parameters = ['--remote-schema', remote_schema] rdiff_parameter_list.extend(['--restore-as-of', 'now', '--force'])
comments = ['','Push data to a PBS *-import instance.', '']
elif slave_type == 'pull':
comments = ['','Pull data from a PBS *-export instance.', '']
remote_directory = '%(port)s::%(path)s' % {'port': parsed_url.port, remote_directory = '%(port)s::%(path)s' % {'port': parsed_url.port,
'path': parsed_url.path} 'path': parsed_url.path}
local_directory = self.createDirectory(self.options['directory'], entry['name']) local_directory = self.createDirectory(self.options['directory'], entry['name'])
rdiff_parameter_list.extend([local_directory, remote_directory])
if entry['type'] == 'push': rdiff_wrapper = self.createWrapper(
parameters.extend(['--restore-as-of', 'now']) name=rdiff_path,
parameters.append('--force') command=self.options['rdiffbackup-binary'],
parameters.extend([local_directory, remote_directory]) parameters=rdiff_parameter_list,
comments = ['','Push data to a PBS *-import instance.',''] comments=comments,
else: )
parameters.extend([remote_directory, local_directory]) path_list.append(rdiff_wrapper)
comments = ['','Pull data from a PBS *-export instance.','']
# Create notifier wrapper
wrapper_basepath = os.path.join(self.options['wrappers-directory'], notifier_wrapper = self.createNotifier(
slave_id) notifier_binary=self.options['notifier-binary'],
wrapper=notifier_path,
if 'notify' in entry: executable=rdiff_wrapper,
wrapper_path = wrapper_basepath + '_raw' log=os.path.join(self.options['feeds'], entry['notification-id']),
else: title=entry.get('title', slave_id),
wrapper_path = wrapper_basepath notification_url=entry['notify'],
feed_url='%s/get/%s' % (self.options['notifier-url'], entry['notification-id']),
wrapper = self.createWrapper(name=wrapper_path, )
command=self.options['rdiffbackup-binary'], path_list.append(notifier_wrapper)
parameters=parameters,
comments = comments)
path_list.append(wrapper)
if 'notify' in entry:
feed_url = '%s/get/%s' % (self.options['notifier-url'],
entry['notification-id'])
wrapper = self.createNotifier(notifier_binary=self.options['notifier-binary'],
wrapper=wrapper_basepath,
executable=wrapper_path,
log=os.path.join(self.options['feeds'], entry['notification-id']),
title=entry.get('title', slave_id),
notification_url=entry['notify'],
feed_url=feed_url,
)
path_list.append(wrapper)
if 'on-notification' in entry: if 'on-notification' in entry:
path_list.append(self.createCallback(str(entry['on-notification']), path_list.append(self.createCallback(str(entry['on-notification']),
wrapper)) notifier_wrapper))
else: else:
cron_entry = os.path.join(self.options['cron-entries'], slave_id) cron_entry = os.path.join(self.options['cron-entries'], slave_id)
with open(cron_entry, 'w') as cron_entry_file: with open(cron_entry, 'w') as cron_entry_file:
cron_entry_file.write('%s %s' % (entry['frequency'], wrapper)) cron_entry_file.write('%s %s' % (entry['frequency'], notifier_wrapper))
path_list.append(cron_entry) path_list.append(cron_entry)
return path_list return path_list
......
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