<s> """<STR_LIT>""" <EOL> import argparse <EOL> import atexit <EOL> import json <EOL> import ssl <EOL> from pyVim import connect <EOL> from pyVmomi import vmodl <EOL> from pyVmomi import vim <EOL> from tools import cli <EOL> def get_args ( ) : <EOL> """<STR_LIT>""" <EOL> parser = argparse . ArgumentParser ( <EOL> description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , required = True , action = '<STR_LIT:store>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , type = int , default = <NUM_LIT> , action = '<STR_LIT:store>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , required = True , action = '<STR_LIT:store>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , required = True , action = '<STR_LIT:store>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , default = False , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> required = False , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> args = parser . parse_args ( ) <EOL> return args <EOL> def sizeof_fmt ( num ) : <EOL> """<STR_LIT>""" <EOL> for item in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if num < <NUM_LIT> : <EOL> return "<STR_LIT>" % ( num , item ) <EOL> num /= <NUM_LIT> <EOL> return "<STR_LIT>" % ( num , '<STR_LIT>' ) <EOL> def print_fs ( host_fs ) : <EOL> """<STR_LIT>""" <EOL> print ( "<STR_LIT>" . format ( "<STR_LIT>" , host_fs . volume . name ) ) <EOL> print ( "<STR_LIT>" . format ( "<STR_LIT>" , host_fs . volume . uuid ) ) <EOL> print ( "<STR_LIT>" . format ( "<STR_LIT>" , sizeof_fmt ( <EOL> host_fs . volume . capacity ) ) ) <EOL> print ( "<STR_LIT>" . format ( "<STR_LIT>" , host_fs . volume . version ) ) <EOL> print ( "<STR_LIT>" . format ( "<STR_LIT>" , host_fs . volume . local ) ) <EOL> print ( "<STR_LIT>" . format ( "<STR_LIT>" , host_fs . volume . ssd ) ) <EOL> def main ( ) : <EOL> """<STR_LIT>""" <EOL> args = get_args ( ) <EOL> cli . prompt_for_password ( args ) <EOL> sslContext = None <EOL> if args . disable_ssl_verification : <EOL> sslContext = ssl . SSLContext ( ssl . PROTOCOL_SSLv23 ) <EOL> sslContext . verify_mode = ssl . CERT_NONE <EOL> try : <EOL> service_instance = connect . SmartConnect ( host = args . host , <EOL> user = args . user , <EOL> pwd = args . password , <EOL> port = int ( args . port ) , <EOL> sslContext = sslContext ) <EOL> if not service_instance : <EOL> print ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return - <NUM_LIT:1> <EOL> atexit . register ( connect . Disconnect , service_instance ) <EOL> content = service_instance . RetrieveContent ( ) <EOL> objview = content . viewManager . CreateContainerView ( content . rootFolder , <EOL> [ vim . HostSystem ] , <EOL> True ) <EOL> esxi_hosts = objview . view <EOL> objview . Destroy ( ) <EOL> datastores = { } <EOL> for esxi_host in esxi_hosts : <EOL> if not args . json : <EOL> print ( "<STR_LIT>" . format ( "<STR_LIT>" , esxi_host . name ) ) <EOL> storage_system = esxi_host . configManager . storageSystem <EOL> host_file_sys_vol_mount_info = storage_system . fileSystemVolumeInfo . mountInfo <EOL> datastore_dict = { } <EOL> for host_mount_info in host_file_sys_vol_mount_info : <EOL> if host_mount_info . volume . type == "<STR_LIT>" : <EOL> extents = host_mount_info . volume . extent <EOL> if not args . json : <EOL> print_fs ( host_mount_info ) <EOL> else : <EOL> datastore_details = { <EOL> '<STR_LIT>' : host_mount_info . volume . uuid , <EOL> '<STR_LIT>' : host_mount_info . volume . capacity , <EOL> '<STR_LIT>' : host_mount_info . volume . version , <EOL> '<STR_LIT>' : host_mount_info . volume . local , <EOL> '<STR_LIT>' : host_mount_info . volume . ssd <EOL> } <EOL> extent_arr = [ ] <EOL> extent_count = <NUM_LIT:0> <EOL> for extent in extents : <EOL> if not args . json : <EOL> print ( "<STR_LIT>" . format ( <EOL> "<STR_LIT>" + str ( extent_count ) + "<STR_LIT>" , <EOL> extent . diskName ) ) <EOL> extent_count += <NUM_LIT:1> <EOL> else : <EOL> extent_arr . append ( extent . diskName ) <EOL> datastore_details [ '<STR_LIT>' ] = extent_arr <EOL> datastore_dict [ host_mount_info . volume . name ] = datastore_details <EOL> if not args . json : <EOL> print <EOL> datastores [ esxi_host . name ] = datastore_dict <EOL> if args . json : <EOL> print ( json . dumps ( datastores ) ) <EOL> except vmodl . MethodFault as error : <EOL> print ( "<STR_LIT>" + error . msg ) <EOL> return - <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
