<s> """<STR_LIT>""" <EOL> from oslo_utils import units <EOL> from oslo_utils import versionutils <EOL> from nova . compute import arch <EOL> from nova . compute import hv_type <EOL> from nova . compute import vm_mode <EOL> from nova import exception <EOL> from nova . virt . vmwareapi import ds_util <EOL> from nova . virt . vmwareapi import vim_util <EOL> from nova . virt . vmwareapi import vm_util <EOL> def _get_ds_capacity_and_freespace ( session , cluster = None , <EOL> datastore_regex = None ) : <EOL> try : <EOL> ds = ds_util . get_datastore ( session , cluster , <EOL> datastore_regex ) <EOL> return ds . capacity , ds . freespace <EOL> except exception . DatastoreNotFound : <EOL> return <NUM_LIT:0> , <NUM_LIT:0> <EOL> class VCState ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , session , host_name , cluster , datastore_regex ) : <EOL> super ( VCState , self ) . __init__ ( ) <EOL> self . _session = session <EOL> self . _host_name = host_name <EOL> self . _cluster = cluster <EOL> self . _datastore_regex = datastore_regex <EOL> self . _stats = { } <EOL> self . update_status ( ) <EOL> def get_host_stats ( self , refresh = False ) : <EOL> """<STR_LIT>""" <EOL> if refresh or not self . _stats : <EOL> self . update_status ( ) <EOL> return self . _stats <EOL> def update_status ( self ) : <EOL> """<STR_LIT>""" <EOL> capacity , freespace = _get_ds_capacity_and_freespace ( self . _session , <EOL> self . _cluster , self . _datastore_regex ) <EOL> stats = vm_util . get_stats_from_cluster ( self . _session , self . _cluster ) <EOL> about_info = self . _session . _call_method ( vim_util , "<STR_LIT>" ) <EOL> data = { } <EOL> data [ "<STR_LIT>" ] = stats [ '<STR_LIT>' ] <EOL> data [ "<STR_LIT>" ] = capacity / units . Gi <EOL> data [ "<STR_LIT>" ] = freespace / units . Gi <EOL> data [ "<STR_LIT>" ] = data [ "<STR_LIT>" ] - data [ "<STR_LIT>" ] <EOL> data [ "<STR_LIT>" ] = stats [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> data [ "<STR_LIT>" ] = stats [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> data [ "<STR_LIT>" ] = about_info . name <EOL> data [ "<STR_LIT>" ] = versionutils . convert_version_to_int ( <EOL> str ( about_info . version ) ) <EOL> data [ "<STR_LIT>" ] = self . _host_name <EOL> data [ "<STR_LIT>" ] = [ <EOL> ( arch . I686 , hv_type . VMWARE , vm_mode . HVM ) , <EOL> ( arch . X86_64 , hv_type . VMWARE , vm_mode . HVM ) ] <EOL> self . _stats = data <EOL> return data </s>
