SmartConnectNoSSL -> disableSslCertValidation=True
This commit is contained in:
parent
b982a56f90
commit
4cd15a9423
@ -23,6 +23,7 @@ echo "Trying to apply role \"$ROLE\" to host/group \"$HOST_PATTERN\"..."
|
||||
ansible-playbook "$@" /dev/stdin <<END
|
||||
---
|
||||
- hosts: $HOST_PATTERN
|
||||
become: yes
|
||||
roles:
|
||||
- $ROLE
|
||||
END
|
||||
|
||||
116
check_vcenter_datastore
Executable file
116
check_vcenter_datastore
Executable file
@ -0,0 +1,116 @@
|
||||
#!/usr/bin/env python3
|
||||
from pyVmomi import vim
|
||||
import pyVim.connect
|
||||
import atexit
|
||||
import argparse
|
||||
import re
|
||||
import siteconf
|
||||
|
||||
site_conf = siteconf.read()
|
||||
|
||||
|
||||
def get_args():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Set VM network')
|
||||
|
||||
parser.add_argument('-s', '--site',
|
||||
required=True,
|
||||
action='store',
|
||||
help='name of the site to connect to')
|
||||
parser.add_argument('-d', '--datastore',
|
||||
required=True,
|
||||
action='store',
|
||||
help='datastore name')
|
||||
parser.add_argument('-W', '--warning',
|
||||
required=False,
|
||||
action='store',
|
||||
default='20%',
|
||||
help='warning if less free space (nnn%, or nnn[GT]B, default: TB)')
|
||||
parser.add_argument('-C', '--critical',
|
||||
required=False,
|
||||
action='store',
|
||||
default='10%',
|
||||
help='critical if less free space')
|
||||
|
||||
args = parser.parse_args()
|
||||
return args
|
||||
|
||||
def get_datastore(content, name):
|
||||
obj_view = content.viewManager.CreateContainerView(
|
||||
content.rootFolder, [vim.Datastore], True)
|
||||
ds_list = obj_view.view
|
||||
obj_view.Destroy()
|
||||
for ds in ds_list:
|
||||
if not ds.summary.accessible:
|
||||
continue
|
||||
if ds.summary.name == name:
|
||||
return ds
|
||||
return None
|
||||
|
||||
def less_free(ds, minimum):
|
||||
cap = ds.summary.capacity
|
||||
free = ds.summary.freeSpace
|
||||
ratio = free / cap
|
||||
if m := re.match("([0-9.]+)%$", minimum):
|
||||
min_ratio = float(m[1]) / 100
|
||||
#print(f"min_ratio: {min_ratio}")
|
||||
if ratio < min_ratio:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
elif m := re.match("([0-9.]+)([GT]B?)$", minimum):
|
||||
min_n, unit = float(m[1]), m[2]
|
||||
if unit[0] == 'G':
|
||||
min_n *= 1024**3
|
||||
if unit[0] == 'T':
|
||||
min_n *= 1024**4
|
||||
else:
|
||||
min_n = float(min_n) * 1024**4 # TB
|
||||
#print(f"min_n: {min_n}")
|
||||
if ds.summary.freeSpace < min_n:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
args = get_args()
|
||||
|
||||
if not args.site in site_conf:
|
||||
print(f"site not found: {args.site}")
|
||||
exit(1)
|
||||
|
||||
host = site_conf[args.site]['vcenter']
|
||||
user = site_conf[args.site]['vcenter_user']
|
||||
passwd = site_conf[args.site]['vcenter_passwd']
|
||||
|
||||
si = pyVim.connect.SmartConnect(
|
||||
host = host,
|
||||
user = user,
|
||||
pwd = passwd,
|
||||
disableSslCertValidation = True
|
||||
)
|
||||
atexit.register(pyVim.connect.Disconnect, si)
|
||||
content = si.RetrieveContent()
|
||||
ds = get_datastore(content, args.datastore)
|
||||
if ds == None:
|
||||
print(f"UNKNOWN: datastore {args.site} | {args.datastore} not found.")
|
||||
exit(3)
|
||||
cap = ds.summary.capacity / 1024**4
|
||||
free = ds.summary.freeSpace / 1024**4
|
||||
ratio = free / cap
|
||||
text = f"{ds.summary.name} {ratio:.0%} free: {free:.3f} TB / {cap:.3f} TB"
|
||||
if less_free(ds, args.critical):
|
||||
print(f"CRITICAL: {text}")
|
||||
exit(2)
|
||||
elif less_free(ds, args.warning):
|
||||
print(f"WARNING: {text}")
|
||||
exit(1)
|
||||
else:
|
||||
print(f"OK: {text}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
# vim: set tabstop=4 shiftwidth=4 expandtab smarttab:
|
||||
@ -31,10 +31,11 @@ def main():
|
||||
user = site_conf[args.site]['vcenter_user']
|
||||
passwd = site_conf[args.site]['vcenter_passwd']
|
||||
|
||||
si = pyVim.connect.SmartConnectNoSSL(
|
||||
si = pyVim.connect.SmartConnect(
|
||||
host = host,
|
||||
user = user,
|
||||
pwd = passwd
|
||||
pwd = passwd,
|
||||
disableSslCertValidation = True
|
||||
)
|
||||
atexit.register(pyVim.connect.Disconnect, si)
|
||||
content = si.RetrieveContent()
|
||||
|
||||
@ -40,10 +40,11 @@ def main():
|
||||
user = site_conf[args.site]['vcenter_user']
|
||||
passwd = site_conf[args.site]['vcenter_passwd']
|
||||
|
||||
si = pyVim.connect.SmartConnectNoSSL(
|
||||
si = pyVim.connect.SmartConnect(
|
||||
host = host,
|
||||
user = user,
|
||||
pwd = passwd
|
||||
pwd = passwd,
|
||||
disableSslCertValidation = True
|
||||
)
|
||||
atexit.register(pyVim.connect.Disconnect, si)
|
||||
content = si.RetrieveContent()
|
||||
|
||||
@ -66,10 +66,11 @@ def main():
|
||||
user = site_conf[args.site]['vcenter_user']
|
||||
passwd = site_conf[args.site]['vcenter_passwd']
|
||||
|
||||
si = pyVim.connect.SmartConnectNoSSL(
|
||||
si = pyVim.connect.SmartConnect(
|
||||
host = host,
|
||||
user = user,
|
||||
pwd = passwd
|
||||
pwd = passwd,
|
||||
disableSslCertValidation = True
|
||||
)
|
||||
atexit.register(pyVim.connect.Disconnect, si)
|
||||
content = si.RetrieveContent()
|
||||
|
||||
@ -62,10 +62,11 @@ def main():
|
||||
user = site_conf[args.site]['vcenter_user']
|
||||
passwd = site_conf[args.site]['vcenter_passwd']
|
||||
|
||||
si = pyVim.connect.SmartConnectNoSSL(
|
||||
si = pyVim.connect.SmartConnect(
|
||||
host = host,
|
||||
user = user,
|
||||
pwd = passwd
|
||||
pwd = passwd,
|
||||
disableSslCertValidation = True
|
||||
)
|
||||
atexit.register(pyVim.connect.Disconnect, si)
|
||||
content = si.RetrieveContent()
|
||||
|
||||
@ -90,10 +90,11 @@ def main():
|
||||
exit(1)
|
||||
#print(f"host {host} user {user} passwd {passwd}")
|
||||
|
||||
si = pyVim.connect.SmartConnectNoSSL(
|
||||
si = pyVim.connect.SmartConnect(
|
||||
host = host,
|
||||
user = user,
|
||||
pwd = passwd
|
||||
pwd = passwd,
|
||||
disableSslCertValidation = True
|
||||
)
|
||||
atexit.register(pyVim.connect.Disconnect, si)
|
||||
content = si.RetrieveContent()
|
||||
|
||||
@ -72,10 +72,11 @@ def main():
|
||||
passwd = site_conf[args.site]['vcenter_passwd']
|
||||
|
||||
|
||||
si = pyVim.connect.SmartConnectNoSSL(
|
||||
si = pyVim.connect.SmartConnect(
|
||||
host = host,
|
||||
user = user,
|
||||
pwd = passwd
|
||||
pwd = passwd,
|
||||
disableSslCertValidation = True
|
||||
)
|
||||
atexit.register(pyVim.connect.Disconnect, si)
|
||||
content = si.RetrieveContent()
|
||||
|
||||
142
vmw_vcenter_data
Executable file
142
vmw_vcenter_data
Executable file
@ -0,0 +1,142 @@
|
||||
#!/usr/bin/env python3
|
||||
from pyVmomi import vim
|
||||
import pyVim.connect
|
||||
import atexit
|
||||
import argparse
|
||||
#import time
|
||||
import json
|
||||
import siteconf
|
||||
|
||||
site_conf = siteconf.read()
|
||||
|
||||
|
||||
def get_args():
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Set VM network')
|
||||
|
||||
parser.add_argument('-s', '--site',
|
||||
required=True,
|
||||
action='store',
|
||||
help='name of the site to connect to')
|
||||
parser.add_argument('--list-datastores',
|
||||
required=False,
|
||||
action='store_true',
|
||||
help='list all accessable datastores')
|
||||
parser.add_argument('--list-config',
|
||||
required=False,
|
||||
action='store_true',
|
||||
help='list relevant configuration')
|
||||
|
||||
args = parser.parse_args()
|
||||
return args
|
||||
|
||||
def get_datastores(content):
|
||||
obj_view = content.viewManager.CreateContainerView(
|
||||
content.rootFolder, [vim.Datastore], True)
|
||||
ds_list = obj_view.view
|
||||
obj_view.Destroy()
|
||||
result = []
|
||||
for ds in ds_list:
|
||||
if not ds.summary.accessible:
|
||||
continue
|
||||
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 list_datastores(content):
|
||||
# datastores = get_datastores(content)
|
||||
# for ds in datastores:
|
||||
# cap = ds.summary.capacity / 1024**4
|
||||
# free = ds.summary.freeSpace / 1024**4
|
||||
# ratio = free / cap
|
||||
# print(f"{ds.summary.name} {ratio:.0%} {free:.3f} TB / {cap:.3f} TB")
|
||||
|
||||
|
||||
def main():
|
||||
args = get_args()
|
||||
|
||||
if not args.site in site_conf:
|
||||
print(f"site not found: {args.site}")
|
||||
exit(1)
|
||||
|
||||
host = site_conf[args.site]['vcenter']
|
||||
user = site_conf[args.site]['vcenter_user']
|
||||
passwd = site_conf[args.site]['vcenter_passwd']
|
||||
|
||||
si = pyVim.connect.SmartConnect(
|
||||
host = host,
|
||||
user = user,
|
||||
pwd = passwd,
|
||||
disableSslCertValidation = True
|
||||
)
|
||||
atexit.register(pyVim.connect.Disconnect, si)
|
||||
content = si.RetrieveContent()
|
||||
if args.list_datastores:
|
||||
datastores = get_datastores(content)
|
||||
names = []
|
||||
for ds in datastores:
|
||||
names.append(ds.summary.name)
|
||||
names.sort()
|
||||
print(names)
|
||||
elif args.list_config:
|
||||
print({
|
||||
'vcenter_addr': site_conf[args.site]['vcenter'],
|
||||
'vcenter_user': site_conf[args.site]['vcenter_user']
|
||||
});
|
||||
else:
|
||||
print("No command given.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
# vim: set tabstop=4 shiftwidth=4 expandtab smarttab:
|
||||
|
||||
####!/usr/bin/env python3
|
||||
###import argparse
|
||||
###import siteconf
|
||||
###
|
||||
###site_conf = siteconf.read()
|
||||
###
|
||||
###
|
||||
###def get_args():
|
||||
### parser = argparse.ArgumentParser(
|
||||
### description='Set VM network')
|
||||
###
|
||||
### parser.add_argument('-s', '--site',
|
||||
### required=True,
|
||||
### action='store',
|
||||
### help='name of the site to connect to')
|
||||
###
|
||||
### args = parser.parse_args()
|
||||
### return args
|
||||
###
|
||||
###
|
||||
###
|
||||
###def main():
|
||||
### args = get_args()
|
||||
###
|
||||
### if not args.site in site_conf:
|
||||
### print(f"site not found: {args.site}")
|
||||
### exit(1)
|
||||
###
|
||||
### vms = get_vms(content)
|
||||
### for vm in vms:
|
||||
### for d in vm.config.hardware.device:
|
||||
### if hasattr(d, 'macAddress'):
|
||||
### print(f'{d.macAddress} {vm.name}')
|
||||
###
|
||||
###
|
||||
###
|
||||
###
|
||||
###if __name__ == "__main__":
|
||||
### main()
|
||||
###
|
||||
#### vim: set tabstop=4 shiftwidth=4 expandtab smarttab:
|
||||
@ -62,10 +62,11 @@ def main():
|
||||
user = site_conf[args.site]['vcenter_user']
|
||||
passwd = site_conf[args.site]['vcenter_passwd']
|
||||
|
||||
si = pyVim.connect.SmartConnectNoSSL(
|
||||
si = pyVim.connect.SmartConnect(
|
||||
host = host,
|
||||
user = user,
|
||||
pwd = passwd
|
||||
pwd = passwd,
|
||||
disableSslCertValidation = True
|
||||
)
|
||||
atexit.register(pyVim.connect.Disconnect, si)
|
||||
content = si.RetrieveContent()
|
||||
|
||||
@ -71,10 +71,11 @@ def main():
|
||||
exit(1)
|
||||
#print(f"host {host} user {user} passwd {passwd}")
|
||||
|
||||
si = pyVim.connect.SmartConnectNoSSL(
|
||||
si = pyVim.connect.SmartConnect(
|
||||
host = host,
|
||||
user = user,
|
||||
pwd = passwd
|
||||
pwd = passwd,
|
||||
disableSslCertValidation = True
|
||||
)
|
||||
atexit.register(pyVim.connect.Disconnect, si)
|
||||
content = si.RetrieveContent()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user