vsphere_inventory.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:vsphere_ansible_inventory 作者: mikesimos 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号