libcloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pque...@apache.org
Subject svn commit: r917338 - /incubator/libcloud/trunk/libcloud/deployment.py
Date Mon, 01 Mar 2010 01:07:12 GMT
Author: pquerna
Date: Mon Mar  1 01:07:12 2010
New Revision: 917338

URL: http://svn.apache.org/viewvc?rev=917338&view=rev
Log:
Add Script and Multistep 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=917338&r1=917337&r2=917338&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/deployment.py (original)
+++ incubator/libcloud/trunk/libcloud/deployment.py Mon Mar  1 01:07:12 2010
@@ -16,11 +16,12 @@
 """
 Provides generic deployment steps for machines post boot.
 """
+import os
 
 class Deployment(object):
   pass
 
-class SSHDeployment(Deployment):
+class SSHKeyDeployment(Deployment):
   def __init__(self, key):
     self.key = key
   
@@ -32,4 +33,49 @@
     ak.write(self.key)
     ak.close()
     sftp.close()
-    return node
\ No newline at end of file
+    return node
+
+class ScriptDeployment(Deployment):
+  def __init__(self, script, name=None, delete=False):
+    self.script = script
+    self.stdout = None
+    self.stderr = None
+    self.delete = delete
+    self.name = name
+    if self.name is None:
+      self.name = "/root/deployment_%s.sh" % (os.urandom(4).encode('hex'))
+
+  def run(self, node, client):
+    sftp = client.open_sftp()
+    ak = sftp.file(self.name,  mode='w')
+    ak.write(self.script)
+    ak.chmod(755)
+    ak.close()
+    sftp.close()
+
+    stdin, stdout, stderr = client.exec_command(self.name)
+    stdin.close()
+    self.stdout = stdout.read()
+    self.stderr = stderr.read()
+
+    if self.delete:
+      sftp = client.open_sftp()
+      sftp.unlink(self.name)
+      sftp.close()
+
+    return node
+
+class MultiStepDeployment(Deployment):
+  def __init__(self, add = None):
+    self.steps = []
+    self.add(add)
+
+  def add(self, add):
+    if add is not None:
+      add = add if isinstance(add, (list, tuple)) else [add]
+      self.steps.extend(add)
+
+  def run(self, node, client):
+    for s in self.steps:
+      node = s.run(node, client)
+    return node



Mime
View raw message