- use Boot.notify_owners()
authorMark Huang <mlhuang@cs.princeton.edu>
Tue, 30 Jan 2007 23:08:44 +0000 (23:08 +0000)
committerMark Huang <mlhuang@cs.princeton.edu>
Tue, 30 Jan 2007 23:08:44 +0000 (23:08 +0000)
PLC/Methods/BootNotifyOwners.py

index 958bf9f..c1da332 100644 (file)
@@ -1,11 +1,10 @@
-from PLC.Debug import log
-from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
 from PLC.Auth import Auth, BootAuth
+from PLC.Nodes import Node, Nodes
 from PLC.Messages import Message, Messages
-from PLC.Persons import Person, Persons
-from PLC.Sites import Site, Sites
+
+from PLC.Boot import notify_owners
 
 class BootNotifyOwners(Method):
     """
@@ -28,45 +27,6 @@ class BootNotifyOwners(Method):
     returns = Parameter(int, '1 if successful')
 
     def call(self, auth, message_id, include_pis, include_techs, include_support):
-        messages = Messages(self.api, [message_id], enabled = True)
-        if not messages:
-            print >> log, "No such message template '%s'" % message_id
-           return 1
-        message = messages[0]
-       
-        if not self.api.config.PLC_MAIL_ENABLED:
-            return 1
-
-        from_addr = {}
-        from_addr[self.api.config.PLC_MAIL_SUPPORT_ADDRESS] = \
-        "%s %s" % ('Planetlab', 'Support')
-       recipients = {}
-
-        if self.api.config.PLC_MAIL_BOOT_ADDRESS:
-            recipients[self.api.config.PLC_MAIL_BOOT_ADDRESS] = "Boot Messages"
-
-        if include_support and self.api.config.PLC_MAIL_SUPPORT_ADDRESS:
-            recipients[self.api.config.PLC_MAIL_SUPPORT_ADDRESS] = self.api.config.PLC_NAME + " Support"
-
-        if include_pis or include_techs:
-            sites = Sites(self.api, [self.caller['site_id']])
-            if not sites:
-                raise PLCAPIError, "No site associated with node"
-            site = sites[0]
-
-            persons = Persons(self.api, site['person_ids'])
-            for person in persons:
-                if include_pis and 'pi' in person['roles'] or \
-                   include_techs and 'tech' in person['roles']:
-                    recipients[person['email']] = person['first_name'] + " " + person['last_name']
-
-        subject = message['subject']
-        template = message['template']
-       
-       # Send email
-       self.api.mailer.mail(recipients, None, from_addr, subject, template)
-
-       # Logging variables
-       self.message = "Node sent message %s to contacts"
-
+        assert isinstance(self.caller, Node)
+        notify_owners(self, self.caller, message_id, include_pis, include_techs, include_support)
         return 1