<s> import atexit <EOL> import requests <EOL> from tools import cli <EOL> from pyVmomi import vim <EOL> from pyVim . connect import SmartConnect , Disconnect <EOL> if hasattr ( requests . packages . urllib3 , '<STR_LIT>' ) : <EOL> requests . packages . urllib3 . disable_warnings ( ) <EOL> def get_args ( ) : <EOL> parser = cli . build_arg_parser ( ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , required = False , <EOL> help = "<STR_LIT>" ) <EOL> my_args = parser . parse_args ( ) <EOL> return cli . prompt_for_password ( my_args ) <EOL> def get_obj ( content , vim_type , name = None ) : <EOL> obj = None <EOL> container = content . viewManager . CreateContainerView ( <EOL> content . rootFolder , vim_type , True ) <EOL> if name : <EOL> for c in container . view : <EOL> if c . name == name : <EOL> obj = c <EOL> return [ obj ] <EOL> else : <EOL> return container . view <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_datastore_info ( ds_obj ) : <EOL> summary = ds_obj . summary <EOL> ds_capacity = summary . capacity <EOL> ds_freespace = summary . freeSpace <EOL> ds_uncommitted = summary . uncommitted if summary . uncommitted else <NUM_LIT:0> <EOL> ds_provisioned = ds_capacity - ds_freespace + ds_uncommitted <EOL> ds_overp = ds_provisioned - ds_capacity <EOL> ds_overp_pct = ( ds_overp * <NUM_LIT:100> ) / ds_capacity if ds_capacity else <NUM_LIT:0> <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" . format ( summary . name ) <EOL> print "<STR_LIT>" . format ( summary . url ) <EOL> print "<STR_LIT>" . format ( sizeof_fmt ( ds_capacity ) ) <EOL> print "<STR_LIT>" . format ( sizeof_fmt ( ds_freespace ) ) <EOL> print "<STR_LIT>" . format ( sizeof_fmt ( ds_uncommitted ) ) <EOL> print "<STR_LIT>" . format ( sizeof_fmt ( ds_provisioned ) ) <EOL> if ds_overp > <NUM_LIT:0> : <EOL> print "<STR_LIT>" . format ( <EOL> sizeof_fmt ( ds_overp ) , <EOL> ds_overp_pct ) <EOL> print "<STR_LIT>" . format ( len ( ds_obj . host ) ) <EOL> print "<STR_LIT>" . format ( len ( ds_obj . vm ) ) <EOL> def main ( ) : <EOL> args = get_args ( ) <EOL> si = SmartConnect ( <EOL> host = args . host , <EOL> user = args . user , <EOL> pwd = args . password , <EOL> port = args . port ) <EOL> atexit . register ( Disconnect , si ) <EOL> content = si . RetrieveContent ( ) <EOL> ds_obj_list = get_obj ( content , [ vim . Datastore ] , args . name ) <EOL> for ds in ds_obj_list : <EOL> print_datastore_info ( ds ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
