Update notification part
diff --git a/staffeln/common/notify.py b/staffeln/common/notify.py
deleted file mode 100644
index e3aabf2..0000000
--- a/staffeln/common/notify.py
+++ /dev/null
@@ -1,54 +0,0 @@
-# Email notification package
-# This should be upgraded by integrating with mail server to send batch
-import smtplib
-from email.mime.text import MIMEText
-from email.mime.multipart import MIMEMultipart
-import staffeln.conf
-from staffeln.common import time as xtime
-
-CONF = staffeln.conf.CONF
-
-
-def sendEmail(src_email, src_pwd, dest_email, subject, content, smtp_server_domain, smtp_server_port):
- try:
- message = MIMEMultipart("alternative")
- message["Subject"] = subject
- message["From"] = src_email
- message["To"] = dest_email
- part = MIMEText(content, "html")
- message.attach(part)
-
- s = smtplib.SMTP(host=smtp_server_domain, port=smtp_server_port)
- s.ehlo()
- s.starttls()
- # we can comment this auth func when use the trusted ip without authentication against the smtp server
- s.login(src_email, src_pwd)
- s.sendmail(src_email, dest_email, message.as_string())
- s.close()
- return True
- except Exception as e:
- print(str(e))
- return False
-
-def SendBackupResultNotification(success_volume_list, failed_volume_list):
- subject = "Backup result"
-
- html = "<h3>${TIME}</h3>" \
- "<h3>Success List</h3>" \
- "<h4>${SUCCESS_VOLUME_LIST}</h4>" \
- "<h3>Failed List</h3>" \
- "<h4>${FAILED_VOLUME_LIST}</h4>"
-
- success_volumes = '<br>'.join([str(elem) for elem in success_volume_list])
- failed_volumes = '<br>'.join([str(elem) for elem in failed_volume_list])
- html = html.replace("${TIME}", xtime.get_current_strtime())
- html = html.replace("${SUCCESS_VOLUME_LIST}", success_volumes)
- html = html.replace("${FAILED_VOLUME_LIST}", failed_volumes)
-
- return sendEmail(src_email=CONF.notification.sender_email,
- src_pwd=CONF.notification.sender_pwd,
- dest_email=CONF.notification.receiver,
- subject=subject,
- content=html,
- smtp_server_domain=CONF.notification.smtp_server_domain,
- smtp_server_port=CONF.notification.smtp_server_port)
diff --git a/staffeln/common/time.py b/staffeln/common/time.py
index 0af1cb4..3059085 100644
--- a/staffeln/common/time.py
+++ b/staffeln/common/time.py
@@ -33,7 +33,7 @@
def get_current_strtime():
- now = datetime.datetime.now()
+ now = datetime.now()
return now.strftime(DEFAULT_TIME_FORMAT)
diff --git a/staffeln/conductor/manager.py b/staffeln/conductor/manager.py
index 5997828..6898348 100755
--- a/staffeln/conductor/manager.py
+++ b/staffeln/conductor/manager.py
@@ -7,10 +7,10 @@
import time
from staffeln.common import constants
-from staffeln.conductor import backup
from staffeln.common import context
-from staffeln.common import notify
from staffeln.common import time as xtime
+from staffeln.conductor import backup
+from staffeln.conductor import notify
from staffeln.i18n import _
LOG = log.getLogger(__name__)
@@ -87,9 +87,11 @@
backup.Backup().create_queue(current_tasks)
def _report_backup_result(self):
+ # TODO(Alex): Need to update these list
self.success_backup_list = []
self.failed_backup_list = []
- notify.SendNotification(self.success_backup_list, self.failed_backup_list)
+ notify.SendBackupResultEmail(self.success_backup_list, self.failed_backup_list)
+
@periodics.periodic(spacing=CONF.conductor.backup_service_period, run_immediately=True)
def backup_engine(self):
diff --git a/staffeln/conductor/notify.py b/staffeln/conductor/notify.py
new file mode 100644
index 0000000..d80da4e
--- /dev/null
+++ b/staffeln/conductor/notify.py
@@ -0,0 +1,57 @@
+# Email notification package
+# This should be upgraded by integrating with mail server to send batch
+import smtplib
+from email.mime.text import MIMEText
+from email.mime.multipart import MIMEMultipart
+from oslo_log import log
+import staffeln.conf
+from staffeln.common import time as xtime
+from staffeln.i18n import _
+
+CONF = staffeln.conf.CONF
+LOG = log.getLogger(__name__)
+
+
+def _sendEmail(src_email, src_pwd, dest_email, subject, content, smtp_server_domain, smtp_server_port):
+ message = MIMEMultipart("alternative")
+ message["Subject"] = subject
+ message["From"] = src_email
+ message["To"] = dest_email
+ part = MIMEText(content, "html")
+ message.attach(part)
+
+ s = smtplib.SMTP(host=smtp_server_domain, port=smtp_server_port)
+ s.ehlo()
+ s.starttls()
+ # we can comment this auth func when use the trusted ip without authentication against the smtp server
+ s.login(src_email, src_pwd)
+ s.sendmail(src_email, dest_email, message.as_string())
+ s.close()
+
+
+def SendBackupResultEmail(success_backup_list, failed_backup_list):
+ subject = "Backup result"
+
+ html = "<h3>${TIME}</h3>" \
+ "<h3>Success List</h3>" \
+ "<h4>${SUCCESS_VOLUME_LIST}</h4>" \
+ "<h3>Failed List</h3>" \
+ "<h4>${FAILED_VOLUME_LIST}</h4>"
+
+ success_volumes = '<br>'.join([str(elem) for elem in success_backup_list])
+ failed_volumes = '<br>'.join([str(elem) for elem in failed_backup_list])
+ html = html.replace("${TIME}", xtime.get_current_strtime())
+ html = html.replace("${SUCCESS_VOLUME_LIST}", success_volumes)
+ html = html.replace("${FAILED_VOLUME_LIST}", failed_volumes)
+ try:
+ _sendEmail(src_email=CONF.notification.sender_email,
+ src_pwd=CONF.notification.sender_pwd,
+ dest_email=CONF.notification.receiver,
+ subject=subject,
+ content=html,
+ smtp_server_domain=CONF.notification.smtp_server_domain,
+ smtp_server_port=CONF.notification.smtp_server_port)
+ LOG.info(_("Backup result email sent"))
+ except Exception as e:
+ LOG.error(_("Backup result email send failed. Please check email configuration. %s" % (str(e))))
+