You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by pq...@apache.org on 2010/05/05 01:43:44 UTC
svn commit: r941105 - /incubator/libcloud/trunk/libcloud/deployment.py
Author: pquerna
Date: Tue May 4 23:43:44 2010
New Revision: 941105
URL: http://svn.apache.org/viewvc?rev=941105&view=rev
Log:
Add doc strings on deployment classes
Modified:
incubator/libcloud/trunk/libcloud/deployment.py
Modified: incubator/libcloud/trunk/libcloud/deployment.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/deployment.py?rev=941105&r1=941104&r2=941105&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/deployment.py (original)
+++ incubator/libcloud/trunk/libcloud/deployment.py Tue May 4 23:43:44 2010
@@ -19,18 +19,63 @@ Provides generic deployment steps for ma
import os
class Deployment(object):
- pass
+ """
+ Base class for deployment tasks.
+ """
+
+ def run(self, node, client):
+ """
+ Runs this deployment task on C{node} using the C{client} provided.
+
+ @type node: L{Node}
+ @keyword node: Node to operate one
+
+ @type client: L{BaseSSHClient}
+ @keyword client: Connected SSH client to use.
+
+ @return: L{Node}
+ """
+ raise NotImplementedError, \
+ 'run not implemented for this deployment'
+
class SSHKeyDeployment(Deployment):
+ """
+ Installs a public SSH Key onto a host.
+ """
+
def __init__(self, key):
+ """
+ @type key: C{str}
+ @keyword key: Contents of the public key write
+ """
self.key = key
def run(self, node, client):
+ """
+ Installs SSH key into C{.ssh/authorized_keys}
+
+ See also L{Deployment.run}
+ """
client.put(".ssh/authorized_keys", contents=self.key)
return node
class ScriptDeployment(Deployment):
+ """
+ Runs an arbitrary Shell Script task.
+ """
+
def __init__(self, script, name=None, delete=False):
+ """
+ @type script: C{str}
+ @keyword script: Contents of the script to run
+
+ @type name: C{str}
+ @keyword name: Name of the script to upload it as, if not specified, a random name will be choosen.
+
+ @type delete: C{bool}
+ @keyword delete: Weither to delete the script on completion.
+ """
self.script = script
self.stdout = None
self.stderr = None
@@ -40,6 +85,11 @@ class ScriptDeployment(Deployment):
self.name = "/root/deployment_%s.sh" % (os.urandom(4).encode('hex'))
def run(self, node, client):
+ """
+ Uploads the shell script and then executes it.
+
+ See also L{Deployment.run}
+ """
client.put(path=self.name, chmod=755, contents=self.script)
self.stdout, self.stderr = client.run(self.name)
if self.delete:
@@ -47,16 +97,33 @@ class ScriptDeployment(Deployment):
return node
class MultiStepDeployment(Deployment):
+ """
+ Runs a chain of Deployment steps.
+ """
def __init__(self, add = None):
+ """
+ @type add: C{list}
+ @keyword add: Deployment steps to add.
+ """
self.steps = []
self.add(add)
def add(self, add):
+ """Add a deployment to this chain.
+
+ @type add: Single L{Deployment} or a C{list} of L{Deployment}
+ @keyword add: Adds this deployment to the others already in this object.
+ """
if add is not None:
add = add if isinstance(add, (list, tuple)) else [add]
self.steps.extend(add)
def run(self, node, client):
+ """
+ Run each deployment that has been added.
+
+ See also L{Deployment.run}
+ """
for s in self.steps:
node = s.run(node, client)
return node