libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pque...@apache.org
Subject svn commit: r917725 - in /incubator/libcloud/trunk/libcloud: base.py deployment.py
Date Mon, 01 Mar 2010 21:23:26 GMT
Author: pquerna
Date: Mon Mar  1 21:23:25 2010
New Revision: 917725

URL: http://svn.apache.org/viewvc?rev=917725&view=rev
Log:
Covert existing code to now use the ssh client wrapper classes

Modified:
    incubator/libcloud/trunk/libcloud/base.py
    incubator/libcloud/trunk/libcloud/deployment.py

Modified: incubator/libcloud/trunk/libcloud/base.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/base.py?rev=917725&r1=917724&r2=917725&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/base.py (original)
+++ incubator/libcloud/trunk/libcloud/base.py Mon Mar  1 21:23:25 2010
@@ -27,20 +27,14 @@
 from libcloud.interface import INodeSizeFactory, INodeSize
 from libcloud.interface import INodeImageFactory, INodeImage
 from libcloud.types import NodeState
+from libcloud.ssh import SSHClient
 import time
 import hashlib
 import StringIO
 import os
+import socket
 from pipes import quote as pquote
 
-have_paramiko = False
-
-try:
-    import paramiko
-    import socket
-    have_paramiko = True
-except ImportError:
-    pass
 
 class Node(object):
     """
@@ -588,10 +582,6 @@
 
     def deploy_node(self, **kwargs):
         # TODO: support ssh keys
-        if not have_paramiko:
-            raise NotImplementedError, \
-                'deploy_node requires paramiko to be installed.'
-
         password = None
 
         if 'generates_password' not in self.features["create_node"]:
@@ -624,24 +614,17 @@
             if node.public_ip is not None and node.public_ip != "" and node.state == NodeState.RUNNING:
                 break
 
-        client = paramiko.SSHClient()
-        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
-        #print 'connecting to '+ node.public_ip[0]
-        conp = {
-                'hostname': node.public_ip[0],
-                'port': 22,
-                'username': 'root',
-                'password': password,
-                'allow_agent': False,
-                'look_for_keys': False,
-                }
-
+        client = SSHClient(hostname=node.public_ip[0],
+                            port=22, username='root',
+                            password=password)
         laste = None
         while time.time() < end:
             laste = None
             try:
-                client.connect(**conp)
+                client.connect()
                 break
+            except IOError, e:
+                laste = e
             except socket.error, e:
                 laste = e
             time.sleep(10)

Modified: incubator/libcloud/trunk/libcloud/deployment.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/deployment.py?rev=917725&r1=917724&r2=917725&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/deployment.py (original)
+++ incubator/libcloud/trunk/libcloud/deployment.py Mon Mar  1 21:23:25 2010
@@ -19,51 +19,32 @@
 import os
 
 class Deployment(object):
-  pass
+    pass
 
 class SSHKeyDeployment(Deployment):
-  def __init__(self, key):
-    self.key = key
+    def __init__(self, key):
+        self.key = key
   
-  def run(self, node, client):
-    sftp = client.open_sftp()
-    sftp.mkdir(".ssh")
-    sftp.chdir(".ssh")
-    ak = sftp.file("authorized_keys",  mode='w')
-    ak.write(self.key)
-    ak.close()
-    sftp.close()
-    return node
+    def run(self, node, client):
+        client.put(".ssh/authorized_keys", contents=self.key)
+        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
+    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):
+        client.put(path=self.name, chmod=755, contents=self.script)
+        self.stdout, self.stderr = client.run(self.name)
+        if self.delete:
+            client.delete(self.name)
+        return node
 
 class MultiStepDeployment(Deployment):
   def __init__(self, add = None):



Mime
View raw message