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 2014/08/20 18:20:58 UTC

[2/3] git commit: Update Node.__repr__ to display a friendly name for the state attribute.

Update Node.__repr__ to display a friendly name for the state attribute.


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/5544e75e
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/5544e75e
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/5544e75e

Branch: refs/heads/trunk
Commit: 5544e75ef2f9fce5d92fba7d04582699f69ba986
Parents: 298f5db
Author: Tomaz Muraus <to...@apache.org>
Authored: Wed Aug 20 17:02:07 2014 +0200
Committer: Tomaz Muraus <to...@apache.org>
Committed: Wed Aug 20 17:05:43 2014 +0200

----------------------------------------------------------------------
 libcloud/compute/base.py  |  4 +++-
 libcloud/compute/types.py | 14 ++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/5544e75e/libcloud/compute/base.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/base.py b/libcloud/compute/base.py
index a585128..c043706 100644
--- a/libcloud/compute/base.py
+++ b/libcloud/compute/base.py
@@ -251,9 +251,11 @@ class Node(UuidMixin):
         return self.driver.destroy_node(self)
 
     def __repr__(self):
+        state = NodeState.tostring(self.state)
+
         return (('<Node: uuid=%s, name=%s, state=%s, public_ips=%s, '
                  'private_ips=%s, provider=%s ...>')
-                % (self.uuid, self.name, self.state, self.public_ips,
+                % (self.uuid, self.name, state, self.public_ips,
                    self.private_ips, self.driver.name))
 
 

http://git-wip-us.apache.org/repos/asf/libcloud/blob/5544e75e/libcloud/compute/types.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/types.py b/libcloud/compute/types.py
index fbe9317..c7c7616 100644
--- a/libcloud/compute/types.py
+++ b/libcloud/compute/types.py
@@ -202,6 +202,20 @@ class NodeState(object):
     ERROR = 7
     PAUSED = 8
 
+    @classmethod
+    def tostring(cls, value):
+        values = cls.__dict__
+        values = dict([(key, string) for key, string in values.items() if
+                       not key.startswith('__')])
+
+        for item_key, item_value in values.items():
+            if value == item_value:
+                return item_key
+
+    @classmethod
+    def fromstring(cls, value):
+        return getattr(cls, value.upper(), None)
+
 
 class Architecture(object):
     """