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
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
 def test_disk_auto_resize_max_value(self):
     message = 'Disk auto resize can not be greater than {}GB'.format(
         self.auto_resize_max_size_in_gb.value
     )
     no_disk_offering = DiskOfferingMaxAutoResize()
     self.assertEqual(no_disk_offering.message, message)