コード例 #1
0
def disk_auto_resize(database, current_size, usage_percentage):
    from notification.tasks import TaskRegister

    disk = DiskOffering.first_greater_than(current_size + 1024,
                                           database.environment)

    if disk > DiskOffering.last_offering_available_for_auto_resize(
            environment=database.environment):
        raise DiskOfferingMaxAutoResize()

    if database.is_being_used_elsewhere():
        raise BusyDatabaseError("")

    user = AccountUser.objects.get(username="******")

    task = TaskRegister.database_disk_resize(
        database=database,
        user=user,
        disk_offering=disk,
        task_name="database_disk_auto_resize",
        register_user=False,
    )

    email_notifications.disk_resize_notification(
        database=database, new_disk=disk, usage_percentage=usage_percentage)

    return task
コード例 #2
0
def disk_auto_resize(database, current_size, usage_percentage):
    from notification.tasks import TaskRegister

    disk = DiskOffering.first_greater_than(current_size + 1024)

    if disk > DiskOffering.last_offering_available_for_auto_resize():
        raise DiskOfferingMaxAutoResize()

    if database.is_being_used_elsewhere():
        raise BusyDatabaseError("")

    user = AccountUser.objects.get(username='******')

    task = TaskRegister.database_disk_resize(
        database=database,
        user=user,
        disk_offering=disk,
        task_name='database_disk_auto_resize',
        register_user=False
    )

    email_notifications.disk_resize_notification(
        database=database, new_disk=disk, usage_percentage=usage_percentage
    )

    return task
コード例 #3
0
    def test_can_send_email_disk_auto_resize(self):
        database = DatabaseFactory()
        usage_percentage = 76.89

        disk_resize_notification(database=database,
                                 new_disk=self.disk,
                                 usage_percentage=usage_percentage)

        self.assertEqual(len(mail.outbox), 2)
        self.assertEqual(mail.outbox[0].subject,
                         SUBJECT_DISK_AUTO_RESIZE.format(database, self.disk))
        self.assertEqual(mail.outbox[1].subject,
                         SUBJECT_DISK_AUTO_RESIZE.format(database, self.disk))
コード例 #4
0
    def test_can_send_email_disk_final_auto_resize(self):
        usage_percentage = 76.89

        disk_resize_notification(database=self.database,
                                 new_disk=self.greater_disk,
                                 usage_percentage=usage_percentage)

        self.assertEqual(len(mail.outbox), 2)
        self.assertEqual(
            mail.outbox[0].subject,
            SUBJECT_DISK_FINAL_AUTO_RESIZE.format(self.database,
                                                  self.greater_disk))
        self.assertEqual(
            mail.outbox[1].subject,
            SUBJECT_DISK_FINAL_AUTO_RESIZE.format(self.database,
                                                  self.greater_disk))
コード例 #5
0
def disk_auto_resize(database, current_size, usage_percentage):
    disk = DiskOffering.first_greater_than(current_size + 1024)

    if disk > DiskOffering.last_offering_available_for_auto_resize():
        raise DiskOfferingMaxAutoResize()

    task = TaskHistory()
    task.task_name = "database_disk_auto_resize"
    task.task_status = task.STATUS_WAITING
    task.arguments = "Database name: {}".format(database.name)
    task.save()

    user = AccountUser.objects.get(username='******')
    database_disk_resize.delay(database=database,
                               disk_offering=disk,
                               user=user,
                               task_history=task)

    email_notifications.disk_resize_notification(
        database=database, new_disk=disk, usage_percentage=usage_percentage)

    return task