Skip to content

Commit

Permalink
Merge branch 'feat/auto_upgrade_notification_588' of github.com:globo…
Browse files Browse the repository at this point in the history
…com/database-as-a-service into feat/fix_enable_disable_zabbix_alarms
  • Loading branch information
Marcelo RS Soares committed May 31, 2023
2 parents ee1b930 + 14ba7be commit 9eb1982
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 3 deletions.
1 change: 1 addition & 0 deletions dbaas/api/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class TaskAPI(viewsets.ReadOnlyModelViewSet):
'maintenance.tasks.restart_database',
'notification.tasks.change_database_persistence',
'maintenance.tasks.task_upgrade_disk_type',
'maintenance.tasks.auto_upgrade_database_vm_offering',
]

model = TaskHistory
Expand Down
3 changes: 2 additions & 1 deletion dbaas/maintenance/task_auto_upgrade_vm_offering.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from physical.models import (Plan, DatabaseInfra, Instance, Pool)
from util.providers import get_auto_upgrade_vm_settings
from workflow.workflow import steps_for_instances
from util import get_vm_name
from util import get_vm_name, email_notifications

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -75,6 +75,7 @@ def task_auto_upgrade_vm_offering(database, task, retry_from=None, resize_target
last_vm_created = number_of_instances_before_task

if not retry_from:
email_notifications.upgrade_offering_notification(database, resize_target)
for i in range(number_of_instances):
instance = None
last_vm_created += 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<h2>Automatic GCP offering upgrade for Database {{ database.name }}</h2>

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.
<br><br>
The update will be done automatically from {{ current_offering.name }} to {{ future_offering.name }}.
<br><br>
Please be aware that this upgrade may increase the costs.
Any questions please contact the DBDevops responsible for your team.
<br><br>

{% if database.team.email %}
You are receiving this email because in our records you are in team {{ database.team.name }}.<br>
If this is not right, contact the DBaaS system administrators.
{% else %}
<h3>Team {{ database.team.name }} has no email set!</h3>
{% endif %}
<br><br><br>
Regards,<br>
DBaaS notification robot<br>
{{domain}}<br>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Automatic GCP offering upgrade for Database {{ database.name }}

We would like to inform you that an automatic offer update is being carried out on DBaaS to meet your database {{database.name}} needs.

The update will be done automatically from {{ current_offering.name }} to {{ future_offering.name }}.

Please be aware that this upgrade may increase the costs.
Any questions please contact the DBDevops responsible for your team.

{% if database.team.email %}
You are receiving this email because in our records you are in team {{ database.team.name }}.<br>
If this is not right, contact the DBaaS system administrators.
{% else %}
Team {{ database.team.name }} has no email set!
{% endif %}

Regards,
DBaaS notification robot
{{domain}}
26 changes: 24 additions & 2 deletions dbaas/util/email_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,30 @@ def disk_resize_notification(database, new_disk, usage_percentage):
)


def schedule_task_notification(database, scheduled_task, is_new,
is_task_warning=False):
def upgrade_offering_notification(database, resize_target):
LOG.info('Notifying auto upgrade offering to database: {}'.format(database))

current_offering = database.databaseinfra.offering
future_offering = database.get_future_offering(resize_target)

subject = _('[DBaaS] Database {} auto upgrade offering to {}').format(database, future_offering.name)
template = "auto_upgrade_offering_notification"

context = {
'domain': get_domain(),
'database': database,
'current_offering': current_offering,
'future_offering': future_offering,
'database_url': get_database_url(database.id)
}

send_mail_template(
subject, template, email_from(), email_to(database.team),
fail_silently=False, attachments=None, context=context
)


def schedule_task_notification(database, scheduled_task, is_new, is_task_warning=False):

subject_tmpl = '[DBaaS] Automatic Task {} for Database {}'
if is_task_warning:
Expand Down

0 comments on commit 9eb1982

Please sign in to comment.