You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2020/08/19 16:58:41 UTC

[libcloud] branch trunk updated: Add __str__ and __repr__ method to all the Deployment classes.

This is an automated email from the ASF dual-hosted git repository.

tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git


The following commit(s) were added to refs/heads/trunk by this push:
     new ecb8181  Add __str__ and __repr__ method to all the Deployment classes.
ecb8181 is described below

commit ecb8181c277f54cc47049f0b4c73977f828034d8
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Wed Aug 19 16:47:50 2020 +0200

    Add __str__ and __repr__ method to all the Deployment classes.
---
 libcloud/compute/deployment.py | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/libcloud/compute/deployment.py b/libcloud/compute/deployment.py
index 7850078..e0ea75f 100644
--- a/libcloud/compute/deployment.py
+++ b/libcloud/compute/deployment.py
@@ -91,6 +91,13 @@ class SSHKeyDeployment(Deployment):
         client.put(".ssh/authorized_keys", contents=self.key, mode='a')
         return node
 
+    def __str__(self):
+        return self.__repr__()
+
+    def __repr__(self):
+        key = self.key[:100]
+        return ("<SSHKeyDeployment key=%s...>" % (key))
+
 
 class FileDeployment(Deployment):
     """
@@ -125,6 +132,13 @@ class FileDeployment(Deployment):
                    contents=content)
         return node
 
+    def __str__(self):
+        return self.__repr__()
+
+    def __repr__(self):
+        return ("<FileDeployment source=%s, target=%s>" % (
+            self.source, self.target))
+
 
 class ScriptDeployment(Deployment):
     """
@@ -325,3 +339,16 @@ class MultiStepDeployment(Deployment):
         for s in self.steps:
             node = s.run(node, client)
         return node
+
+    def __str__(self):
+        return self.__repr__()
+
+    def __repr__(self):
+        steps = []
+
+        for step in self.steps:
+            steps.append(str(step))
+
+        steps = ', '.join(steps)
+
+        return ("<MultiStepDeployment steps=[%s]>" % (steps))