@@ -14,7 +14,6 @@ def get_domain():
1414 domain = Site .objects .get (id = 1 ).domain
1515 if not domain .startswith ('http' ):
1616 return "http://" + domain
17-
1817 return domain
1918
2019
@@ -29,25 +28,50 @@ def email_to(team):
2928
3029
3130def get_database_url (uuid ):
32- return get_domain () + reverse ('admin:logical_database_hosts' ,
33- kwargs = {'id' : uuid })
31+ return get_domain () + reverse ('admin:logical_database_hosts' , kwargs = {'id' : uuid })
32+
33+
34+ def notify_new_database_creation (database = None ):
35+ subject = _ ("[DBAAS] a new database has just been created: {} by {}" .format (database .name , database .team .name ))
36+ template = "database_create_notification"
37+ addr_from = Configuration .get_by_name ("email_addr_from" )
38+ addr_to = Configuration .get_by_name_as_list ("new_user_notify_email" )
39+ domain = get_domain ()
40+
41+ context = {
42+ "database" : database ,
43+ "database_name" : database .name ,
44+ "offering" : database .infra .offering .name ,
45+ "environment" : database .environment .name ,
46+ "database_type" : database .infra .engine .name ,
47+ "disk_size" : database .infra .disk_offering .name ,
48+ "user" : database .user ,
49+ "database_url" : domain + reverse ('admin:account_team_changelist' ),
50+ "domain" : domain
51+ }
52+ LOG .debug ("user: %s | addr_from: %s | addr_to: %s" % (database .user , addr_from , addr_to ))
53+ if database .user and addr_from and addr_to :
54+ send_mail_template (
55+ subject , template , addr_from , addr_to , fail_silently = False , attachments = None , context = context
56+ )
57+ else :
58+ LOG .warning ("could not send email for new user creation" )
3459
3560
3661def notify_new_user_creation (user = None ):
3762 subject = _ ("[DBAAS] a new user has just been created: %s" % user .username )
3863 template = "new_user_notification"
3964 addr_from = Configuration .get_by_name ("email_addr_from" )
4065 addr_to = Configuration .get_by_name_as_list ("new_user_notify_email" )
66+
4167 context = {}
4268 context ['user' ] = user
4369 domain = get_domain ()
4470 context ['url' ] = domain + reverse ('admin:account_team_changelist' )
45- LOG .debug ("user: %s | addr_from: %s | addr_to: %s" %
46- (user , addr_from , addr_to ))
71+ LOG .debug ("user: %s | addr_from: %s | addr_to: %s" % (user , addr_from , addr_to ))
4772 if user and addr_from and addr_to :
4873 send_mail_template (
49- subject , template , addr_from , addr_to ,
50- fail_silently = False , attachments = None , context = context
74+ subject , template , addr_from , addr_to , fail_silently = False , attachments = None , context = context
5175 )
5276 else :
5377 LOG .warning ("could not send email for new user creation" )
@@ -163,7 +187,7 @@ def upgrade_offering_notification(database, resize_target):
163187 current_offering = database .databaseinfra .offering
164188 future_offering = database .get_future_offering (resize_target )
165189
166- subject = _ ('[DBaaS] Database {} auto upgrade offering to {}' ).format (database , future_offering .name )
190+ subject = _ ('[DBaaS] Database {} is being auto upgrade offering to {}' ).format (database , future_offering .name )
167191 template = "auto_upgrade_offering_notification"
168192
169193 context = {
0 commit comments