Skip to content

Commit f0a1d5d

Browse files
author
Marcelo Rodrigues Da Silva Soares
committed
Merge branch 'feat/auto_upgrade_notification_588' into 'dev'
Added upgrade offering notification and added upgrade offering to chg registry See merge request dbdev/dbaas!11
2 parents 4229a9a + b19d384 commit f0a1d5d

File tree

5 files changed

+67
-3
lines changed

5 files changed

+67
-3
lines changed

dbaas/api/task.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ class TaskAPI(viewsets.ReadOnlyModelViewSet):
160160
'maintenance.tasks.restart_database',
161161
'notification.tasks.change_database_persistence',
162162
'maintenance.tasks.task_upgrade_disk_type',
163+
'maintenance.tasks.auto_upgrade_database_vm_offering',
163164
]
164165

165166
model = TaskHistory

dbaas/maintenance/task_auto_upgrade_vm_offering.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from physical.models import (Plan, DatabaseInfra, Instance, Pool)
77
from util.providers import get_auto_upgrade_vm_settings
88
from workflow.workflow import steps_for_instances
9-
from util import get_vm_name
9+
from util import get_vm_name, email_notifications
1010

1111
LOG = logging.getLogger(__name__)
1212

@@ -72,6 +72,8 @@ def task_auto_upgrade_vm_offering(database, task, retry_from=None, resize_target
7272

7373
if create_temporary_instance: # se precisar criar nova temporary instance, cria
7474
LOG.info("Creating temporary instance")
75+
email_notifications.upgrade_offering_notification(database, resize_target)
76+
7577
for i in range(number_of_instances):
7678
instance = None
7779
last_vm_created += 1
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<h2>Automatic GCP offering upgrade for Database {{ database.name }}</h2>
2+
3+
We would like to inform you that an automatic offer update is being carried out on DBaaS to meet your database <a href="{{database_url}}">{{database.name}}</a> needs.
4+
<br><br>
5+
The update will be done automatically from {{ current_offering.name }} to {{ future_offering.name }}.
6+
<br><br>
7+
Please be aware that this upgrade may increase the costs.
8+
Any questions please contact the DBDevops responsible for your team.
9+
<br><br>
10+
11+
{% if database.team.email %}
12+
You are receiving this email because in our records you are in team {{ database.team.name }}.<br>
13+
If this is not right, contact the DBaaS system administrators.
14+
{% else %}
15+
<h3>Team {{ database.team.name }} has no email set!</h3>
16+
{% endif %}
17+
<br><br><br>
18+
Regards,<br>
19+
DBaaS notification robot<br>
20+
{{domain}}<br>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Automatic GCP offering upgrade for Database {{ database.name }}
2+
3+
We would like to inform you that an automatic offer update is being carried out on DBaaS to meet your database {{database.name}} needs.
4+
5+
The update will be done automatically from {{ current_offering.name }} to {{ future_offering.name }}.
6+
7+
Please be aware that this upgrade may increase the costs.
8+
Any questions please contact the DBDevops responsible for your team.
9+
10+
{% if database.team.email %}
11+
You are receiving this email because in our records you are in team {{ database.team.name }}.<br>
12+
If this is not right, contact the DBaaS system administrators.
13+
{% else %}
14+
Team {{ database.team.name }} has no email set!
15+
{% endif %}
16+
17+
Regards,
18+
DBaaS notification robot
19+
{{domain}}

dbaas/util/email_notifications.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,30 @@ def disk_resize_notification(database, new_disk, usage_percentage):
157157
)
158158

159159

160-
def schedule_task_notification(database, scheduled_task, is_new,
161-
is_task_warning=False):
160+
def upgrade_offering_notification(database, resize_target):
161+
LOG.info('Notifying auto upgrade offering to database: {}'.format(database))
162+
163+
current_offering = database.databaseinfra.offering
164+
future_offering = database.get_future_offering(resize_target)
165+
166+
subject = _('[DBaaS] Database {} auto upgrade offering to {}').format(database, future_offering.name)
167+
template = "auto_upgrade_offering_notification"
168+
169+
context = {
170+
'domain': get_domain(),
171+
'database': database,
172+
'current_offering': current_offering,
173+
'future_offering': future_offering,
174+
'database_url': get_database_url(database.id)
175+
}
176+
177+
send_mail_template(
178+
subject, template, email_from(), email_to(database.team),
179+
fail_silently=False, attachments=None, context=context
180+
)
181+
182+
183+
def schedule_task_notification(database, scheduled_task, is_new, is_task_warning=False):
162184

163185
subject_tmpl = '[DBaaS] Automatic Task {} for Database {}'
164186
if is_task_warning:

0 commit comments

Comments
 (0)