def with_host(client, host): monkey_patch(infi.hbaapi.generators, "get_list_of_generators", HostSystemPortGeneratorFactory.get) previous = HostSystemPortGeneratorFactory.get() try: HostSystemPortGeneratorFactory.set(HostSystemPortGeneratorFactory.create(client, host)) yield finally: HostSystemPortGeneratorFactory.set(previous)
def with_host(client, host): from infi.pyvmomi_wrapper import get_reference_to_managed_object monkey_patch(infi.iscsiapi, "get_iscsiapi", ConnectionManagerFactory.get) previous = ConnectionManagerFactory.get() try: ConnectionManagerFactory.set(ConnectionManagerFactory.create(client, host)) yield finally: ConnectionManagerFactory.set(previous)
def with_host(client, host): monkey_patch(infi.hbaapi.generators, "get_list_of_generators", HostSystemPortGeneratorFactory.get) previous = HostSystemPortGeneratorFactory.get() try: HostSystemPortGeneratorFactory.set( HostSystemPortGeneratorFactory.create(client, host)) yield finally: HostSystemPortGeneratorFactory.set(previous)
def with_host(client, host): from infi.pyvmomi_wrapper import get_reference_to_managed_object monkey_patch(infi.iscsiapi, "get_iscsiapi", ConnectionManagerFactory.get) previous = ConnectionManagerFactory.get() try: ConnectionManagerFactory.set( ConnectionManagerFactory.create(client, host)) yield finally: ConnectionManagerFactory.set(previous)
def with_host(client, host): from traceback import extract_stack from infi.pyvmomi_wrapper import get_reference_to_managed_object monkey_patch(infi.storagemodel, "get_storage_model", StorageModelFactory.get) previous = StorageModelFactory.get() stack_trace = get_stack_trace() caller = extract_stack(stack_trace, 6)[1][2] moref = get_reference_to_managed_object(host) try: current = StorageModelFactory.set(StorageModelFactory.create(client, host)) if previous is current: logger.debug("entered context for the same host {} as part of {}".format(moref, caller)) else: logger.debug("entered context for host {} as part of {}".format(moref, caller)) yield finally: logger.debug("exited context for host {} as part of {}".format(moref, caller)) StorageModelFactory.set(previous)
def with_host(client, host): from traceback import extract_stack from infi.pyvmomi_wrapper import get_reference_to_managed_object monkey_patch(infi.storagemodel, "get_storage_model", StorageModelFactory.get) previous = StorageModelFactory.get() stack_trace = get_stack_trace() caller = extract_stack(stack_trace, 6)[1][2] moref = get_reference_to_managed_object(host) try: current = StorageModelFactory.set( StorageModelFactory.create(client, host)) if previous is current: logger.debug( "entered context for the same host {} as part of {}".format( moref, caller)) else: logger.debug("entered context for host {} as part of {}".format( moref, caller)) yield finally: logger.debug("exited context for host {} as part of {}".format( moref, caller)) StorageModelFactory.set(previous)