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 print >> log, "No such message template"
36 if not self.api.config.PLC_MAIL_ENABLED:
40 from_addr[self.api.config.PLC_MAIL_SUPPORT_ADDRESS] = \
41 "%s %s" % ('Planetlab', 'Support')
44 if self.api.config.PLC_MAIL_BOOT_ADDRESS:
45 recipients[self.api.config.PLC_MAIL_BOOT_ADDRESS] = "Boot Messages"
47 if include_support and self.api.config.PLC_MAIL_SUPPORT_ADDRESS:
48 recipients[self.api.config.PLC_MAIL_SUPPORT_ADDRESS] = self.api.config.PLC_NAME + " Support"
50 if include_pis or include_techs:
51 sites = Sites(self.api, [self.caller['site_id']])
53 raise PLCAPIError, "No site associated with node"
56 persons = Persons(self.api, site['person_ids'])
57 for person in persons:
58 if include_pis and 'pi' in person['roles'] or \
59 include_techs and 'tech' in person['roles']:
60 recipients[person['email']] = person['first_name'] + " " + person['last_name']
62 subject = message['subject']
63 template = message['template']
66 self.api.mailer.mail(recipients, None, from_addr, subject, template)
69 self.message = "Node sent message %s to contacts"