libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [2/3] git commit: Update Node.__repr__ to display a friendly name for the state attribute.
Date Wed, 20 Aug 2014 16:20:58 GMT
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 <tomaz@apache.org>
Authored: Wed Aug 20 17:02:07 2014 +0200
Committer: Tomaz Muraus <tomaz@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):
     """


Mime
View raw message