rtslib/root.py
def restore(self, config, target=None, storage_object=None,
                clear_existing=False, abort_on_error=False):
        '''
        Takes a dict generated by dump() and reconfigures the target to match.
        Returns list of non-fatal errors that were encountered.
        Will refuse to restore over an existing configuration unless clear_existing
            is True.
        '''
        if clear_existing:
            self.clear_existing(target, storage_object, confirm=True)
        elif any(self.storage_objects) or any(self.targets):
            if any(self.storage_objects):
                for config_so in config.get('storage_objects', []):
                    for loaded_so in self.storage_objects:
                        if config_so['name'] == loaded_so.name and \
                           config_so['plugin'] == loaded_so.plugin:
                            raise RTSLibError("storageobject '%s:%s' exist not restoring"
                                              %(loaded_so.plugin, loaded_so.name))

            if any(self.targets):
                for config_tg in config.get('targets', []):
                    for loaded_tg in self.targets:
                        if config_tg['wwn'] == loaded_tg.wwn:
                            raise RTSLibError("target with wwn %s exist, not restoring"
                                              %(loaded_tg.wwn))
        errors = []

        if abort_on_error:
            def err_func(err_str):
                raise RTSLibError(err_str)
        else:
            def err_func(err_str):
                errors.append(err_str + ", skipped")

        for index, so in enumerate(config.get('storage_objects', [])):
            if 'name' not in so:
                err_func("'name' not defined in storage object %d" % index)
                continue

            # * Restore/load the single matching storage object if
            #   storage_object=blockx was supplied with restoreconfig command
            # * In case if no storage_object was supplied but only target=iqn.xxx
            #   was supplied then do not load any storage_object's
            # * If neither storage_object nor target option was supplied to
            #   restoreconfig, then go ahead and load all storage_object's
            if (not storage_object and not target) or (storage_object and so['name'] == storage_object):
                try:
                    so_cls = so_mapping[so['plugin']]
                except KeyError:
                    err_func("'plugin' not defined or invalid in storageobject %s" % so['name'])
                    if storage_object:
                        break
                    continue
                kwargs = so.copy()
                dict_remove(kwargs, ('exists', 'attributes', 'plugin', 'buffered_mode', 'alua_tpgs'))
                try:
                    so_obj = so_cls(**kwargs)
                except Exception as e:
                    err_func("Could not create StorageObject %s: %s" % (so['name'], e))
                    if storage_object:
                        break
                    continue

                # Custom err func to include block name
                def so_err_func(x):
                    return err_func("Storage Object %s/%s: %s" % (so['plugin'], so['name'], x))

                set_attributes(so_obj, so.get('attributes', {}), so_err_func)

                for alua_tpg in so.get('alua_tpgs', {}):
                    try:
                        ALUATargetPortGroup.setup(so_obj, alua_tpg, err_func)
                    except RTSLibALUANotSupported:
                        pass

                if storage_object:
                    break

        # Don't need to create fabric modules
        for index, fm in enumerate(config.get('fabric_modules', [])):
            if 'name' not in fm:
                err_func("'name' not defined in fabricmodule %d" % index)
                continue
            for fm_obj in self.fabric_modules:
                if fm['name'] == fm_obj.name:
                    fm_obj.setup(fm, err_func)
                    break

        for index, t in enumerate(config.get('targets', [])):
            if 'wwn' not in t:
                err_func("'wwn' not defined in target %d" % index)
                continue

            # * Restore/load the single matching target if target=iqn.xxx was
            #   supplied with restoreconfig command
            # * In case if no target was supplied but only storage_object=blockx
            #   was supplied then do not load any targets
            # * If neither storage_object nor target option was supplied to
            #   restoreconfig, then go ahead and load all targets
            if (not storage_object and not target) or (target and t['wwn'] == target):
                if 'fabric' not in t:
                    err_func("target %s missing 'fabric' field" % t['wwn'])
                    if target:
                        break
                    continue
                if t['fabric'] not in (f.name for f in self.fabric_modules):
                    err_func("Unknown fabric '%s'" % t['fabric'])
                    if target:
                        break
                    continue

                fm_obj = FabricModule(t['fabric'])

                # Instantiate target
                Target.setup(fm_obj, t, err_func)

                if target:
                    break

        return errors

        Takes a dict generated by dump() and reconfigures the target to match.
        Returns list of non-fatal errors that were encountered.
        Will refuse to restore over an existing configuration unless clear_existing
            is True.
        
Takes a dict generated by dump() and reconfigures the target to match.
Returns list of non-fatal errors that were encountered.
Will refuse to restore over an existing configuration unless clear_existing
is True.
Takes a dict generated by dump () and reconfigures the target to match . Returns list of non - fatal errors that were encountered . Will refuse to restore over an existing configuration unless clear_existing is True .
def restore(self, config, target=None, storage_object=None,
                clear_existing=False, abort_on_error=False):
        if clear_existing:
            self.clear_existing(target, storage_object, confirm=True)
        elif any(self.storage_objects) or any(self.targets):
            if any(self.storage_objects):
                for config_so in config.get('storage_objects', []):
                    for loaded_so in self.storage_objects:
                        if config_so['name'] == loaded_so.name and \
                           config_so['plugin'] == loaded_so.plugin:
                            raise RTSLibError("storageobject '%s:%s' exist not restoring"
                                              %(loaded_so.plugin, loaded_so.name))
            if any(self.targets):
                for config_tg in config.get('targets', []):
                    for loaded_tg in self.targets:
                        if config_tg['wwn'] == loaded_tg.wwn:
                            raise RTSLibError("target with wwn %s exist, not restoring"
                                              %(loaded_tg.wwn))
        errors = []
        if abort_on_error:
            def err_func(err_str):
                raise RTSLibError(err_str)
        else:
            def err_func(err_str):
                errors.append(err_str + ", skipped")
        for index, so in enumerate(config.get('storage_objects', [])):
            if 'name' not in so:
                err_func("'name' not defined in storage object %d" % index)
                continue
            if (not storage_object and not target) or (storage_object and so['name'] == storage_object):
                try:
                    so_cls = so_mapping[so['plugin']]
                except KeyError:
                    err_func("'plugin' not defined or invalid in storageobject %s" % so['name'])
                    if storage_object:
                        break
                    continue
                kwargs = so.copy()
                dict_remove(kwargs, ('exists', 'attributes', 'plugin', 'buffered_mode', 'alua_tpgs'))
                try:
                    so_obj = so_cls(**kwargs)
                except Exception as e:
                    err_func("Could not create StorageObject %s: %s" % (so['name'], e))
                    if storage_object:
                        break
                    continue
                def so_err_func(x):
                    return err_func("Storage Object %s/%s: %s" % (so['plugin'], so['name'], x))
                set_attributes(so_obj, so.get('attributes', {}), so_err_func)
                for alua_tpg in so.get('alua_tpgs', {}):
                    try:
                        ALUATargetPortGroup.setup(so_obj, alua_tpg, err_func)
                    except RTSLibALUANotSupported:
                        pass
                if storage_object:
                    break
        for index, fm in enumerate(config.get('fabric_modules', [])):
            if 'name' not in fm:
                err_func("'name' not defined in fabricmodule %d" % index)
                continue
            for fm_obj in self.fabric_modules:
                if fm['name'] == fm_obj.name:
                    fm_obj.setup(fm, err_func)
                    break
        for index, t in enumerate(config.get('targets', [])):
            if 'wwn' not in t:
                err_func("'wwn' not defined in target %d" % index)
                continue
            if (not storage_object and not target) or (target and t['wwn'] == target):
                if 'fabric' not in t:
                    err_func("target %s missing 'fabric' field" % t['wwn'])
                    if target:
                        break
                    continue
                if t['fabric'] not in (f.name for f in self.fabric_modules):
                    err_func("Unknown fabric '%s'" % t['fabric'])
                    if target:
                        break
                    continue
                fm_obj = FabricModule(t['fabric'])
                Target.setup(fm_obj, t, err_func)
                if target:
                    break
        return errors
def restore ( self , config , target = None , storage_object = None , clear_existing = False , abort_on_error = False ) : if clear_existing : self . clear_existing ( target , storage_object , confirm = True ) elif any ( self . storage_objects ) or any ( self . targets ) : if any ( self . storage_objects ) : for config_so in config . get ( 'storage_objects' , [ ] ) : for loaded_so in self . storage_objects : if config_so [ 'name' ] == loaded_so . name and config_so [ 'plugin' ] == loaded_so . plugin : raise RTSLibError ( "storageobject '%s:%s' exist not restoring" % ( loaded_so . plugin , loaded_so . name ) ) if any ( self . targets ) : for config_tg in config . get ( 'targets' , [ ] ) : for loaded_tg in self . targets : if config_tg [ 'wwn' ] == loaded_tg . wwn : raise RTSLibError ( "target with wwn %s exist, not restoring" % ( loaded_tg . wwn ) ) errors = [ ] if abort_on_error : def err_func ( err_str ) : raise RTSLibError ( err_str ) else : def err_func ( err_str ) : errors . append ( err_str + ", skipped" ) for index , so in enumerate ( config . get ( 'storage_objects' , [ ] ) ) : if 'name' not in so : err_func ( "'name' not defined in storage object %d" % index ) continue if ( not storage_object and not target ) or ( storage_object and so [ 'name' ] == storage_object ) : try : so_cls = so_mapping [ so [ 'plugin' ] ] except KeyError : err_func ( "'plugin' not defined or invalid in storageobject %s" % so [ 'name' ] ) if storage_object : break continue kwargs = so . copy ( ) dict_remove ( kwargs , ( 'exists' , 'attributes' , 'plugin' , 'buffered_mode' , 'alua_tpgs' ) ) try : so_obj = so_cls ( ** kwargs ) except Exception as e : err_func ( "Could not create StorageObject %s: %s" % ( so [ 'name' ] , e ) ) if storage_object : break continue def so_err_func ( x ) : return err_func ( "Storage Object %s/%s: %s" % ( so [ 'plugin' ] , so [ 'name' ] , x ) ) set_attributes ( so_obj , so . get ( 'attributes' , { } ) , so_err_func ) for alua_tpg in so . get ( 'alua_tpgs' , { } ) : try : ALUATargetPortGroup . setup ( so_obj , alua_tpg , err_func ) except RTSLibALUANotSupported : pass if storage_object : break for index , fm in enumerate ( config . get ( 'fabric_modules' , [ ] ) ) : if 'name' not in fm : err_func ( "'name' not defined in fabricmodule %d" % index ) continue for fm_obj in self . fabric_modules : if fm [ 'name' ] == fm_obj . name : fm_obj . setup ( fm , err_func ) break for index , t in enumerate ( config . get ( 'targets' , [ ] ) ) : if 'wwn' not in t : err_func ( "'wwn' not defined in target %d" % index ) continue if ( not storage_object and not target ) or ( target and t [ 'wwn' ] == target ) : if 'fabric' not in t : err_func ( "target %s missing 'fabric' field" % t [ 'wwn' ] ) if target : break continue if t [ 'fabric' ] not in ( f . name for f in self . fabric_modules ) : err_func ( "Unknown fabric '%s'" % t [ 'fabric' ] ) if target : break continue fm_obj = FabricModule ( t [ 'fabric' ] ) Target . setup ( fm_obj , t , err_func ) if target : break return errors
Takes a dict generated by dump() and reconfigures the target to match.
Takes a dict generated by dump () and reconfigures the target to match .
'''
        Takes a dict generated by dump() and reconfigures the target to match.
        Returns list of non-fatal errors that were encountered.
        Will refuse to restore over an existing configuration unless clear_existing
            is True.
        ''' # * Restore/load the single matching storage object if #   storage_object=blockx was supplied with restoreconfig command # * In case if no storage_object was supplied but only target=iqn.xxx #   was supplied then do not load any storage_object's # * If neither storage_object nor target option was supplied to #   restoreconfig, then go ahead and load all storage_object's # Custom err func to include block name # Don't need to create fabric modules # * Restore/load the single matching target if target=iqn.xxx was #   supplied with restoreconfig command # * In case if no target was supplied but only storage_object=blockx #   was supplied then do not load any targets # * If neither storage_object nor target option was supplied to #   restoreconfig, then go ahead and load all targets # Instantiate target
self
config
target
storage_object
clear_existing
abort_on_error