in libcloud/compute/drivers/nttcis.py [0:0]
def _to_node(self, element):
# Get all information at once and process in common/nttcis
# Below, future to dynamically generate classes
# return process_xml(ET.tostring(element))
started = findtext(element, "started", TYPES_URN)
status = self._to_status(element.find(fixxpath("progress", TYPES_URN)))
dd_state = findtext(element, "state", TYPES_URN)
node_state = self._get_node_state(dd_state, started, status.action)
has_network_info = element.find(fixxpath("networkInfo", TYPES_URN)) is not None
cpu_spec = self._to_cpu_spec(element.find(fixxpath("cpu", TYPES_URN)))
has_snapshot = element.find(fixxpath("snapshotService", TYPES_URN)) is not None
has_scsi = element.find(fixxpath("scsiController", TYPES_URN)) is not None
has_sata = element.find(fixxpath("sataController", TYPES_URN)) is not None
has_ide = element.find(fixxpath("ideController")) is not None
scsi_controllers = []
disks = []
if has_scsi:
scsi_controllers.append(
self._to_scsi_controllers(element.find(fixxpath("scsiController", TYPES_URN)))
)
for scsi in element.findall(fixxpath("scsiController", TYPES_URN)):
disks.extend(self._to_disks(scsi))
if has_sata:
for sata in element.findall(fixxpath("sataController", TYPES_URN)):
disks.extend(self._to_disks(sata))
if has_ide:
for ide in element.findall(fixxpath("ideController", TYPES_URN)):
disks.extend(self._to_snapshot(ide))
# Vmware Tools
# Version 2.3 or earlier
if LooseVersion(self.connection.active_api_version) < LooseVersion("2.4"):
vmware_tools = self._to_vmware_tools(element.find(fixxpath("vmwareTools", TYPES_URN)))
operation_system = element.find(fixxpath("operatingSystem", TYPES_URN))
# Version 2.4 or later
else:
# vmtools_elm = fixxpath('guest/vmTools', TYPES_URN)
vmtools_elm = element.find(fixxpath("guest/vmTools", TYPES_URN))
if vmtools_elm is not None:
vmware_tools = self._to_vmware_tools(vmtools_elm)
else:
vmware_tools = NttCisServerVMWareTools(
status=None, version_status=None, api_version=None
)
operation_system = element.find(fixxpath("guest/operatingSystem", TYPES_URN))
extra = {
"description": findtext(element, "description", TYPES_URN),
"sourceImageId": findtext(element, "sourceImageId", TYPES_URN),
"networkId": findtext(element, "networkId", TYPES_URN),
"networkDomainId": (
element.find(fixxpath("networkInfo", TYPES_URN)).get("networkDomainId")
if has_network_info
else None
),
"datacenterId": element.get("datacenterId"),
"deployedTime": findtext(element, "createTime", TYPES_URN),
"window": (
(
element.find(fixxpath("snapshotService/window", TYPES_URN)).get("dayOfWeek"),
element.find(fixxpath("snapshotService/window", TYPES_URN)).get("startHour"),
)
if has_snapshot
else None
),
"cpu": cpu_spec,
"memoryMb": int(findtext(element, "memoryGb", TYPES_URN)) * 1024,
"OS_id": operation_system.get("id"),
"OS_type": operation_system.get("family"),
"OS_displayName": operation_system.get("displayName"),
"status": status,
"scsi_controller": scsi_controllers,
"disks": disks,
"vmWareTools": vmware_tools,
}
public_ip = findtext(element, "publicIpAddress", TYPES_URN)
private_ip = (
element.find(fixxpath("networkInfo/primaryNic", TYPES_URN)).get("privateIpv4")
if has_network_info
else element.find(fixxpath("nic", TYPES_URN)).get("privateIpv4")
)
extra["ipv6"] = (
element.find(fixxpath("networkInfo/primaryNic", TYPES_URN)).get("ipv6")
if has_network_info
else element.find(fixxpath("nic", TYPES_URN)).get("ipv6")
)
n = Node(
id=element.get("id"),
name=findtext(element, "name", TYPES_URN),
state=node_state,
public_ips=[public_ip] if public_ip is not None else [],
private_ips=[private_ip] if private_ip is not None else [],
size=self.list_sizes()[0],
image=NodeImage(
extra["sourceImageId"], extra["OS_displayName"], self.connection.driver
),
driver=self.connection.driver,
extra=extra,
)
return n