better local disk detection for multipath, vmw_vcenter_data host list

This commit is contained in:
ROTTLER Tamas 2025-09-08 21:59:37 +02:00
parent 3945f50999
commit 6e9598996f
2 changed files with 31 additions and 11 deletions

View File

@ -58,6 +58,8 @@ class Main:
ds = canonical_datastore.get(lun.canonicalName)
if not ds:
continue # not a datastore
if lun.localDisk:
ds['local'] = True
#print(f"uuid {lun.uuid} name {ds['name']} local {ds['local']}")
self.uuid_datastore[lun.uuid] = ds
@ -89,9 +91,9 @@ class Main:
if ds['local']:
minpath = 1
prefix = f"{ds['name']} (local)"
elif re.search(r'-local\d?$', ds['name']):
minpath = 1
prefix = f"{ds['name']} (local-by-name)"
#elif re.search(r'-local\d?$', ds['name']):
# minpath = 1
# prefix = f"{ds['name']} (local-by-name)"
else:
minpath = 2
prefix = f"{ds['name']}"

View File

@ -22,6 +22,10 @@ def get_args():
required=False,
action='store_true',
help='list all accessable datastores')
parser.add_argument('--list-hosts',
required=False,
action='store_true',
help='list all hosts')
parser.add_argument('--list-config',
required=False,
action='store_true',
@ -42,13 +46,13 @@ def get_datastores(content):
result.append(ds)
return result
#def get_all_objs(content, vimtype):
# obj = {}
# container = content.viewManager.CreateContainerView(
# content.rootFolder, vimtype, True)
# for managed_object_ref in container.view:
# obj.update({managed_object_ref: managed_object_ref.name})
# return obj
def get_all_objs(content, vimtype):
obj = {}
container = content.viewManager.CreateContainerView(
content.rootFolder, vimtype, True)
for managed_object_ref in container.view:
obj.update({managed_object_ref: managed_object_ref.name})
return obj
#def list_datastores(content):
# datastores = get_datastores(content)
@ -78,13 +82,27 @@ def main():
)
atexit.register(pyVim.connect.Disconnect, si)
content = si.RetrieveContent()
if args.list_datastores:
if args.list_datastores + args.list_hosts + args.list_config > 1:
print("More than 1 command given.")
elif args.list_datastores:
datastores = get_datastores(content)
names = []
for ds in datastores:
names.append(ds.summary.name)
names.sort()
print(names)
elif args.list_hosts:
hosts = get_all_objs(content, [vim.HostSystem])
hostlist = {}
for h in hosts:
hostlist[hosts[h]] = {
'connectionState': h.runtime.connectionState,
'powerState': h.runtime.powerState,
'standbyMode': h.runtime.standbyMode,
'inMaintenanceMode': h.runtime.inMaintenanceMode,
'inQuarantineMode': h.runtime.inQuarantineMode,
}
print(hostlist)
elif args.list_config:
print({
'vcenter_addr': site_conf[args.site]['vcenter'],