1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Auth import Auth, BootAuth
5 from PLC.Messages import Message, Messages
6 from PLC.Persons import Person, Persons
7 from PLC.Sites import Site, Sites
9 class BootNotifyOwners(Method):
11 Notify the owners of the node, and/or support about an event that
12 happened on the machine.
14 Returns 1 if successful.
21 Message.fields['message_id'],
22 Parameter(int, "Notify PIs"),
23 Parameter(int, "Notify technical contacts"),
24 Parameter(int, "Notify support")
27 returns = Parameter(int, '1 if successful')
29 def call(self, auth, message_id, include_pis, include_techs, include_support):
30 messages = Messages(self.api, [message_id], enabled = True)
32 # raise PLCInvalidArgument, "No such message template"
36 if not self.api.config.PLC_MAIL_ENABLED:
41 if self.api.config.PLC_MAIL_BOOT_ADDRESS:
42 recipients[self.api.config.PLC_MAIL_BOOT_ADDRESS] = "Boot Messages"
44 if include_support and self.api.config.PLC_MAIL_SUPPORT_ADDRESS:
45 recipients[self.api.config.PLC_MAIL_SUPPORT_ADDRESS] = self.api.config.PLC_NAME + " Support"
47 if include_pis or include_techs:
48 sites = Sites(self.api, [self.caller['site_id']])
50 raise PLCAPIError, "No site associated with node"
53 persons = Persons(self.api, site['person_ids'])
54 for person in persons:
55 if include_pis and 'pi' in person['roles'] or \
56 include_techs and 'tech' in person['roles']:
57 recipients[person['email']] = person['first_name'] + " " + person['last_name']
60 self.message = "Node sent message %s to contacts"