X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FBootNotifyOwners.py;h=958bf9f050363267066e1204ca43fef212de167b;hb=e43eb135483c45435c9d4a50d6dff744fb7aef85;hp=79c86b6e1864b4c88edb9b28365f22cd7e51948d;hpb=b8b8f37734046b457f94e030f975c8bdcfde05e9;p=plcapi.git diff --git a/PLC/Methods/BootNotifyOwners.py b/PLC/Methods/BootNotifyOwners.py index 79c86b6..958bf9f 100644 --- a/PLC/Methods/BootNotifyOwners.py +++ b/PLC/Methods/BootNotifyOwners.py @@ -1,3 +1,4 @@ +from PLC.Debug import log from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed @@ -27,14 +28,19 @@ class BootNotifyOwners(Method): returns = Parameter(int, '1 if successful') def call(self, auth, message_id, include_pis, include_techs, include_support): - messages = Messages(self.api, [message_id], enabled = True).values() + messages = Messages(self.api, [message_id], enabled = True) if not messages: - raise PLCInvalidArgument, "No such message template" - + print >> log, "No such message template '%s'" % message_id + return 1 + message = messages[0] + if not self.api.config.PLC_MAIL_ENABLED: return 1 - recipients = {} + from_addr = {} + from_addr[self.api.config.PLC_MAIL_SUPPORT_ADDRESS] = \ + "%s %s" % ('Planetlab', 'Support') + recipients = {} if self.api.config.PLC_MAIL_BOOT_ADDRESS: recipients[self.api.config.PLC_MAIL_BOOT_ADDRESS] = "Boot Messages" @@ -43,17 +49,24 @@ class BootNotifyOwners(Method): recipients[self.api.config.PLC_MAIL_SUPPORT_ADDRESS] = self.api.config.PLC_NAME + " Support" if include_pis or include_techs: - sites = Sites(self.api, [self.caller['site_id']]).values() + sites = Sites(self.api, [self.caller['site_id']]) if not sites: raise PLCAPIError, "No site associated with node" site = sites[0] - persons = Persons(self.api, site['person_ids']).values() + persons = Persons(self.api, site['person_ids']) for person in persons: if include_pis and 'pi' in person['roles'] or \ include_techs and 'tech' in person['roles']: recipients[person['email']] = person['first_name'] + " " + person['last_name'] - # XXX Send mail + subject = message['subject'] + template = message['template'] + + # Send email + self.api.mailer.mail(recipients, None, from_addr, subject, template) + + # Logging variables + self.message = "Node sent message %s to contacts" return 1