X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FBootNotifyOwners.py;h=7458b9dee1fbfbe40cd803d6aed92945aa9ae392;hb=475ee53aaaa011ba14a34af34d3340257d6f9d59;hp=b3a0b99b21bdacb5d17772e6375ba6ff1fd85ebe;hpb=dd6f6871abdf5412d908dc31777ce88b09192efe;p=plcapi.git diff --git a/PLC/Methods/BootNotifyOwners.py b/PLC/Methods/BootNotifyOwners.py index b3a0b99..7458b9d 100644 --- a/PLC/Methods/BootNotifyOwners.py +++ b/PLC/Methods/BootNotifyOwners.py @@ -1,10 +1,10 @@ -from PLC.Faults import * from PLC.Method import Method from PLC.Parameter import Parameter, Mixed -from PLC.Auth import Auth, BootAuth +from PLC.Auth import Auth, BootAuth, SessionAuth +from PLC.Nodes import Node, Nodes from PLC.Messages import Message, Messages -from PLC.Persons import Person, Persons -from PLC.Sites import Site, Sites + +from PLC.Boot import notify_owners class BootNotifyOwners(Method): """ @@ -17,7 +17,7 @@ class BootNotifyOwners(Method): roles = ['node'] accepts = [ - BootAuth(), + Auth(), Message.fields['message_id'], Parameter(int, "Notify PIs"), Parameter(int, "Notify technical contacts"), @@ -27,36 +27,6 @@ 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) - if not messages: - # raise PLCInvalidArgument, "No such message template" - return 1 - message = messages[0] - - if not self.api.config.PLC_MAIL_ENABLED: - return 1 - - recipients = {} - - if self.api.config.PLC_MAIL_BOOT_ADDRESS: - recipients[self.api.config.PLC_MAIL_BOOT_ADDRESS] = "Boot Messages" - - if include_support and self.api.config.PLC_MAIL_SUPPORT_ADDRESS: - 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']]) - if not sites: - raise PLCAPIError, "No site associated with node" - site = sites[0] - - 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 - self.message = "Node sent message %s to contacts" - + assert isinstance(self.caller, Node) + notify_owners(self, self.caller, message_id, include_pis, include_techs, include_support) return 1