def main():
# - Get command line args and config args.
args = get_args()
(filters, cache_path, cache_ttl, vcenter_host, vsphere_user, vsphere_pass, vsphere_port, cert_check) \
= parse_config()
# - Override settings with arg parameters if defined
if not args.password:
if not vsphere_pass:
import getpass
vsphere_pass = getpass.getpass()
setattr(args, 'password', vsphere_pass)
if not args.username:
setattr(args, 'username', vsphere_user)
if not args.hostname:
setattr(args, 'hostname', vcenter_host)
if not args.port:
setattr(args, 'port', vsphere_port)
if not args.no_cert_check:
setattr(args, 'cert_check', cert_check)
else:
setattr(args, 'cert_check', False)
# - Perform requested operations (list, host/guest, reload cache)
if args.host or args.guest:
print ('{}')
exit(0)
elif args.list or args.reload_cache:
v = VSphere(args.hostname, args.username, args.password, vsphere_port=443, cert_check=args.cert_check)
data = v.cached_inventory(filters, cache_path=cache_path, cache_ttl=cache_ttl, refresh=args.reload_cache)
print ("{}".format(dumps(data)))
exit(0)
vsphere_inventory.py 文件源码
python
阅读 27
收藏 0
点赞 0
评论 0
评论列表
文章目录