From: Mark Huang Date: Tue, 30 Jan 2007 23:07:54 +0000 (+0000) Subject: - Boot Manager support functions (so far, only notify_owners()) X-Git-Tag: pycurl-7_13_1~47 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=c93e31479f4b3da49a06345e65179a9d16165c9b;p=plcapi.git - Boot Manager support functions (so far, only notify_owners()) --- diff --git a/PLC/Boot.py b/PLC/Boot.py new file mode 100644 index 0000000..cd3a738 --- /dev/null +++ b/PLC/Boot.py @@ -0,0 +1,61 @@ +# +# Boot Manager support +# +# Mark Huang +# Copyright (C) 2007 The Trustees of Princeton University +# +# $Id$ +# + +from PLC.Faults import * +from PLC.Debug import log +from PLC.Messages import Message, Messages +from PLC.Persons import Person, Persons +from PLC.Sites import Site, Sites +from PLC.sendmail import sendmail + +def notify_owners(method, node, message_id, + include_pis = False, include_techs = False, include_support = False, + fault = None): + messages = Messages(method.api, [message_id], enabled = True) + if not messages: + print >> log, "No such message template '%s'" % message_id + return 1 + message = messages[0] + + To = [] + + if method.api.config.PLC_MAIL_BOOT_ADDRESS: + To.append(("Boot Messages", method.api.config.PLC_MAIL_BOOT_ADDRESS)) + + if include_support and method.api.config.PLC_MAIL_SUPPORT_ADDRESS: + To.append(("%s Support" % method.api.config.PLC_NAME, + method.api.config.PLC_MAIL_SUPPORT_ADDRESS)) + + if include_pis or include_techs: + sites = Sites(method.api, [node['site_id']]) + if not sites: + raise PLCAPIError, "No site associated with node" + site = sites[0] + + persons = Persons(method.api, site['person_ids']) + for person in persons: + if include_pis and 'pi' in person['roles'] or \ + include_techs and 'tech' in person['roles']: + To.append(("%s %s" % (person['first_name'], person['last_name']), person['email'])) + + # Send email + params = {'node_id': node['node_id'], + 'hostname': node['hostname'], + 'PLC_WWW_HOST': method.api.config.PLC_WWW_HOST, + 'PLC_WWW_SSL_PORT': method.api.config.PLC_WWW_SSL_PORT, + 'fault': fault} + + sendmail(method.api, To = To, + Subject = message['subject'] % params, + Body = message['template'] % params) + + # Logging variables + method.object_type = "Node" + method.object_ids = [node['node_id']] + method.message = "Sent message %s" % message_id