better local disk detection for multipath, vmw_vcenter_data host list
This commit is contained in:
parent
3945f50999
commit
6e9598996f
@ -58,6 +58,8 @@ class Main:
|
|||||||
ds = canonical_datastore.get(lun.canonicalName)
|
ds = canonical_datastore.get(lun.canonicalName)
|
||||||
if not ds:
|
if not ds:
|
||||||
continue # not a datastore
|
continue # not a datastore
|
||||||
|
if lun.localDisk:
|
||||||
|
ds['local'] = True
|
||||||
#print(f"uuid {lun.uuid} name {ds['name']} local {ds['local']}")
|
#print(f"uuid {lun.uuid} name {ds['name']} local {ds['local']}")
|
||||||
self.uuid_datastore[lun.uuid] = ds
|
self.uuid_datastore[lun.uuid] = ds
|
||||||
|
|
||||||
@ -89,9 +91,9 @@ class Main:
|
|||||||
if ds['local']:
|
if ds['local']:
|
||||||
minpath = 1
|
minpath = 1
|
||||||
prefix = f"{ds['name']} (local)"
|
prefix = f"{ds['name']} (local)"
|
||||||
elif re.search(r'-local\d?$', ds['name']):
|
#elif re.search(r'-local\d?$', ds['name']):
|
||||||
minpath = 1
|
# minpath = 1
|
||||||
prefix = f"{ds['name']} (local-by-name)"
|
# prefix = f"{ds['name']} (local-by-name)"
|
||||||
else:
|
else:
|
||||||
minpath = 2
|
minpath = 2
|
||||||
prefix = f"{ds['name']}"
|
prefix = f"{ds['name']}"
|
||||||
|
|||||||
@ -22,6 +22,10 @@ def get_args():
|
|||||||
required=False,
|
required=False,
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='list all accessable datastores')
|
help='list all accessable datastores')
|
||||||
|
parser.add_argument('--list-hosts',
|
||||||
|
required=False,
|
||||||
|
action='store_true',
|
||||||
|
help='list all hosts')
|
||||||
parser.add_argument('--list-config',
|
parser.add_argument('--list-config',
|
||||||
required=False,
|
required=False,
|
||||||
action='store_true',
|
action='store_true',
|
||||||
@ -42,13 +46,13 @@ def get_datastores(content):
|
|||||||
result.append(ds)
|
result.append(ds)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
#def get_all_objs(content, vimtype):
|
def get_all_objs(content, vimtype):
|
||||||
# obj = {}
|
obj = {}
|
||||||
# container = content.viewManager.CreateContainerView(
|
container = content.viewManager.CreateContainerView(
|
||||||
# content.rootFolder, vimtype, True)
|
content.rootFolder, vimtype, True)
|
||||||
# for managed_object_ref in container.view:
|
for managed_object_ref in container.view:
|
||||||
# obj.update({managed_object_ref: managed_object_ref.name})
|
obj.update({managed_object_ref: managed_object_ref.name})
|
||||||
# return obj
|
return obj
|
||||||
|
|
||||||
#def list_datastores(content):
|
#def list_datastores(content):
|
||||||
# datastores = get_datastores(content)
|
# datastores = get_datastores(content)
|
||||||
@ -78,13 +82,27 @@ def main():
|
|||||||
)
|
)
|
||||||
atexit.register(pyVim.connect.Disconnect, si)
|
atexit.register(pyVim.connect.Disconnect, si)
|
||||||
content = si.RetrieveContent()
|
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)
|
datastores = get_datastores(content)
|
||||||
names = []
|
names = []
|
||||||
for ds in datastores:
|
for ds in datastores:
|
||||||
names.append(ds.summary.name)
|
names.append(ds.summary.name)
|
||||||
names.sort()
|
names.sort()
|
||||||
print(names)
|
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:
|
elif args.list_config:
|
||||||
print({
|
print({
|
||||||
'vcenter_addr': site_conf[args.site]['vcenter'],
|
'vcenter_addr': site_conf[args.site]['vcenter'],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user