#!/usr/bin/env python
# vsphere-repl --- interactive python interpreter with hostd connection

# Author: Noah Friedman <friedman@splode.com>
# Created: 2018-09-05
# Public domain

# $Id: vsphere-repl,v 1.4 2018/10/04 15:51:05 friedman Exp $

# Commentary:
# Code:

from   __future__ import print_function

import sys
import code
import subprocess
import pprint
import vspherelib     as vsl
from   pyVmomi    import vim, vmodl


args = vsl.ArgumentParser( loadrc=True ).parse()
vsi  = vsl.vmomiConnect( args )

def restart():
    reload( vsl )
    global vsi
    vsi = vsl.vmomiConnect( args )

repl_pp = pprint.PrettyPrinter( indent=2, width=40 )
def pp( *args, **kwargs ):
    for arg in args:
        repl_pp.pprint( arg, **kwargs )

def bt( cmd ):
    return subprocess.check_output( [cmd] ).rstrip( ' \t\r\n' )

if __name__ == '__main__':
    # Don't display 'None' if there is nothing to display.
    sys.displayhook = lambda arg: (arg is None) or pp( arg )
    code.interact(
        banner = '{} {} | {}'.format(
            vsi.si.content.about.apiType,
            vsi.si.content.about.apiVersion,
            vsi.si.content.about.fullName ),
        local = locals() )

# vsphere-repl ends here
