Fix version output when missing.
[plcapi.git] / PLC / Boot.py
1 #
2 # Boot Manager support
3 #
4 # Mark Huang <mlhuang@cs.princeton.edu>
5 # Copyright (C) 2007 The Trustees of Princeton University
6 #
7 # $Id$
8 # $URL$
9 #
10
11 from PLC.Faults import *
12 from PLC.Debug import log
13 from PLC.Messages import Message, Messages
14 from PLC.Persons import Person, Persons
15 from PLC.Sites import Site, Sites
16 from PLC.sendmail import sendmail
17
18 def notify_owners(method, node, message_id,
19                   include_pis = False, include_techs = False, include_support = False,
20                   fault = None):
21     messages = Messages(method.api, [message_id], enabled = True)
22     if not messages:
23         print >> log, "No such message template '%s'" % message_id
24         return 1
25     message = messages[0]
26
27     To = []
28
29     if method.api.config.PLC_MAIL_BOOT_ADDRESS:
30         To.append(("Boot Messages", method.api.config.PLC_MAIL_BOOT_ADDRESS))
31
32     if include_support and method.api.config.PLC_MAIL_SUPPORT_ADDRESS:
33         To.append(("%s Support" % method.api.config.PLC_NAME,
34                    method.api.config.PLC_MAIL_SUPPORT_ADDRESS))
35
36     if include_pis or include_techs:
37         sites = Sites(method.api, [node['site_id']])
38         if not sites:
39             raise PLCAPIError, "No site associated with node"
40         site = sites[0]
41
42         persons = Persons(method.api, site['person_ids'])
43         for person in persons:
44             if (include_pis and 'pi' in person['roles'] and person['enabled']) or \
45                (include_techs and 'tech' in person['roles'] and person['enabled']) :
46                 To.append(("%s %s" % (person['first_name'], person['last_name']), person['email']))
47
48     # Send email
49     params = {'node_id': node['node_id'],
50               'hostname': node['hostname'],
51               'PLC_WWW_HOST': method.api.config.PLC_WWW_HOST,
52               'PLC_WWW_SSL_PORT': method.api.config.PLC_WWW_SSL_PORT,
53               'fault': fault}
54
55     sendmail(method.api, To = To,
56              Subject = message['subject'] % params,
57              Body = message['template'] % params)
58
59     # Logging variables
60     method.object_type = "Node"
61     method.object_ids = [node['node_id']]
62     method.message = "Sent message %s" % message_id