Cloud Providers

This is the interface that the provisioning system uses to create new nodes/volumes/backups for the clusters.

These classes are meant to be used in the task system as they are usually long running operations. During the execution of a long running process the status should be updated on the base objects, usually a dtrove.models.Instance.

Here is a example:

from celery import shared_task
from dtrove.models import Instance
from dtrove.provider import get_provider

provider = get_provider()

@shared_task
def create(instance_id):
    instance = Instance.objects.get(pk=instance_id)
    provider.create(instance)
class dtrove.providers.base.BaseProvider

Base Provider Interface

attach_volume(instance)

Creates and mounts a volume on an instance

Parameters:instance (dtrove.models.Instance) – An instance object to delete
Raises:dtrove.providers.base.ProviderError If the volume create and mount failed

The provider should update instance with the following info:

  • volume: Reference to the actual volume id on the provider
create(instance, **kwargs)

Creates a new instance

Parameters:instance (dtrove.models.Instance) – An instance object to create
Raises:dtrove.providers.base.ProviderError If the create failed

Typically the provider should respond with a 202 message and work in the background to create the instance. So during creation of the instance on the provider this should update the progress field of the instance.

The provider should update instance with the following info:

  • server: Reference to the actual server id on the provider
  • addr: The public facing ip address to this server
  • user: The inital user that was created

The task, status and progress are properties that are cached on the dtrove.models.Instance Instance object.

destroy(instance)

Destroys an instance

Parameters:instance (dtrove.models.Instance) – An instance object to delete
Raises:dtrove.providers.base.ProviderError If the delete failed

This should delete the instance and poll until the instance is deleted.

flavors(datastore=None)

Return a list of flavors available

Parameters:datastore (str) – (optional) datastore to filter flavors by
snapshot(instance)

Creates a snapshot of an instance

Parameters:instance (dtrove.models.Instance) – An instance object to delete
Raises:dtrove.providers.base.ProviderError If the snapshot failed
supports_snapshots = True

Whether of not this provider supports snapshots

supports_volumes = True

Whether or not this provider supports creating and attaching volumes

update_status(instance)

Updates the status of an instance

Parameters:instance (dtrove.models.Instance) – An instance object to create
Raises:dtrove.providers.base.ProviderError If the status failed
Returns:tuple of (status, progress)

A call to this method should set the properties on the instance. For example here:

def update_status(self, instance):
    obj = self.get(instance.id)

    instance.message = obj.error_message
    instance.server_status = obj.status
    instance.progress = obj.progress

    return instance.server_status, instance.progress
  • status property should be a string of the current status
  • progress property should be an int which is the percent complete
exception dtrove.providers.base.ProviderError

An exception during a provisoner action.

dtrove.providers.base.get_provider()

Return the current provider class