in libcloud/compute/drivers/vcloud.py [0:0]
def _to_node(self, node_elm):
# Parse snapshots and VMs as extra
if node_elm.find(fixxpath(node_elm, "SnapshotSection")) is None:
snapshots = None
else:
snapshots = []
for snapshot_elem in node_elm.findall(fixxpath(node_elm, "SnapshotSection/Snapshot")):
snapshots.append(
{
"created": snapshot_elem.get("created"),
"poweredOn": snapshot_elem.get("poweredOn"),
"size": snapshot_elem.get("size"),
}
)
vms = []
for vm_elem in node_elm.findall(fixxpath(node_elm, "Children/Vm")):
public_ips = []
private_ips = []
xpath = fixxpath(vm_elem, "NetworkConnectionSection/NetworkConnection")
for connection in vm_elem.findall(xpath):
ip = connection.find(fixxpath(connection, "IpAddress"))
if ip is not None:
private_ips.append(ip.text)
external_ip = connection.find(fixxpath(connection, "ExternalIpAddress"))
if external_ip is not None:
public_ips.append(external_ip.text)
elif ip is not None:
public_ips.append(ip.text)
xpath = "{http://schemas.dmtf.org/ovf/envelope/1}" "OperatingSystemSection"
os_type_elem = vm_elem.find(xpath)
if os_type_elem is not None:
os_type = os_type_elem.get("{http://www.vmware.com/schema/ovf}osType")
else:
os_type = None
vm = {
"id": vm_elem.get("href"),
"name": vm_elem.get("name"),
"state": self.NODE_STATE_MAP[vm_elem.get("status")],
"public_ips": public_ips,
"private_ips": private_ips,
"os_type": os_type,
}
vms.append(vm)
# Take the node IP addresses from all VMs
public_ips = []
private_ips = []
for vm in vms:
public_ips.extend(vm["public_ips"])
private_ips.extend(vm["private_ips"])
# Find vDC
vdc_id = next(
link.get("href")
for link in node_elm.findall(fixxpath(node_elm, "Link"))
if link.get("type") == "application/vnd.vmware.vcloud.vdc+xml"
) # pylint: disable=no-member
vdc = next(vdc for vdc in self.vdcs if vdc.id == vdc_id)
extra = {"vdc": vdc.name, "vms": vms}
description = node_elm.find(fixxpath(node_elm, "Description"))
if description is not None:
extra["description"] = description.text
else:
extra["description"] = ""
lease_settings = node_elm.find(fixxpath(node_elm, "LeaseSettingsSection"))
if lease_settings is not None:
extra["lease_settings"] = Lease.to_lease(lease_settings)
else:
extra["lease_settings"] = None
if snapshots is not None:
extra["snapshots"] = snapshots
node = Node(
id=node_elm.get("href"),
name=node_elm.get("name"),
state=self.NODE_STATE_MAP[node_elm.get("status")],
public_ips=public_ips,
private_ips=private_ips,
driver=self.connection.driver,
extra=extra,
)
return node