1. Robert Myers
  2. cannula


cannula / cannula / worker.py

import os

from cannula.conf import api, proxy, CANNULA_CLUSTER_DEFAULTS, CANNULA_BASE

class DeploymentError(Exception):
    """Base class for all deployment exception classes."""

class InvalidAction(DeploymentError):
    """There was an attempt to run an invalid action"""

class InvalidStatus(DeploymentError):
    """The deployment is not in the correct state for this action."""

class WorkerBase(object):
    """Base Worker class. Subclasses need to define 'deploy', 'delete' 
    and 'modify'
    # The process runner, name used for templates ('uwsgi', 'gunicorn', 'fastcgi')
    worker = ''
    # The type of application ('django', 'pylons', 'paste', 'php')
    flavor = ''
    def defaults(self, deployment):
        """Return a dictionary of the default values for this deployment."""
        cluster = api.clusters.get(deployment.cluster)
        defaults = CANNULA_CLUSTER_DEFAULTS.get('__all__', {})
        defaults.update(CANNULA_CLUSTER_DEFAULTS.get(cluster.abbr, {}))
        defaults.update({'deployment': deployment})
        return defaults 
    def deploy(self, deployment, **kwargs):
        """Deploy the deployment object. """
        defaults = self.defaults(deployment)
        worker_base = os.path.join(CANNULA_BASE, self.worker)
    def delete(self, *args, **kwargs):
        raise NotImplementedError
    def modify(self, *args, **kwargs):
        """Start|stop|restart the application.
        Raises 'InvalidAction' and 'InvalidStatus'"""
        raise NotImplementedError