Robert Myers avatar Robert Myers committed 3a73858

Fixing up models and start of new simplified worker object.

Comments (0)

Files changed (3)

cannula/api/djangodb/models.py

     desc = models.TextField(blank=True, null=True)
     url = models.CharField(max_length=255, blank=True,
                            help_text="Default URL to use when deploying.")
-    repo = models.ForeignKey(Repository, blank=True, null=True,
-                             help_text="Default repository when deploying.")
+    repo = models.CharField(max_length=512)
+    repo_type = models.CharField(max_length=20, choices=VCS_CHOICES)
     members = models.ManyToManyField(User, through="ProjectMembership")
     date_created = models.DateField(default=datetime.now)
 
         ordering = ('user', 'permission')
 
 
-class Credential(models.Model, ApiModels.BaseCredential):
-    """
-    A system credential for a host or set of hosts.
-
-    Stores username, certfile, and password. The later
-    two are stored encrypted.
-    """
-    username = models.CharField(max_length=100)
-    certfile = EncryptedTextField(blank=True, null=True,
-        help_text="The contents of the private key.")
-    password = EncryptedCharField(max_length=255, blank=True, null=True,
-        help_text="The password for the username or private key.")
-    class Meta:
-        app_label = "cannula"
-
 class Server(models.Model, ApiModels.BaseServer):
     name = models.CharField(max_length=255)
     ipaddr = models.CharField(max_length=255)
     port = models.IntegerField(default=22)
     platform_class = models.CharField(max_length=255,
         help_text="Dotted path to system platform type")
-    root_path = models.CharField(max_length=512,
-        blank=True, null=True,
-        help_text="Base path where projects are deployed to.")
     admin_only = models.NullBooleanField(default=False)
-    credential = models.ForeignKey(Credential, blank=True, null=True)
+    active = models.NullBooleanField(default=True)
     class Meta:
         app_label = "cannula"
 
     parent = models.ForeignKey('self', blank=True, null=True)
     name = models.CharField(max_length=255)
     abbr = models.CharField(max_length=30, unique=True)
-    hostname = models.CharField(max_length=100, blank=True,
-        help_text="The host name that will refer to this cluster for when the"
-                  " cluster is behind a load balancer.  E.g. www.example.com"
-                  " load balances between www1, www2, etc.")
-
-    servers = models.ManyToManyField(Server, through='ClusterServer')
-    min_uid = models.IntegerField(blank=True, null=True)
-    max_uid = models.IntegerField(blank=True, null=True)
-    min_gid = models.IntegerField(blank=True, null=True)
-    max_gid = models.IntegerField(blank=True, null=True)
+    servers = models.ManyToManyField(Server)
     order = models.IntegerField(default=1,
         help_text="Sorting order of this cluster.")
     deployable = models.NullBooleanField(default=True)
     admin_only = models.NullBooleanField(default=False)
     production = models.NullBooleanField(default=False,
         help_text="Is this cluster a production (non-staging) cluster.")
-    jump_host = models.ForeignKey(Server, blank=True, null=True,
-        related_name="jumphost",
-        help_text="Server that can connect to this cluster.")
 
     class Meta:
         app_label = "cannula"
         ordering = ('order',)
 
-
-class ClusterServer(models.Model):
-    cluster = models.ForeignKey(Cluster)
-    server = models.ForeignKey(Server)
-    active = models.BooleanField(default=True)
-    class Meta:
-        app_label = "cannula"
-
 class Deployment(models.Model, ApiModels.BaseDeployment):
     """
     An instance of a deployed project.
     project = models.ForeignKey(Project)
     cluster = models.ForeignKey(Cluster)
     url = models.CharField(max_length=255,
-        help_text="Absolute URL to deploy project to.")
+        help_text="Absolute URL to deploy project to ie. '/', '/myapp'")
     package = models.ForeignKey(Package)
-    # TODO: we might want to also allow an optional repo object to override
-    # the project's default one.
-    #repo = models.ForeignKey(Repository, blank=True, null=True,
-    #                         help_text="Override repository.")
     repo_path = models.CharField(max_length=512,
-        help_text="ie. branch/name, trunk, tag/number, etc...")
+        help_text="ie. branch/name, trunk, tag/number, tip, etc...")
     revision = models.CharField(max_length=100, default="HEAD")
-    # TODO: what are we defaulting num_processes to for prod deployments?
-    num_processes = models.IntegerField(default=1)
     date_stamp = models.DateTimeField(default=datetime.now)
     active = models.BooleanField(default=True)
     status = models.CharField(max_length=50, default="Up")
     settings = models.TextField(blank=True)
+    requirements = models.TextField(blank=True,
+        help_text="override the project default requirements")
+    
     class Meta:
         app_label = "cannula"
 
     'users': 'cannula.api.djangodb.users.UserAPI',
 }
 #
+# Dictionary of values to pass to the context when
+# deploying applications. 
+# CANNUL_CLUSTER_DEFAULTS = {
+#     'cluster_abbr': {'special_value': 'for this cluster'},
+#     '__all__':  {'values': 'for all clusters'}
+# }
+CANNULA_CLUSTER_DEFAULTS = {}
+#
+# Lock timeout in seconds
+CANNULA_LOCK_TIMEOUT = 30
 #### END Defaults ###################################################
 
 # Check for if Django settings module is defined.
     CANNULA_BASE = getattr(settings, 'CANNULA_BASE', CANNULA_BASE)
     CANNULA_PROXY = getattr(settings, 'CANNULA_PROXY', CANNULA_PROXY)
     CANNULA_VCS_ENABLED = getattr(settings, 'CANNULA_VCS_ENABLED', CANNULA_VCS_ENABLED)
+    CANNULA_CLUSTER_DEFAULTS = getattr(settings, 'CANNULA_CLUSTER_DEFAULTS', CANNULA_CLUSTER_DEFAULTS)
+    CANNULA_LOCK_TIMEOUT = getattr(settings, 'CANNULA_LOCK_TIMEOUT', CANNULA_LOCK_TIMEOUT)
+    # Update the api with user specified Classes.
     _api = getattr(settings, 'CANNULA_BASE', {})
     CANNULA_API.update(_api)
 

cannula/worker.py

+import os
+
+from cannula.conf import api, 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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.