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/01/12 23:07:03 UTC
[3/5] git commit: Add and use _to_nodes and _to_node method.
Add and use _to_nodes and _to_node method.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/7012c6d1
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/7012c6d1
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/7012c6d1
Branch: refs/heads/trunk
Commit: 7012c6d17d064df01b899d90cc8ac0b19a6c3e51
Parents: 4aeb37c
Author: Tomaz Muraus <to...@apache.org>
Authored: Sun Jan 12 22:04:30 2014 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Sun Jan 12 22:04:30 2014 +0100
----------------------------------------------------------------------
libcloud/compute/drivers/libvirt_driver.py | 43 ++++++++++++-------------
1 file changed, 21 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/libcloud/blob/7012c6d1/libcloud/compute/drivers/libvirt_driver.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/libvirt_driver.py b/libcloud/compute/drivers/libvirt_driver.py
index 644902f..a9cc6fc 100644
--- a/libcloud/compute/drivers/libvirt_driver.py
+++ b/libcloud/compute/drivers/libvirt_driver.py
@@ -62,28 +62,7 @@ class LibvirtNodeDriver(NodeDriver):
def list_nodes(self):
domains = self.connection.listAllDomains()
-
- nodes = []
- for domain in domains:
- state, max_mem, memory, vcpu_count, used_cpu_time = domain.info()
-
- if state in self.NODE_STATE_MAP:
- state = self.NODE_STATE_MAP[state]
- else:
- state = NodeState.UNKNOWN
-
- # TODO: Use XML config to get Mac address and then parse ips
- extra = {'uuid': domain.UUIDString(), 'os_type': domain.OSType(),
- 'types': self.connection.getType(),
- 'used_memory': memory / 1024, 'vcpu_count': vcpu_count,
- 'used_cpu_time': used_cpu_time}
-
- node = Node(id=domain.ID(), name=domain.name(), state=state,
- public_ips=[], private_ips=[], driver=self,
- extra=extra)
- node._uuid = domain.UUIDString() # we want to use a custom UUID
- nodes.append(node)
-
+ nodes = self._to_nodes(domains=domains)
return nodes
def reboot_node(self, node):
@@ -142,6 +121,26 @@ class LibvirtNodeDriver(NodeDriver):
domain = self._get_domain_for_node(node=node)
return domain.resume() == 0
+ def _to_nodes(self, domains):
+ nodes = [self._to_node(domain=domain) for domain in domains]
+ return nodes
+
+ def _to_node(self, domain):
+ state, max_mem, memory, vcpu_count, used_cpu_time = domain.info()
+ state = self.NODE_STATE_MAP.get(state, NodeState.UNKNOWN)
+
+ # TODO: Use XML config to get Mac address and then parse ips
+ extra = {'uuid': domain.UUIDString(), 'os_type': domain.OSType(),
+ 'types': self.connection.getType(),
+ 'used_memory': memory / 1024, 'vcpu_count': vcpu_count,
+ 'used_cpu_time': used_cpu_time}
+
+ node = Node(id=domain.ID(), name=domain.name(), state=state,
+ public_ips=[], private_ips=[], driver=self,
+ extra=extra)
+ node._uuid = domain.UUIDString() # we want to use a custom UUID
+ return node
+
def _get_domain_for_node(self, node):
"""
Return libvirt domain object for the provided node.