DTrove Models

These objects persist infomation about the clusters, datastores and other information to the Dtrove database. Creating instances of these are pretty straight forward if you know anything about Django. When a user adds a Cluster from the API or the web front end the underlining servers are created. Celery workers are spawn to create the nodes and then report back the status. For example:

>>> from dtrove.models import *
>>> ds = Datastore.objects.get(version='5.5')
>>> ds
<Datastore: mysql - 5.5>
>>> c = Cluster.objects.create(name='my_cluster', datastore=ds, size=10)
>>> c
<Cluster: my_cluster>
>>> c.datastore.name
u'mysql - 5.5'
>>> c.datastore.status
u'spawning'

Once the cluster is in an ‘active’ state further operations can be done.

Available models

class dtrove.models.Cluster(*args, **kwargs)

Datastore Cluster

This is the Main User facing object it defines the datastore type along with the size of the cluster and the other user options.

Parameters:
  • name (str) – Name of the cluster
  • datastore (dtrove.models.Datastore) – Datastore of the cluster
  • size (int) – Number of nodes in the cluster

When a user creates a new Cluster the system handles provisioning the underlining instances and checking on the health of them.

After the cluster is created the user can then use the datastores, or perform certain actions:

  • Schedule automated backups
  • Import from a previous datastore export
  • Export the data into a transportable type
  • Change configuration parameters

The posibilities are endless!

add_node(count=1)

Add a node to the cluster.

class dtrove.models.Datastore(*args, **kwargs)

Datastore

This represents a version of a specific datastore that is available

Parameters:
  • manager_class (dtrove.config.DTROVE_DATASTORE_MANAGERS) – The dotted path to the actual manager object
  • version (str) – The version of the datastore ex: 5.6
  • image (str) – The id of the VM image to use to create new instances
  • packages (str) – Comma separated list of packages to install

The main purpose of this object is to link the datastore manager to a list of packages to install and the base image that is used to create instances.

By creating an datastore that makes it available for users to select and install a cluster from it.

The manager_class property should be an importable subclass of the dtrove.datastores.base.BaseManager class.

manager

The manager object initialize with this datastores information

name

The display name of the datastore (manager.name - version)

class dtrove.models.Instance(*args, **kwargs)

Instance

This contains the information about the actual server instance that runs the datastore in the cluster.

Parameters:
  • name (str) – Name of the instance
  • cluster (dtrove.models.Cluster) – Cluster that this instance is a part of
  • key (dtrove.models.Key) – SSH Key pair object for this instance
  • user (str) – The user which the SSH Key is connected to
  • addr (ipaddr) – IP Address of this server
  • server (str) – UUID of the nova server instance

Note

This model is internal only, all interactions are handled thought the cluster model and or the manager class on the cluster

Remote operations can be preformed on this instance by using the connection_info property like so:

from fabric.api import sudo, settings
from fabric.network import disconnect_all
from dtrove.models import Instance

instance = Instance.objects.first()

with settings(**instance.connection_info):
    sudo('rm -rf /etc/trove/*')

# Always remember to disconnect ssh sessions
disconnect_all()

See the dtrove.datastores.base.BaseManager class for more examples.

connection_info

Provides the connection info from the key stored for this server

message

Error message of the last server task

progress

Progress of the current server task

server_status

Status of the server

class dtrove.models.Key(*args, **kwargs)

SSH Key Pair

This holds the public and private keys for connecting to a remote host.

Note

This should have encrypted fields. Don’t put anything really secure in here. This is just a proof of concept.

Parameters:
  • name (str) – Name of the key
  • passphrase (str) – Passphrase for the key
  • private (str) – Text of the private key
  • public (str) – Text of the public key

These keys are attached to an instance, the idea is that each cluster would have it’s own ssh key assigned to it. That way there isn’t a single master key that own’s your entire network.

You should also use a passphrase for each key even though it is not a required field.

You can access the information in this key in the dtrove.models.Instance.connection_info property on the instance(s) the key is attached to.

classmethod create(save=True)

Factory method to create a new private/public key pair