1 from PLC.Debug import log
2 from PLC.Faults import *
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.Auth import Auth, BootAuth
6 from PLC.Messages import Message, Messages
7 from PLC.Persons import Person, Persons
8 from PLC.Sites import Site, Sites
10 class BootNotifyOwners(Method):
12 Notify the owners of the node, and/or support about an event that
13 happened on the machine.
15 Returns 1 if successful.
22 Message.fields['message_id'],
23 Parameter(int, "Notify PIs"),
24 Parameter(int, "Notify technical contacts"),
25 Parameter(int, "Notify support")
28 returns = Parameter(int, '1 if successful')
30 def call(self, auth, message_id, include_pis, include_techs, include_support):
31 messages = Messages(self.api, [message_id], enabled = True)
33 print >> log, "No such message template '%s'" % message_id
37 if not self.api.config.PLC_MAIL_ENABLED:
41 from_addr[self.api.config.PLC_MAIL_SUPPORT_ADDRESS] = \
42 "%s %s" % ('Planetlab', 'Support')
45 if self.api.config.PLC_MAIL_BOOT_ADDRESS:
46 recipients[self.api.config.PLC_MAIL_BOOT_ADDRESS] = "Boot Messages"
48 if include_support and self.api.config.PLC_MAIL_SUPPORT_ADDRESS:
49 recipients[self.api.config.PLC_MAIL_SUPPORT_ADDRESS] = self.api.config.PLC_NAME + " Support"
51 if include_pis or include_techs:
52 sites = Sites(self.api, [self.caller['site_id']])
54 raise PLCAPIError, "No site associated with node"
57 persons = Persons(self.api, site['person_ids'])
58 for person in persons:
59 if include_pis and 'pi' in person['roles'] or \
60 include_techs and 'tech' in person['roles']:
61 recipients[person['email']] = person['first_name'] + " " + person['last_name']
63 subject = message['subject']
64 template = message['template']
67 self.api.mailer.mail(recipients, None, from_addr, subject, template)
70 self.message = "Node sent message %s to contacts"