- send email
[plcapi.git] / PLC / Methods / BootNotifyOwners.py
index 777a590..7de5a1a 100644 (file)
@@ -19,22 +19,27 @@ class BootNotifyOwners(Method):
     accepts = [
         BootAuth(),
         Message.fields['message_id'],
-        Parameter(bool, "Notify PIs"),
-        Parameter(bool, "Notify technical contacts"),
-        Parameter(bool, "Notify support")
+        Parameter(int, "Notify PIs"),
+        Parameter(int, "Notify technical contacts"),
+        Parameter(int, "Notify support")
         ]
 
     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).values()
+        messages = Messages(self.api, [message_id], enabled = True)
         if not messages:
-            raise PLCInvalidArgument, "No such message template"
-
+            # raise PLCInvalidArgument, "No such message template"
+            return 1
+        message = messages[0]
+       
         if not self.api.config.PLC_MAIL_ENABLED:
             return 1
 
-        recipients = {}
+        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"
@@ -43,17 +48,24 @@ class BootNotifyOwners(Method):
             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']]).values()
+            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']).values()
+            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']
 
-        # XXX Send mail
+        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"
 
         return 1