in libcloud/compute/drivers/vsphere.py [0:0]
def _to_node(self, vm):
name = vm.get("summary.config.name")
path = vm.get("summary.config.vmPathName")
memory = vm.get("summary.config.memorySizeMB")
cpus = vm.get("summary.config.numCpu")
disk = vm.get("summary.storage.committed", 0) // (1024**3)
id_to_hash = str(memory) + str(cpus) + str(disk)
size_id = hashlib.md5(id_to_hash.encode("utf-8")).hexdigest() # nosec
size_name = name + "-size"
size_extra = {"cpus": cpus}
driver = self
size = NodeSize(
id=size_id,
name=size_name,
ram=memory,
disk=disk,
bandwidth=0,
price=0,
driver=driver,
extra=size_extra,
)
operating_system = vm.get("summary.config.guestFullName")
host = vm.get("summary.runtime.host")
os_type = "unix"
if "Microsoft" in str(operating_system):
os_type = "windows"
uuid = vm.get("summary.config.instanceUuid") or (
vm.get("obj").config and vm.get("obj").config.instanceUuid
)
if not uuid:
logger.error("No uuid for vm: {}".format(vm))
annotation = vm.get("summary.config.annotation")
state = vm.get("summary.runtime.powerState")
status = self.NODE_STATE_MAP.get(state, NodeState.UNKNOWN)
boot_time = vm.get("summary.runtime.bootTime")
ip_addresses = []
if vm.get("summary.guest.ipAddress"):
ip_addresses.append(vm.get("summary.guest.ipAddress"))
overall_status = str(vm.get("summary.overallStatus"))
public_ips = []
private_ips = []
extra = {
"path": path,
"operating_system": operating_system,
"os_type": os_type,
"memory_MB": memory,
"cpus": cpus,
"overall_status": overall_status,
"metadata": {},
"snapshots": [],
}
if disk:
extra["disk"] = disk
if host:
extra["host"] = host.name
parent = host.parent
while parent:
if isinstance(parent, vim.ClusterComputeResource):
extra["cluster"] = parent.name
break
parent = parent.parent
if boot_time:
extra["boot_time"] = boot_time.isoformat()
if annotation:
extra["annotation"] = annotation
for ip_address in ip_addresses:
try:
if is_public_subnet(ip_address):
public_ips.append(ip_address)
else:
private_ips.append(ip_address)
except Exception:
# IPV6 not supported
pass
if vm.get("snapshot"):
extra["snapshots"] = format_snapshots(
recurse_snapshots(vm.get("snapshot").rootSnapshotList)
)
for custom_field in vm.get("customValue", []):
key_id = custom_field.key
key = self.find_custom_field_key(key_id)
extra["metadata"][key] = custom_field.value
node = Node(
id=uuid,
name=name,
state=status,
size=size,
public_ips=public_ips,
private_ips=private_ips,
driver=self,
extra=extra,
)
node._uuid = uuid
return node