Commit cc8a16fb authored by Antoine Catton's avatar Antoine Catton

Modify pbs recipe in order to support notifications

parent f275875f
...@@ -32,8 +32,10 @@ import subprocess ...@@ -32,8 +32,10 @@ import subprocess
import sys import sys
import time import time
from slapos.recipe.librecipe import GenericBaseRecipe from slapos.recipe.librecipe import GenericSlapRecipe
from slapos.recipe.dropbear import KnownHostsFile from slapos.recipe.dropbear import KnownHostsFile
from slapos.recipe.notifier import Notify
from slapos.recipe.notifier import Callback
from slapos import slap as slapmodule from slapos import slap as slapmodule
...@@ -67,7 +69,7 @@ def promise(args): ...@@ -67,7 +69,7 @@ def promise(args):
class Recipe(GenericBaseRecipe): class Recipe(GenericSlapRecipe, Notify, Callback):
def add_slave(self, entry, known_hosts_file): def add_slave(self, entry, known_hosts_file):
path_list = [] path_list = []
...@@ -119,13 +121,38 @@ class Recipe(GenericBaseRecipe): ...@@ -119,13 +121,38 @@ class Recipe(GenericBaseRecipe):
else: else:
command.extend([remote_directory, local_directory]) command.extend([remote_directory, local_directory])
wrapper_basepath = os.path.join(self.options['wrappers-directory'],
url_hash)
wrapper_path = wrapper_basepath
if 'notify' in entry:
wrapper_path = '%s_raw' % wrapper_basepath
wrapper = self.createPythonScript( wrapper = self.createPythonScript(
os.path.join(self.options['wrappers-directory'], url_hash), wrapper_path,
'slapos.recipe.librecipe.execute.execute', 'slapos.recipe.librecipe.execute.execute',
command [str(i) for i in command]
) )
path_list.append(wrapper) path_list.append(wrapper)
if 'notify' in entry:
feed_url = '%s/get/%s' % (self.options['notifier-url'],
entry['notification-id'])
wrapper = self.createNotifier(
self.options['notifier-binary'],
wrapper=wrapper_basepath,
executable=wrapper_path,
log=os.path.join(self.options['feeds'], entry['notification-id']),
title=entry['title'],
notification_url=entry['notify'],
feed_url=feed_url,
)
path_list.append(wrapper)
#self.setConnectionDict(dict(feed_url=feed_url), entry['slave_reference'])
if 'on-notification' in entry:
path_list.append(self.createCallback(entry['on-notification'], wrapper))
else:
cron_entry = os.path.join(self.options['cron-entries'], url_hash) cron_entry = os.path.join(self.options['cron-entries'], url_hash)
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'], wrapper))
...@@ -133,7 +160,7 @@ class Recipe(GenericBaseRecipe): ...@@ -133,7 +160,7 @@ class Recipe(GenericBaseRecipe):
return path_list return path_list
def install(self): def _install(self):
path_list = [] 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