<s> """<STR_LIT>""" <EOL> import collections <EOL> import sys <EOL> from oslo_log import log as logging <EOL> from oslo_serialization import jsonutils <EOL> from oslo_utils import units <EOL> from oslo_utils import uuidutils <EOL> from oslo_vmware import exceptions as vexc <EOL> from oslo_vmware . objects import datastore as ds_obj <EOL> import six <EOL> from nova import exception <EOL> from nova . virt . vmwareapi import constants <EOL> _CLASSES = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> _FAKE_FILE_SIZE = <NUM_LIT> <EOL> _FAKE_VCENTER_UUID = '<STR_LIT>' <EOL> _db_content = { } <EOL> _array_types = { } <EOL> _vim_map = { } <EOL> LOG = logging . getLogger ( __name__ ) <EOL> def reset ( ) : <EOL> """<STR_LIT>""" <EOL> cleanup ( ) <EOL> create_network ( ) <EOL> create_folder ( ) <EOL> create_host_network_system ( ) <EOL> create_host_storage_system ( ) <EOL> ds_ref1 = create_datastore ( '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> ) <EOL> create_host ( ds_ref = ds_ref1 ) <EOL> ds_ref2 = create_datastore ( '<STR_LIT>' , <NUM_LIT> , <NUM_LIT> ) <EOL> create_host ( ds_ref = ds_ref2 ) <EOL> create_datacenter ( '<STR_LIT>' , ds_ref1 ) <EOL> create_datacenter ( '<STR_LIT>' , ds_ref2 ) <EOL> create_res_pool ( ) <EOL> create_cluster ( '<STR_LIT>' , ds_ref1 ) <EOL> create_cluster ( '<STR_LIT>' , ds_ref2 ) <EOL> def cleanup ( ) : <EOL> """<STR_LIT>""" <EOL> for c in _CLASSES : <EOL> if c == '<STR_LIT>' : <EOL> _db_content [ c ] = [ ] <EOL> else : <EOL> _db_content [ c ] = { } <EOL> def _create_object ( table , table_obj ) : <EOL> """<STR_LIT>""" <EOL> _db_content . setdefault ( table , { } ) <EOL> _db_content [ table ] [ table_obj . obj ] = table_obj <EOL> def _get_object ( obj_ref ) : <EOL> """<STR_LIT>""" <EOL> return _db_content [ obj_ref . type ] [ obj_ref ] <EOL> def _get_objects ( obj_type ) : <EOL> """<STR_LIT>""" <EOL> lst_objs = FakeRetrieveResult ( ) <EOL> for key in _db_content [ obj_type ] : <EOL> lst_objs . add_object ( _db_content [ obj_type ] [ key ] ) <EOL> return lst_objs <EOL> def _convert_to_array_of_mor ( mors ) : <EOL> """<STR_LIT>""" <EOL> array_of_mors = DataObject ( ) <EOL> array_of_mors . ManagedObjectReference = mors <EOL> return array_of_mors <EOL> def _convert_to_array_of_opt_val ( optvals ) : <EOL> """<STR_LIT>""" <EOL> array_of_optv = DataObject ( ) <EOL> array_of_optv . OptionValue = optvals <EOL> return array_of_optv <EOL> def _create_array_of_type ( t ) : <EOL> """<STR_LIT>""" <EOL> if t in _array_types : <EOL> return _array_types [ t ] ( ) <EOL> array_type_name = '<STR_LIT>' % t <EOL> array_type = type ( array_type_name , ( DataObject , ) , { } ) <EOL> def __init__ ( self ) : <EOL> super ( array_type , self ) . __init__ ( array_type_name ) <EOL> setattr ( self , t , [ ] ) <EOL> setattr ( array_type , '<STR_LIT>' , __init__ ) <EOL> _array_types [ t ] = array_type <EOL> return array_type ( ) <EOL> class FakeRetrieveResult ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , token = None ) : <EOL> self . objects = [ ] <EOL> if token is not None : <EOL> self . token = token <EOL> def add_object ( self , object ) : <EOL> self . objects . append ( object ) <EOL> def _get_object_refs ( obj_type ) : <EOL> """<STR_LIT>""" <EOL> lst_objs = [ ] <EOL> for key in _db_content [ obj_type ] : <EOL> lst_objs . append ( key ) <EOL> return lst_objs <EOL> def _update_object ( table , table_obj ) : <EOL> """<STR_LIT>""" <EOL> _db_content [ table ] [ table_obj . obj ] = table_obj <EOL> class Prop ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name = None , val = None ) : <EOL> self . name = name <EOL> self . val = val <EOL> class ManagedObjectReference ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name = "<STR_LIT>" , value = None ) : <EOL> super ( ManagedObjectReference , self ) <EOL> self . value = value <EOL> self . type = name <EOL> self . _type = name <EOL> class ObjectContent ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , obj_ref , prop_list = None , missing_list = None ) : <EOL> self . obj = obj_ref <EOL> if not isinstance ( prop_list , collections . Iterable ) : <EOL> prop_list = [ ] <EOL> if not isinstance ( missing_list , collections . Iterable ) : <EOL> missing_list = [ ] <EOL> if prop_list : <EOL> self . propSet = prop_list <EOL> if missing_list : <EOL> self . missingSet = missing_list <EOL> class ManagedObject ( object ) : <EOL> """<STR_LIT>""" <EOL> _counter = <NUM_LIT:0> <EOL> def __init__ ( self , mo_id_prefix = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> object . __setattr__ ( self , '<STR_LIT>' , self . _generate_moid ( mo_id_prefix ) ) <EOL> object . __setattr__ ( self , '<STR_LIT>' , [ ] ) <EOL> object . __setattr__ ( self , '<STR_LIT>' , <EOL> ManagedObjectReference ( self . __class__ . __name__ , <EOL> self . mo_id ) ) <EOL> def set ( self , attr , val ) : <EOL> """<STR_LIT>""" <EOL> self . __setattr__ ( attr , val ) <EOL> def get ( self , attr ) : <EOL> """<STR_LIT>""" <EOL> return self . __getattr__ ( attr ) <EOL> def delete ( self , attr ) : <EOL> """<STR_LIT>""" <EOL> self . propSet = filter ( lambda elem : elem . name != attr , self . propSet ) <EOL> def __setattr__ ( self , attr , val ) : <EOL> for prop in self . propSet : <EOL> if prop . name == attr : <EOL> prop . val = val <EOL> return <EOL> elem = Prop ( ) <EOL> elem . name = attr <EOL> elem . val = val <EOL> self . propSet . append ( elem ) <EOL> def __getattr__ ( self , attr ) : <EOL> for elem in self . propSet : <EOL> if elem . name == attr : <EOL> return elem . val <EOL> msg = "<STR_LIT>" <EOL> raise exception . NovaException ( msg % { '<STR_LIT>' : attr , <EOL> '<STR_LIT:name>' : self . __class__ . __name__ } ) <EOL> def _generate_moid ( self , prefix ) : <EOL> """<STR_LIT>""" <EOL> self . __class__ . _counter += <NUM_LIT:1> <EOL> return prefix + "<STR_LIT:->" + str ( self . __class__ . _counter ) <EOL> def __repr__ ( self ) : <EOL> return jsonutils . dumps ( { elem . name : elem . val <EOL> for elem in self . propSet } ) <EOL> class DataObject ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , obj_name = None ) : <EOL> if obj_name is None : <EOL> obj_name = '<STR_LIT>' + self . __class__ . __name__ <EOL> self . obj_name = obj_name <EOL> def __repr__ ( self ) : <EOL> return str ( self . __dict__ ) <EOL> def __eq__ ( self , other ) : <EOL> return self . __dict__ == other . __dict__ <EOL> class HostInternetScsiHba ( DataObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , iscsi_name = None ) : <EOL> super ( HostInternetScsiHba , self ) . __init__ ( ) <EOL> self . device = '<STR_LIT>' <EOL> self . key = '<STR_LIT>' <EOL> self . iScsiName = iscsi_name <EOL> class FileAlreadyExists ( DataObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( FileAlreadyExists , self ) . __init__ ( ) <EOL> self . __name__ = vexc . FILE_ALREADY_EXISTS <EOL> class FileNotFound ( DataObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( FileNotFound , self ) . __init__ ( ) <EOL> self . __name__ = vexc . FILE_NOT_FOUND <EOL> class FileFault ( DataObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( FileFault , self ) . __init__ ( ) <EOL> self . __name__ = vexc . FILE_FAULT <EOL> class CannotDeleteFile ( DataObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( CannotDeleteFile , self ) . __init__ ( ) <EOL> self . __name__ = vexc . CANNOT_DELETE_FILE <EOL> class FileLocked ( DataObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( FileLocked , self ) . __init__ ( ) <EOL> self . __name__ = vexc . FILE_LOCKED <EOL> class VirtualDisk ( DataObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , controllerKey = <NUM_LIT:0> , unitNumber = <NUM_LIT:0> ) : <EOL> super ( VirtualDisk , self ) . __init__ ( ) <EOL> self . key = <NUM_LIT:0> <EOL> self . controllerKey = controllerKey <EOL> self . unitNumber = unitNumber <EOL> class VirtualDiskFlatVer2BackingInfo ( DataObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( VirtualDiskFlatVer2BackingInfo , self ) . __init__ ( ) <EOL> self . thinProvisioned = False <EOL> self . eagerlyScrub = False <EOL> class VirtualDiskRawDiskMappingVer1BackingInfo ( DataObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( VirtualDiskRawDiskMappingVer1BackingInfo , self ) . __init__ ( ) <EOL> self . lunUuid = "<STR_LIT>" <EOL> class VirtualIDEController ( DataObject ) : <EOL> def __init__ ( self , key = <NUM_LIT:0> ) : <EOL> self . key = key <EOL> class VirtualLsiLogicController ( DataObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , key = <NUM_LIT:0> , scsiCtlrUnitNumber = <NUM_LIT:0> , busNumber = <NUM_LIT:0> ) : <EOL> self . key = key <EOL> self . busNumber = busNumber <EOL> self . scsiCtlrUnitNumber = scsiCtlrUnitNumber <EOL> self . device = [ ] <EOL> class VirtualLsiLogicSASController ( DataObject ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class VirtualPCNet32 ( DataObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( VirtualPCNet32 , self ) . __init__ ( ) <EOL> self . key = <NUM_LIT> <EOL> class OptionValue ( DataObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , key = None , value = None ) : <EOL> super ( OptionValue , self ) . __init__ ( ) <EOL> self . key = key <EOL> self . value = value <EOL> class VirtualMachine ( ManagedObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( VirtualMachine , self ) . __init__ ( "<STR_LIT>" ) <EOL> self . set ( "<STR_LIT:name>" , kwargs . get ( "<STR_LIT:name>" , '<STR_LIT>' ) ) <EOL> self . set ( "<STR_LIT>" , <EOL> kwargs . get ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> self . set ( "<STR_LIT>" , <EOL> kwargs . get ( "<STR_LIT>" , constants . DEFAULT_OS_TYPE ) ) <EOL> ds_do = kwargs . get ( "<STR_LIT>" , None ) <EOL> self . set ( "<STR_LIT>" , _convert_to_array_of_mor ( ds_do ) ) <EOL> self . set ( "<STR_LIT>" , kwargs . get ( "<STR_LIT>" , <EOL> "<STR_LIT>" ) ) <EOL> self . set ( "<STR_LIT>" , kwargs . get ( <EOL> "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> self . set ( "<STR_LIT>" , kwargs . get ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> self . set ( "<STR_LIT>" , kwargs . get ( "<STR_LIT>" ) ) <EOL> self . set ( "<STR_LIT>" , kwargs . get ( "<STR_LIT>" , <NUM_LIT:1> ) ) <EOL> self . set ( "<STR_LIT>" , kwargs . get ( "<STR_LIT>" , <NUM_LIT:1> ) ) <EOL> self . set ( "<STR_LIT>" , kwargs . get ( "<STR_LIT>" ) ) <EOL> self . set ( "<STR_LIT:version>" , kwargs . get ( "<STR_LIT:version>" ) ) <EOL> devices = _create_array_of_type ( '<STR_LIT>' ) <EOL> devices . VirtualDevice = kwargs . get ( "<STR_LIT>" , [ ] ) <EOL> self . set ( "<STR_LIT>" , devices ) <EOL> exconfig_do = kwargs . get ( "<STR_LIT>" , None ) <EOL> self . set ( "<STR_LIT>" , <EOL> _convert_to_array_of_opt_val ( exconfig_do ) ) <EOL> if exconfig_do : <EOL> for optval in exconfig_do : <EOL> self . set ( '<STR_LIT>' % optval . key , optval ) <EOL> self . set ( '<STR_LIT>' , kwargs . get ( "<STR_LIT>" , None ) ) <EOL> self . device = kwargs . get ( "<STR_LIT>" , [ ] ) <EOL> config = [ <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:0> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:0> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:1> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:1> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:1> ) ] <EOL> self . set ( "<STR_LIT>" , config ) <EOL> quickStats = [ <EOL> ( '<STR_LIT>' , <NUM_LIT:0> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:0> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:0> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:0> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:20> ) ] <EOL> self . set ( "<STR_LIT>" , quickStats ) <EOL> key1 = { '<STR_LIT:key>' : '<STR_LIT>' } <EOL> key2 = { '<STR_LIT:key>' : '<STR_LIT>' } <EOL> runtime = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:0> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , [ key1 , key2 ] ) ] <EOL> self . set ( "<STR_LIT>" , runtime ) <EOL> def _update_extra_config ( self , extra ) : <EOL> extra_config = self . get ( "<STR_LIT>" ) <EOL> values = extra_config . OptionValue <EOL> for value in values : <EOL> if value . key == extra . key : <EOL> value . value = extra . value <EOL> return <EOL> kv = DataObject ( ) <EOL> kv . key = extra . key <EOL> kv . value = extra . value <EOL> extra_config . OptionValue . append ( kv ) <EOL> self . set ( "<STR_LIT>" , extra_config ) <EOL> extra_config = self . get ( "<STR_LIT>" ) <EOL> def reconfig ( self , factory , val ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( val , '<STR_LIT:name>' ) and val . name : <EOL> self . set ( "<STR_LIT:name>" , val . name ) <EOL> if hasattr ( val , '<STR_LIT>' ) : <EOL> extraConfigs = _merge_extraconfig ( <EOL> self . get ( "<STR_LIT>" ) . OptionValue , <EOL> val . extraConfig ) <EOL> self . get ( "<STR_LIT>" ) . OptionValue = extraConfigs <EOL> if hasattr ( val , '<STR_LIT>' ) and val . instanceUuid is not None : <EOL> if val . instanceUuid == "<STR_LIT>" : <EOL> val . instanceUuid = uuidutils . generate_uuid ( ) <EOL> self . set ( "<STR_LIT>" , val . instanceUuid ) <EOL> try : <EOL> if not hasattr ( val , '<STR_LIT>' ) : <EOL> return <EOL> if hasattr ( val , '<STR_LIT>' ) : <EOL> for extra in val . extraConfig : <EOL> self . _update_extra_config ( extra ) <EOL> if len ( val . deviceChange ) < <NUM_LIT:2> : <EOL> return <EOL> controller_key = val . deviceChange [ <NUM_LIT:0> ] . device . controllerKey <EOL> filename = val . deviceChange [ <NUM_LIT:0> ] . device . backing . fileName <EOL> disk = VirtualDisk ( ) <EOL> disk . controllerKey = controller_key <EOL> disk_backing = VirtualDiskFlatVer2BackingInfo ( ) <EOL> disk_backing . fileName = filename <EOL> disk_backing . key = - <NUM_LIT> <EOL> disk . backing = disk_backing <EOL> disk . capacityInBytes = <NUM_LIT> <EOL> disk . capacityInKB = <NUM_LIT:1> <EOL> controller = VirtualLsiLogicController ( ) <EOL> controller . key = controller_key <EOL> devices = _create_array_of_type ( '<STR_LIT>' ) <EOL> devices . VirtualDevice = [ disk , controller , self . device [ <NUM_LIT:0> ] ] <EOL> self . set ( "<STR_LIT>" , devices ) <EOL> except AttributeError : <EOL> pass <EOL> class Folder ( ManagedObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( Folder , self ) . __init__ ( "<STR_LIT>" ) <EOL> self . set ( "<STR_LIT>" , [ ] ) <EOL> class Network ( ManagedObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( Network , self ) . __init__ ( "<STR_LIT>" ) <EOL> self . set ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> class ResourcePool ( ManagedObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name = "<STR_LIT>" , value = "<STR_LIT>" ) : <EOL> super ( ResourcePool , self ) . __init__ ( "<STR_LIT>" ) <EOL> self . set ( "<STR_LIT:name>" , name ) <EOL> summary = DataObject ( ) <EOL> runtime = DataObject ( ) <EOL> config = DataObject ( ) <EOL> memory = DataObject ( ) <EOL> cpu = DataObject ( ) <EOL> memoryAllocation = DataObject ( ) <EOL> cpuAllocation = DataObject ( ) <EOL> vm_list = DataObject ( ) <EOL> memory . maxUsage = <NUM_LIT:1000> * units . Mi <EOL> memory . overallUsage = <NUM_LIT> * units . Mi <EOL> cpu . maxUsage = <NUM_LIT> <EOL> cpu . overallUsage = <NUM_LIT:1000> <EOL> runtime . cpu = cpu <EOL> runtime . memory = memory <EOL> summary . runtime = runtime <EOL> cpuAllocation . limit = <NUM_LIT> <EOL> memoryAllocation . limit = <NUM_LIT> <EOL> memoryAllocation . reservation = <NUM_LIT> <EOL> config . memoryAllocation = memoryAllocation <EOL> config . cpuAllocation = cpuAllocation <EOL> vm_list . ManagedObjectReference = [ ] <EOL> self . set ( "<STR_LIT>" , summary ) <EOL> self . set ( "<STR_LIT>" , memory ) <EOL> self . set ( "<STR_LIT>" , config ) <EOL> self . set ( "<STR_LIT>" , vm_list ) <EOL> parent = ManagedObjectReference ( value = value , <EOL> name = name ) <EOL> owner = ManagedObjectReference ( value = value , <EOL> name = name ) <EOL> self . set ( "<STR_LIT>" , parent ) <EOL> self . set ( "<STR_LIT>" , owner ) <EOL> class DatastoreHostMount ( DataObject ) : <EOL> def __init__ ( self , value = '<STR_LIT>' ) : <EOL> super ( DatastoreHostMount , self ) . __init__ ( ) <EOL> host_ref = ( _db_content [ "<STR_LIT>" ] <EOL> [ list ( _db_content [ "<STR_LIT>" ] . keys ( ) ) [ <NUM_LIT:0> ] ] . obj ) <EOL> host_system = DataObject ( ) <EOL> host_system . ManagedObjectReference = [ host_ref ] <EOL> host_system . value = value <EOL> self . key = host_system <EOL> class ClusterComputeResource ( ManagedObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name = "<STR_LIT>" ) : <EOL> super ( ClusterComputeResource , self ) . __init__ ( "<STR_LIT>" ) <EOL> self . set ( "<STR_LIT:name>" , name ) <EOL> self . set ( "<STR_LIT:host>" , None ) <EOL> self . set ( "<STR_LIT>" , None ) <EOL> self . set ( "<STR_LIT>" , None ) <EOL> summary = DataObject ( ) <EOL> summary . numHosts = <NUM_LIT:0> <EOL> summary . numCpuCores = <NUM_LIT:0> <EOL> summary . numCpuThreads = <NUM_LIT:0> <EOL> summary . numEffectiveHosts = <NUM_LIT:0> <EOL> summary . totalMemory = <NUM_LIT:0> <EOL> summary . effectiveMemory = <NUM_LIT:0> <EOL> summary . effectiveCpu = <NUM_LIT> <EOL> self . set ( "<STR_LIT>" , summary ) <EOL> def _add_root_resource_pool ( self , r_pool ) : <EOL> if r_pool : <EOL> self . set ( "<STR_LIT>" , r_pool ) <EOL> def _add_host ( self , host_sys ) : <EOL> if host_sys : <EOL> hosts = self . get ( "<STR_LIT:host>" ) <EOL> if hosts is None : <EOL> hosts = DataObject ( ) <EOL> hosts . ManagedObjectReference = [ ] <EOL> self . set ( "<STR_LIT:host>" , hosts ) <EOL> hosts . ManagedObjectReference . append ( host_sys ) <EOL> self . _update_summary ( ) <EOL> def _add_datastore ( self , datastore ) : <EOL> if datastore : <EOL> datastores = self . get ( "<STR_LIT>" ) <EOL> if datastores is None : <EOL> datastores = DataObject ( ) <EOL> datastores . ManagedObjectReference = [ ] <EOL> self . set ( "<STR_LIT>" , datastores ) <EOL> datastores . ManagedObjectReference . append ( datastore ) <EOL> def _update_summary ( self ) : <EOL> summary = self . get ( "<STR_LIT>" ) <EOL> summary . numHosts = <NUM_LIT:0> <EOL> summary . numCpuCores = <NUM_LIT:0> <EOL> summary . numCpuThreads = <NUM_LIT:0> <EOL> summary . numEffectiveHosts = <NUM_LIT:0> <EOL> summary . totalMemory = <NUM_LIT:0> <EOL> summary . effectiveMemory = <NUM_LIT:0> <EOL> hosts = self . get ( "<STR_LIT:host>" ) <EOL> summary . numHosts = len ( hosts . ManagedObjectReference ) <EOL> for host_ref in hosts . ManagedObjectReference : <EOL> host_sys = _get_object ( host_ref ) <EOL> connected = host_sys . get ( "<STR_LIT>" ) <EOL> host_summary = host_sys . get ( "<STR_LIT>" ) <EOL> summary . numCpuCores += host_summary . hardware . numCpuCores <EOL> summary . numCpuThreads += host_summary . hardware . numCpuThreads <EOL> summary . totalMemory += host_summary . hardware . memorySize <EOL> free_memory = ( host_summary . hardware . memorySize / units . Mi <EOL> - host_summary . quickStats . overallMemoryUsage ) <EOL> summary . effectiveMemory += free_memory if connected else <NUM_LIT:0> <EOL> summary . numEffectiveHosts += <NUM_LIT:1> if connected else <NUM_LIT:0> <EOL> self . set ( "<STR_LIT>" , summary ) <EOL> class Datastore ( ManagedObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name = "<STR_LIT>" , capacity = <NUM_LIT> , free = <NUM_LIT> , <EOL> accessible = True , maintenance_mode = "<STR_LIT>" ) : <EOL> super ( Datastore , self ) . __init__ ( "<STR_LIT>" ) <EOL> self . set ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . set ( "<STR_LIT>" , name ) <EOL> self . set ( "<STR_LIT>" , capacity * units . Gi ) <EOL> self . set ( "<STR_LIT>" , free * units . Gi ) <EOL> self . set ( "<STR_LIT>" , accessible ) <EOL> self . set ( "<STR_LIT>" , maintenance_mode ) <EOL> self . set ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> class HostNetworkSystem ( ManagedObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name = "<STR_LIT>" ) : <EOL> super ( HostNetworkSystem , self ) . __init__ ( "<STR_LIT>" ) <EOL> self . set ( "<STR_LIT:name>" , name ) <EOL> pnic_do = DataObject ( ) <EOL> pnic_do . device = "<STR_LIT>" <EOL> net_info_pnic = DataObject ( ) <EOL> net_info_pnic . PhysicalNic = [ pnic_do ] <EOL> self . set ( "<STR_LIT>" , net_info_pnic ) <EOL> class HostStorageSystem ( ManagedObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( HostStorageSystem , self ) . __init__ ( "<STR_LIT>" ) <EOL> class HostSystem ( ManagedObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name = "<STR_LIT>" , connected = True , ds_ref = None , <EOL> maintenance_mode = False ) : <EOL> super ( HostSystem , self ) . __init__ ( "<STR_LIT:host>" ) <EOL> self . set ( "<STR_LIT:name>" , name ) <EOL> if _db_content . get ( "<STR_LIT>" , None ) is None : <EOL> create_host_network_system ( ) <EOL> if not _get_object_refs ( '<STR_LIT>' ) : <EOL> create_host_storage_system ( ) <EOL> host_net_key = list ( _db_content [ "<STR_LIT>" ] . keys ( ) ) [ <NUM_LIT:0> ] <EOL> host_net_sys = _db_content [ "<STR_LIT>" ] [ host_net_key ] . obj <EOL> self . set ( "<STR_LIT>" , host_net_sys ) <EOL> host_storage_sys_key = _get_object_refs ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> self . set ( "<STR_LIT>" , host_storage_sys_key ) <EOL> if not ds_ref : <EOL> ds_ref = create_datastore ( '<STR_LIT>' % name , <NUM_LIT> , <NUM_LIT> ) <EOL> datastores = DataObject ( ) <EOL> datastores . ManagedObjectReference = [ ds_ref ] <EOL> self . set ( "<STR_LIT>" , datastores ) <EOL> summary = DataObject ( ) <EOL> hardware = DataObject ( ) <EOL> hardware . numCpuCores = <NUM_LIT:8> <EOL> hardware . numCpuPkgs = <NUM_LIT:2> <EOL> hardware . numCpuThreads = <NUM_LIT:16> <EOL> hardware . vendor = "<STR_LIT>" <EOL> hardware . cpuModel = "<STR_LIT>" <EOL> hardware . uuid = "<STR_LIT>" <EOL> hardware . memorySize = units . Gi <EOL> summary . hardware = hardware <EOL> runtime = DataObject ( ) <EOL> if connected : <EOL> runtime . connectionState = "<STR_LIT>" <EOL> else : <EOL> runtime . connectionState = "<STR_LIT>" <EOL> runtime . inMaintenanceMode = maintenance_mode <EOL> summary . runtime = runtime <EOL> quickstats = DataObject ( ) <EOL> quickstats . overallMemoryUsage = <NUM_LIT> <EOL> summary . quickStats = quickstats <EOL> product = DataObject ( ) <EOL> product . name = "<STR_LIT>" <EOL> product . version = constants . MIN_VC_VERSION <EOL> config = DataObject ( ) <EOL> config . product = product <EOL> summary . config = config <EOL> pnic_do = DataObject ( ) <EOL> pnic_do . device = "<STR_LIT>" <EOL> net_info_pnic = DataObject ( ) <EOL> net_info_pnic . PhysicalNic = [ pnic_do ] <EOL> self . set ( "<STR_LIT>" , summary ) <EOL> self . set ( "<STR_LIT>" , <NUM_LIT> ) <EOL> self . set ( "<STR_LIT>" , hardware ) <EOL> self . set ( "<STR_LIT>" , runtime ) <EOL> self . set ( "<STR_LIT>" , net_info_pnic ) <EOL> self . set ( "<STR_LIT>" , connected ) <EOL> if _db_content . get ( "<STR_LIT>" , None ) is None : <EOL> create_network ( ) <EOL> net_ref = _db_content [ "<STR_LIT>" ] [ <EOL> list ( _db_content [ "<STR_LIT>" ] . keys ( ) ) [ <NUM_LIT:0> ] ] . obj <EOL> network_do = DataObject ( ) <EOL> network_do . ManagedObjectReference = [ net_ref ] <EOL> self . set ( "<STR_LIT>" , network_do ) <EOL> vswitch_do = DataObject ( ) <EOL> vswitch_do . pnic = [ "<STR_LIT>" ] <EOL> vswitch_do . name = "<STR_LIT>" <EOL> vswitch_do . portgroup = [ "<STR_LIT>" ] <EOL> net_swicth = DataObject ( ) <EOL> net_swicth . HostVirtualSwitch = [ vswitch_do ] <EOL> self . set ( "<STR_LIT>" , net_swicth ) <EOL> host_pg_do = DataObject ( ) <EOL> host_pg_do . key = "<STR_LIT>" <EOL> pg_spec = DataObject ( ) <EOL> pg_spec . vlanId = <NUM_LIT:0> <EOL> pg_spec . name = "<STR_LIT>" <EOL> host_pg_do . spec = pg_spec <EOL> host_pg = DataObject ( ) <EOL> host_pg . HostPortGroup = [ host_pg_do ] <EOL> self . set ( "<STR_LIT>" , host_pg ) <EOL> config = DataObject ( ) <EOL> storageDevice = DataObject ( ) <EOL> iscsi_hba = HostInternetScsiHba ( ) <EOL> iscsi_hba . iScsiName = "<STR_LIT>" <EOL> host_bus_adapter_array = DataObject ( ) <EOL> host_bus_adapter_array . HostHostBusAdapter = [ iscsi_hba ] <EOL> storageDevice . hostBusAdapter = host_bus_adapter_array <EOL> config . storageDevice = storageDevice <EOL> self . set ( "<STR_LIT>" , host_bus_adapter_array ) <EOL> host_storage_sys = _get_object ( host_storage_sys_key ) <EOL> host_storage_sys . set ( '<STR_LIT>' , <EOL> host_bus_adapter_array ) <EOL> def _add_iscsi_target ( self , data ) : <EOL> default_lun = DataObject ( ) <EOL> default_lun . scsiLun = '<STR_LIT>' <EOL> default_lun . key = '<STR_LIT>' <EOL> default_lun . deviceName = '<STR_LIT>' <EOL> default_lun . uuid = '<STR_LIT>' <EOL> scsi_lun_array = DataObject ( ) <EOL> scsi_lun_array . ScsiLun = [ default_lun ] <EOL> self . set ( "<STR_LIT>" , scsi_lun_array ) <EOL> transport = DataObject ( ) <EOL> transport . address = [ data [ '<STR_LIT>' ] ] <EOL> transport . iScsiName = data [ '<STR_LIT>' ] <EOL> default_target = DataObject ( ) <EOL> default_target . lun = [ default_lun ] <EOL> default_target . transport = transport <EOL> iscsi_adapter = DataObject ( ) <EOL> iscsi_adapter . adapter = '<STR_LIT>' <EOL> iscsi_adapter . transport = transport <EOL> iscsi_adapter . target = [ default_target ] <EOL> iscsi_topology = DataObject ( ) <EOL> iscsi_topology . adapter = [ iscsi_adapter ] <EOL> self . set ( "<STR_LIT>" , iscsi_topology ) <EOL> def _add_port_group ( self , spec ) : <EOL> """<STR_LIT>""" <EOL> pg_name = spec . name <EOL> vswitch_name = spec . vswitchName <EOL> vlanid = spec . vlanId <EOL> vswitch_do = DataObject ( ) <EOL> vswitch_do . pnic = [ "<STR_LIT>" ] <EOL> vswitch_do . name = vswitch_name <EOL> vswitch_do . portgroup = [ "<STR_LIT>" % pg_name ] <EOL> vswitches = self . get ( "<STR_LIT>" ) . HostVirtualSwitch <EOL> vswitches . append ( vswitch_do ) <EOL> host_pg_do = DataObject ( ) <EOL> host_pg_do . key = "<STR_LIT>" % pg_name <EOL> pg_spec = DataObject ( ) <EOL> pg_spec . vlanId = vlanid <EOL> pg_spec . name = pg_name <EOL> host_pg_do . spec = pg_spec <EOL> host_pgrps = self . get ( "<STR_LIT>" ) . HostPortGroup <EOL> host_pgrps . append ( host_pg_do ) <EOL> class Datacenter ( ManagedObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name = "<STR_LIT>" , ds_ref = None ) : <EOL> super ( Datacenter , self ) . __init__ ( "<STR_LIT>" ) <EOL> self . set ( "<STR_LIT:name>" , name ) <EOL> if _db_content . get ( "<STR_LIT>" , None ) is None : <EOL> create_folder ( ) <EOL> folder_ref = _db_content [ "<STR_LIT>" ] [ <EOL> list ( _db_content [ "<STR_LIT>" ] . keys ( ) ) [ <NUM_LIT:0> ] ] . obj <EOL> folder_do = DataObject ( ) <EOL> folder_do . ManagedObjectReference = [ folder_ref ] <EOL> self . set ( "<STR_LIT>" , folder_ref ) <EOL> if _db_content . get ( "<STR_LIT>" , None ) is None : <EOL> create_network ( ) <EOL> net_ref = _db_content [ "<STR_LIT>" ] [ <EOL> list ( _db_content [ "<STR_LIT>" ] . keys ( ) ) [ <NUM_LIT:0> ] ] . obj <EOL> network_do = DataObject ( ) <EOL> network_do . ManagedObjectReference = [ net_ref ] <EOL> self . set ( "<STR_LIT>" , network_do ) <EOL> if ds_ref : <EOL> datastore = DataObject ( ) <EOL> datastore . ManagedObjectReference = [ ds_ref ] <EOL> else : <EOL> datastore = None <EOL> self . set ( "<STR_LIT>" , datastore ) <EOL> class Task ( ManagedObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , task_name , state = "<STR_LIT>" , result = None , <EOL> error_fault = None ) : <EOL> super ( Task , self ) . __init__ ( "<STR_LIT>" ) <EOL> info = DataObject ( ) <EOL> info . name = task_name <EOL> info . state = state <EOL> if state == '<STR_LIT:error>' : <EOL> error = DataObject ( ) <EOL> error . localizedMessage = "<STR_LIT>" <EOL> if not error_fault : <EOL> error . fault = DataObject ( ) <EOL> else : <EOL> error . fault = error_fault <EOL> info . error = error <EOL> info . result = result <EOL> self . set ( "<STR_LIT:info>" , info ) <EOL> def create_host_network_system ( ) : <EOL> host_net_system = HostNetworkSystem ( ) <EOL> _create_object ( "<STR_LIT>" , host_net_system ) <EOL> def create_host_storage_system ( ) : <EOL> host_storage_system = HostStorageSystem ( ) <EOL> _create_object ( "<STR_LIT>" , host_storage_system ) <EOL> def create_host ( ds_ref = None ) : <EOL> host_system = HostSystem ( ds_ref = ds_ref ) <EOL> _create_object ( '<STR_LIT>' , host_system ) <EOL> def create_datacenter ( name , ds_ref = None ) : <EOL> data_center = Datacenter ( name , ds_ref ) <EOL> _create_object ( '<STR_LIT>' , data_center ) <EOL> def create_datastore ( name , capacity , free ) : <EOL> data_store = Datastore ( name , capacity , free ) <EOL> _create_object ( '<STR_LIT>' , data_store ) <EOL> return data_store . obj <EOL> def create_res_pool ( ) : <EOL> res_pool = ResourcePool ( ) <EOL> _create_object ( '<STR_LIT>' , res_pool ) <EOL> return res_pool . obj <EOL> def create_folder ( ) : <EOL> folder = Folder ( ) <EOL> _create_object ( '<STR_LIT>' , folder ) <EOL> return folder . obj <EOL> def create_network ( ) : <EOL> network = Network ( ) <EOL> _create_object ( '<STR_LIT>' , network ) <EOL> def create_cluster ( name , ds_ref ) : <EOL> cluster = ClusterComputeResource ( name = name ) <EOL> cluster . _add_host ( _get_object_refs ( "<STR_LIT>" ) [ <NUM_LIT:0> ] ) <EOL> cluster . _add_host ( _get_object_refs ( "<STR_LIT>" ) [ <NUM_LIT:1> ] ) <EOL> cluster . _add_datastore ( ds_ref ) <EOL> cluster . _add_root_resource_pool ( create_res_pool ( ) ) <EOL> _create_object ( '<STR_LIT>' , cluster ) <EOL> return cluster <EOL> def create_vm ( uuid = None , name = None , <EOL> cpus = <NUM_LIT:1> , memory = <NUM_LIT> , devices = None , <EOL> vmPathName = None , extraConfig = None , <EOL> res_pool_ref = None , host_ref = None , <EOL> version = None ) : <EOL> if uuid is None : <EOL> uuid = uuidutils . generate_uuid ( ) <EOL> if name is None : <EOL> name = uuid <EOL> if devices is None : <EOL> devices = [ ] <EOL> if vmPathName is None : <EOL> vm_path = ds_obj . DatastorePath ( <EOL> list ( _db_content [ '<STR_LIT>' ] . values ( ) ) [ <NUM_LIT:0> ] ) <EOL> else : <EOL> vm_path = ds_obj . DatastorePath . parse ( vmPathName ) <EOL> if res_pool_ref is None : <EOL> res_pool_ref = list ( _db_content [ '<STR_LIT>' ] . keys ( ) ) [ <NUM_LIT:0> ] <EOL> if host_ref is None : <EOL> host_ref = list ( _db_content [ "<STR_LIT>" ] . keys ( ) ) [ <NUM_LIT:0> ] <EOL> if vm_path . rel_path == '<STR_LIT>' : <EOL> vm_path = vm_path . join ( name , name + '<STR_LIT>' ) <EOL> for key , value in six . iteritems ( _db_content [ "<STR_LIT>" ] ) : <EOL> if value . get ( '<STR_LIT>' ) == vm_path . datastore : <EOL> ds = key <EOL> break <EOL> else : <EOL> ds = create_datastore ( vm_path . datastore , <NUM_LIT> , <NUM_LIT> ) <EOL> vm_dict = { "<STR_LIT:name>" : name , <EOL> "<STR_LIT>" : [ ds ] , <EOL> "<STR_LIT>" : host_ref , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : str ( vm_path ) , <EOL> "<STR_LIT>" : cpus , <EOL> "<STR_LIT>" : memory , <EOL> "<STR_LIT>" : extraConfig , <EOL> "<STR_LIT>" : devices , <EOL> "<STR_LIT>" : uuid , <EOL> "<STR_LIT:version>" : version } <EOL> vm = VirtualMachine ( ** vm_dict ) <EOL> _create_object ( "<STR_LIT>" , vm ) <EOL> res_pool = _get_object ( res_pool_ref ) <EOL> res_pool . vm . ManagedObjectReference . append ( vm . obj ) <EOL> return vm . obj <EOL> def create_task ( task_name , state = "<STR_LIT>" , result = None , error_fault = None ) : <EOL> task = Task ( task_name , state , result , error_fault ) <EOL> _create_object ( "<STR_LIT>" , task ) <EOL> return task <EOL> def _add_file ( file_path ) : <EOL> """<STR_LIT>""" <EOL> _db_content [ "<STR_LIT>" ] . append ( file_path ) <EOL> def _remove_file ( file_path ) : <EOL> """<STR_LIT>""" <EOL> if file_path . find ( "<STR_LIT>" ) != - <NUM_LIT:1> : <EOL> if file_path not in _db_content . get ( "<STR_LIT>" ) : <EOL> raise vexc . FileNotFoundException ( file_path ) <EOL> _db_content . get ( "<STR_LIT>" ) . remove ( file_path ) <EOL> else : <EOL> to_delete = set ( ) <EOL> for file in _db_content . get ( "<STR_LIT>" ) : <EOL> if file . find ( file_path ) != - <NUM_LIT:1> : <EOL> to_delete . add ( file ) <EOL> for file in to_delete : <EOL> _db_content . get ( "<STR_LIT>" ) . remove ( file ) <EOL> def fake_plug_vifs ( * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def fake_get_network ( * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return { '<STR_LIT:type>' : '<STR_LIT>' } <EOL> def assertPathExists ( test , path ) : <EOL> test . assertIn ( path , _db_content . get ( '<STR_LIT>' ) ) <EOL> def assertPathNotExists ( test , path ) : <EOL> test . assertNotIn ( path , _db_content . get ( '<STR_LIT>' ) ) <EOL> def get_file ( file_path ) : <EOL> """<STR_LIT>""" <EOL> return file_path in _db_content . get ( "<STR_LIT>" ) <EOL> def fake_upload_image ( context , image , instance , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def fake_fetch_image ( context , instance , host , port , dc_name , ds_name , <EOL> file_path , cookies = None ) : <EOL> """<STR_LIT>""" <EOL> ds_file_path = "<STR_LIT:[>" + ds_name + "<STR_LIT>" + file_path <EOL> _add_file ( ds_file_path ) <EOL> def _get_vm_mdo ( vm_ref ) : <EOL> """<STR_LIT>""" <EOL> if _db_content . get ( "<STR_LIT>" , None ) is None : <EOL> raise exception . NotFound ( "<STR_LIT>" ) <EOL> if vm_ref not in _db_content . get ( "<STR_LIT>" ) : <EOL> raise exception . NotFound ( "<STR_LIT>" <EOL> "<STR_LIT>" % vm_ref ) <EOL> return _db_content . get ( "<STR_LIT>" ) [ vm_ref ] <EOL> def _merge_extraconfig ( existing , changes ) : <EOL> """<STR_LIT>""" <EOL> existing = existing or [ ] <EOL> if ( changes ) : <EOL> for c in changes : <EOL> if len ( [ x for x in existing if x . key == c . key ] ) > <NUM_LIT:0> : <EOL> extraConf = [ x for x in existing if x . key == c . key ] [ <NUM_LIT:0> ] <EOL> extraConf . value = c . value <EOL> else : <EOL> existing . append ( c ) <EOL> return existing <EOL> class FakeFactory ( object ) : <EOL> """<STR_LIT>""" <EOL> def create ( self , obj_name ) : <EOL> """<STR_LIT>""" <EOL> klass = obj_name [ <NUM_LIT:4> : ] <EOL> module = sys . modules [ __name__ ] <EOL> fake_klass = getattr ( module , klass , None ) <EOL> if fake_klass is None : <EOL> return DataObject ( obj_name ) <EOL> else : <EOL> return fake_klass ( ) <EOL> class SharesInfo ( DataObject ) : <EOL> def __init__ ( self ) : <EOL> super ( SharesInfo , self ) . __init__ ( ) <EOL> self . level = None <EOL> self . shares = None <EOL> class VirtualEthernetCardResourceAllocation ( DataObject ) : <EOL> def __init__ ( self ) : <EOL> super ( VirtualEthernetCardResourceAllocation , self ) . __init__ ( ) <EOL> self . share = SharesInfo ( ) <EOL> class VirtualE1000 ( DataObject ) : <EOL> def __init__ ( self ) : <EOL> super ( VirtualE1000 , self ) . __init__ ( ) <EOL> self . resourceAllocation = VirtualEthernetCardResourceAllocation ( ) <EOL> class FakeService ( DataObject ) : <EOL> """<STR_LIT>""" <EOL> def Logout ( self , session_manager ) : <EOL> pass <EOL> def FindExtension ( self , extension_manager , key ) : <EOL> return [ ] <EOL> class FakeClient ( DataObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> self . service = FakeService ( ) <EOL> class FakeSession ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . vim = FakeVim ( ) <EOL> def _call_method ( self , module , method , * args , ** kwargs ) : <EOL> raise NotImplementedError ( ) <EOL> def _wait_for_task ( self , task_ref ) : <EOL> raise NotImplementedError ( ) <EOL> class FakeObjectRetrievalSession ( FakeSession ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * ret ) : <EOL> super ( FakeObjectRetrievalSession , self ) . __init__ ( ) <EOL> self . ret = ret <EOL> self . ind = <NUM_LIT:0> <EOL> def _call_method ( self , module , method , * args , ** kwargs ) : <EOL> if ( method == '<STR_LIT>' or <EOL> method == '<STR_LIT>' ) : <EOL> return <EOL> self . ind = ( self . ind + <NUM_LIT:1> ) % len ( self . ret ) <EOL> return self . ret [ self . ind - <NUM_LIT:1> ] <EOL> def get_fake_vim_object ( vmware_api_session ) : <EOL> key = vmware_api_session . __repr__ ( ) <EOL> if key not in _vim_map : <EOL> _vim_map [ key ] = FakeVim ( ) <EOL> return _vim_map [ key ] <EOL> class FakeVim ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , protocol = "<STR_LIT>" , host = "<STR_LIT:localhost>" , trace = None ) : <EOL> """<STR_LIT>""" <EOL> self . _session = None <EOL> self . client = FakeClient ( ) <EOL> self . client . factory = FakeFactory ( ) <EOL> transport = DataObject ( ) <EOL> transport . cookiejar = "<STR_LIT>" <EOL> options = DataObject ( ) <EOL> options . transport = transport <EOL> self . client . options = options <EOL> service_content = self . client . factory . create ( '<STR_LIT>' ) <EOL> service_content . propertyCollector = "<STR_LIT>" <EOL> service_content . virtualDiskManager = "<STR_LIT>" <EOL> service_content . fileManager = "<STR_LIT>" <EOL> service_content . rootFolder = "<STR_LIT>" <EOL> service_content . sessionManager = "<STR_LIT>" <EOL> service_content . extensionManager = "<STR_LIT>" <EOL> service_content . searchIndex = "<STR_LIT>" <EOL> about_info = DataObject ( ) <EOL> about_info . name = "<STR_LIT>" <EOL> about_info . version = "<STR_LIT>" <EOL> about_info . instanceUuid = _FAKE_VCENTER_UUID <EOL> service_content . about = about_info <EOL> self . _service_content = service_content <EOL> @ property <EOL> def service_content ( self ) : <EOL> return self . _service_content <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" <EOL> def _login ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _session = uuidutils . generate_uuid ( ) <EOL> session = DataObject ( ) <EOL> session . key = self . _session <EOL> session . userName = '<STR_LIT>' <EOL> _db_content [ '<STR_LIT>' ] [ self . _session ] = session <EOL> return session <EOL> def _terminate_session ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> s = kwargs . get ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> if s not in _db_content [ '<STR_LIT>' ] : <EOL> return <EOL> del _db_content [ '<STR_LIT>' ] [ s ] <EOL> def _check_session ( self ) : <EOL> """<STR_LIT>""" <EOL> if ( self . _session is None or self . _session not in <EOL> _db_content [ '<STR_LIT>' ] ) : <EOL> LOG . debug ( "<STR_LIT>" ) <EOL> raise vexc . VimFaultException ( [ vexc . NOT_AUTHENTICATED ] , <EOL> "<STR_LIT>" ) <EOL> def _session_is_active ( self , * args , ** kwargs ) : <EOL> try : <EOL> self . _check_session ( ) <EOL> return True <EOL> except Exception : <EOL> return False <EOL> def _create_vm ( self , method , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> config_spec = kwargs . get ( "<STR_LIT>" ) <EOL> if config_spec . guestId not in constants . VALID_OS_TYPES : <EOL> ex = vexc . VMwareDriverException ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return create_task ( method , "<STR_LIT:error>" , error_fault = ex ) . obj <EOL> pool = kwargs . get ( '<STR_LIT>' ) <EOL> version = getattr ( config_spec , '<STR_LIT:version>' , None ) <EOL> devices = [ ] <EOL> for device_change in config_spec . deviceChange : <EOL> if device_change . operation == '<STR_LIT>' : <EOL> devices . append ( device_change . device ) <EOL> vm_ref = create_vm ( config_spec . instanceUuid , config_spec . name , <EOL> config_spec . numCPUs , config_spec . memoryMB , <EOL> devices , config_spec . files . vmPathName , <EOL> config_spec . extraConfig , pool , <EOL> version = version ) <EOL> task_mdo = create_task ( method , "<STR_LIT:success>" , result = vm_ref ) <EOL> return task_mdo . obj <EOL> def _create_folder ( self , method , * args , ** kwargs ) : <EOL> return create_folder ( ) <EOL> def _reconfig_vm ( self , method , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> vm_ref = args [ <NUM_LIT:0> ] <EOL> vm_mdo = _get_vm_mdo ( vm_ref ) <EOL> vm_mdo . reconfig ( self . client . factory , kwargs . get ( "<STR_LIT>" ) ) <EOL> task_mdo = create_task ( method , "<STR_LIT:success>" ) <EOL> return task_mdo . obj <EOL> def _rename ( self , method , * args , ** kwargs ) : <EOL> vm_ref = args [ <NUM_LIT:0> ] <EOL> vm_mdo = _get_vm_mdo ( vm_ref ) <EOL> vm_mdo . set ( '<STR_LIT:name>' , kwargs [ '<STR_LIT>' ] ) <EOL> task_mdo = create_task ( method , "<STR_LIT:success>" ) <EOL> return task_mdo . obj <EOL> def _create_copy_disk ( self , method , vmdk_file_path ) : <EOL> """<STR_LIT>""" <EOL> flat_vmdk_file_path = vmdk_file_path . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> _add_file ( vmdk_file_path ) <EOL> _add_file ( flat_vmdk_file_path ) <EOL> task_mdo = create_task ( method , "<STR_LIT:success>" ) <EOL> return task_mdo . obj <EOL> def _extend_disk ( self , method , size ) : <EOL> """<STR_LIT>""" <EOL> task_mdo = create_task ( method , "<STR_LIT:success>" ) <EOL> return task_mdo . obj <EOL> def _snapshot_vm ( self , method ) : <EOL> """<STR_LIT>""" <EOL> task_mdo = create_task ( method , "<STR_LIT:success>" ) <EOL> return task_mdo . obj <EOL> def _find_all_by_uuid ( self , * args , ** kwargs ) : <EOL> uuid = kwargs . get ( '<STR_LIT>' ) <EOL> vm_refs = [ ] <EOL> for vm_ref in _db_content . get ( "<STR_LIT>" ) : <EOL> vm = _get_object ( vm_ref ) <EOL> vm_uuid = vm . get ( "<STR_LIT>" ) <EOL> if vm_uuid == uuid : <EOL> vm_refs . append ( vm_ref ) <EOL> return vm_refs <EOL> def _delete_snapshot ( self , method , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> task_mdo = create_task ( method , "<STR_LIT:success>" ) <EOL> return task_mdo . obj <EOL> def _delete_file ( self , method , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> _remove_file ( kwargs . get ( "<STR_LIT:name>" ) ) <EOL> task_mdo = create_task ( method , "<STR_LIT:success>" ) <EOL> return task_mdo . obj <EOL> def _just_return ( self ) : <EOL> """<STR_LIT>""" <EOL> return <EOL> def _just_return_task ( self , method ) : <EOL> """<STR_LIT>""" <EOL> task_mdo = create_task ( method , "<STR_LIT:success>" ) <EOL> return task_mdo . obj <EOL> def _clone_vm ( self , method , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> source_vmref = args [ <NUM_LIT:0> ] <EOL> source_vm_mdo = _get_vm_mdo ( source_vmref ) <EOL> clone_spec = kwargs . get ( "<STR_LIT>" ) <EOL> vm_dict = { <EOL> "<STR_LIT:name>" : kwargs . get ( "<STR_LIT:name>" ) , <EOL> "<STR_LIT>" : source_vm_mdo . get ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : source_vm_mdo . get ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : source_vm_mdo . get ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : source_vm_mdo . get ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : source_vm_mdo . get ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : source_vm_mdo . get ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" : source_vm_mdo . get ( "<STR_LIT>" ) . OptionValue , <EOL> "<STR_LIT>" : <EOL> source_vm_mdo . get ( "<STR_LIT>" ) . VirtualDevice , <EOL> "<STR_LIT>" : source_vm_mdo . get ( "<STR_LIT>" ) } <EOL> if hasattr ( clone_spec , '<STR_LIT>' ) : <EOL> if ( hasattr ( clone_spec . config , '<STR_LIT>' ) and <EOL> clone_spec . config . instanceUuid is not None ) : <EOL> vm_dict [ "<STR_LIT>" ] = clone_spec . config . instanceUuid <EOL> if hasattr ( clone_spec . config , '<STR_LIT>' ) : <EOL> extraConfigs = _merge_extraconfig ( vm_dict [ "<STR_LIT>" ] , <EOL> clone_spec . config . extraConfig ) <EOL> vm_dict [ "<STR_LIT>" ] = extraConfigs <EOL> virtual_machine = VirtualMachine ( ** vm_dict ) <EOL> _create_object ( "<STR_LIT>" , virtual_machine ) <EOL> task_mdo = create_task ( method , "<STR_LIT:success>" ) <EOL> return task_mdo . obj <EOL> def _unregister_vm ( self , method , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> vm_ref = args [ <NUM_LIT:0> ] <EOL> _get_vm_mdo ( vm_ref ) <EOL> del _db_content [ "<STR_LIT>" ] [ vm_ref ] <EOL> task_mdo = create_task ( method , "<STR_LIT:success>" ) <EOL> return task_mdo . obj <EOL> def _search_ds ( self , method , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> ds_path = kwargs . get ( "<STR_LIT>" ) <EOL> matched_files = set ( ) <EOL> directory = False <EOL> dname = '<STR_LIT>' % ds_path <EOL> for file in _db_content . get ( "<STR_LIT>" ) : <EOL> if file == dname : <EOL> directory = True <EOL> break <EOL> if directory : <EOL> for file in _db_content . get ( "<STR_LIT>" ) : <EOL> if file . find ( ds_path ) != - <NUM_LIT:1> : <EOL> if not file . endswith ( ds_path ) : <EOL> path = file . replace ( dname , '<STR_LIT>' , <NUM_LIT:1> ) . split ( '<STR_LIT:/>' ) <EOL> if path : <EOL> matched_files . add ( path [ <NUM_LIT:0> ] ) <EOL> if not matched_files : <EOL> matched_files . add ( '<STR_LIT:/>' ) <EOL> else : <EOL> for file in _db_content . get ( "<STR_LIT>" ) : <EOL> if file . find ( ds_path ) != - <NUM_LIT:1> : <EOL> matched_files . add ( ds_path ) <EOL> if matched_files : <EOL> result = DataObject ( ) <EOL> result . path = ds_path <EOL> result . file = [ ] <EOL> for file in matched_files : <EOL> matched = DataObject ( ) <EOL> matched . path = file <EOL> matched . fileSize = <NUM_LIT> <EOL> result . file . append ( matched ) <EOL> task_mdo = create_task ( method , "<STR_LIT:success>" , result = result ) <EOL> else : <EOL> task_mdo = create_task ( method , "<STR_LIT:error>" , error_fault = FileNotFound ( ) ) <EOL> return task_mdo . obj <EOL> def _move_file ( self , method , * args , ** kwargs ) : <EOL> source = kwargs . get ( '<STR_LIT>' ) <EOL> destination = kwargs . get ( '<STR_LIT>' ) <EOL> new_files = [ ] <EOL> if source != destination : <EOL> for file in _db_content . get ( "<STR_LIT>" ) : <EOL> if source in file : <EOL> new_file = file . replace ( source , destination ) <EOL> new_files . append ( new_file ) <EOL> _remove_file ( source ) <EOL> for file in new_files : <EOL> _add_file ( file ) <EOL> task_mdo = create_task ( method , "<STR_LIT:success>" ) <EOL> return task_mdo . obj <EOL> def _make_dir ( self , method , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> ds_path = kwargs . get ( "<STR_LIT:name>" ) <EOL> if get_file ( ds_path ) : <EOL> raise vexc . FileAlreadyExistsException ( ) <EOL> _db_content [ "<STR_LIT>" ] . append ( '<STR_LIT>' % ds_path ) <EOL> def _set_power_state ( self , method , vm_ref , pwr_state = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> if _db_content . get ( "<STR_LIT>" , None ) is None : <EOL> raise exception . NotFound ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if vm_ref not in _db_content . get ( "<STR_LIT>" ) : <EOL> raise exception . NotFound ( "<STR_LIT>" <EOL> "<STR_LIT>" % vm_ref ) <EOL> vm_mdo = _db_content . get ( "<STR_LIT>" ) . get ( vm_ref ) <EOL> vm_mdo . set ( "<STR_LIT>" , pwr_state ) <EOL> task_mdo = create_task ( method , "<STR_LIT:success>" ) <EOL> return task_mdo . obj <EOL> def _retrieve_properties_continue ( self , method , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return FakeRetrieveResult ( ) <EOL> def _retrieve_properties_cancel ( self , method , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return None <EOL> def _retrieve_properties ( self , method , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> spec_set = kwargs . get ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> spec_type = spec_set . propSet [ <NUM_LIT:0> ] . type <EOL> properties = spec_set . propSet [ <NUM_LIT:0> ] . pathSet <EOL> if not isinstance ( properties , list ) : <EOL> properties = properties . split ( ) <EOL> objs = spec_set . objectSet <EOL> lst_ret_objs = FakeRetrieveResult ( ) <EOL> for obj in objs : <EOL> try : <EOL> obj_ref = obj . obj <EOL> if obj_ref == "<STR_LIT>" : <EOL> mdo_refs = _db_content [ spec_type ] <EOL> elif obj_ref . type != spec_type : <EOL> parent_mdo = _db_content [ obj_ref . type ] [ obj_ref ] <EOL> path = obj . selectSet [ <NUM_LIT:0> ] . path <EOL> mdo_refs = parent_mdo . get ( path ) . ManagedObjectReference <EOL> else : <EOL> mdo_refs = [ obj_ref ] <EOL> for mdo_ref in mdo_refs : <EOL> mdo = _db_content [ spec_type ] [ mdo_ref ] <EOL> prop_list = [ ] <EOL> for prop_name in properties : <EOL> prop = Prop ( prop_name , mdo . get ( prop_name ) ) <EOL> prop_list . append ( prop ) <EOL> obj_content = ObjectContent ( mdo . obj , prop_list ) <EOL> lst_ret_objs . add_object ( obj_content ) <EOL> except Exception : <EOL> LOG . exception ( "<STR_LIT>" ) <EOL> continue <EOL> return lst_ret_objs <EOL> def _add_port_group ( self , method , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> _host_sk = list ( _db_content [ "<STR_LIT>" ] . keys ( ) ) [ <NUM_LIT:0> ] <EOL> host_mdo = _db_content [ "<STR_LIT>" ] [ _host_sk ] <EOL> host_mdo . _add_port_group ( kwargs . get ( "<STR_LIT>" ) ) <EOL> def _add_iscsi_send_tgt ( self , method , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> send_targets = kwargs . get ( '<STR_LIT>' ) <EOL> host_storage_sys = _get_objects ( '<STR_LIT>' ) . objects [ <NUM_LIT:0> ] <EOL> iscsi_hba_array = host_storage_sys . get ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> iscsi_hba = iscsi_hba_array . HostHostBusAdapter [ <NUM_LIT:0> ] <EOL> if hasattr ( iscsi_hba , '<STR_LIT>' ) : <EOL> iscsi_hba . configuredSendTarget . extend ( send_targets ) <EOL> else : <EOL> iscsi_hba . configuredSendTarget = send_targets <EOL> def __getattr__ ( self , attr_name ) : <EOL> if attr_name != "<STR_LIT>" : <EOL> self . _check_session ( ) <EOL> if attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _login ( ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _session_is_active ( <EOL> * args , ** kwargs ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _terminate_session ( <EOL> * args , ** kwargs ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _create_vm ( attr_name , <EOL> * args , ** kwargs ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _create_folder ( attr_name , <EOL> * args , ** kwargs ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _reconfig_vm ( attr_name , <EOL> * args , ** kwargs ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _rename ( attr_name , <EOL> * args , ** kwargs ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _create_copy_disk ( attr_name , <EOL> kwargs . get ( "<STR_LIT:name>" ) ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _delete_file ( attr_name , <EOL> * args , ** kwargs ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _set_power_state ( attr_name , <EOL> args [ <NUM_LIT:0> ] , "<STR_LIT>" ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _set_power_state ( attr_name , <EOL> args [ <NUM_LIT:0> ] , "<STR_LIT>" ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _just_return ( ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _set_power_state ( attr_name , <EOL> args [ <NUM_LIT:0> ] , "<STR_LIT>" ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _set_power_state ( attr_name , <EOL> args [ <NUM_LIT:0> ] , "<STR_LIT>" ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _snapshot_vm ( attr_name ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _delete_snapshot ( attr_name , <EOL> * args , ** kwargs ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _create_copy_disk ( attr_name , <EOL> kwargs . get ( "<STR_LIT>" ) ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _extend_disk ( attr_name , <EOL> kwargs . get ( "<STR_LIT:size>" ) ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _unregister_vm ( attr_name , <EOL> * args , ** kwargs ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _unregister_vm ( attr_name , <EOL> * args , ** kwargs ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _clone_vm ( attr_name , <EOL> * args , ** kwargs ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _find_all_by_uuid ( attr_name , <EOL> * args , ** kwargs ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _search_ds ( attr_name , <EOL> * args , ** kwargs ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _move_file ( attr_name , <EOL> * args , ** kwargs ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _make_dir ( attr_name , <EOL> * args , ** kwargs ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _retrieve_properties ( <EOL> attr_name , * args , ** kwargs ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _retrieve_properties_continue ( <EOL> attr_name , * args , ** kwargs ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _retrieve_properties_cancel ( <EOL> attr_name , * args , ** kwargs ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _add_port_group ( attr_name , <EOL> * args , ** kwargs ) <EOL> elif attr_name in ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ) : <EOL> return lambda * args , ** kwargs : self . _just_return_task ( attr_name ) <EOL> elif attr_name == "<STR_LIT>" : <EOL> return lambda * args , ** kwargs : self . _add_iscsi_send_tgt ( attr_name , <EOL> * args , ** kwargs ) </s>
