rtslib/root.py
def _get_saveconf(self, so_path, save_file):
        '''
        Fetch the configuration of all the blocks and return conf with
        updated storageObject info and its related target configuraion of
        given storage object path
        '''
        current = self.dump()

        try:
            with open(save_file, "r") as f:
                saveconf = json.loads(f.read())
        except IOError as e:
            if e.errno == errno.ENOENT:
                saveconf = {'storage_objects': [], 'targets': []}
            else:
                raise ExecutionError("Could not open %s" % save_file)

        fetch_cur_so = False
        fetch_cur_tg = False
        # Get the given block current storageObj configuration
        for sidx, sobj in enumerate(current.get('storage_objects', [])):
            if '/backstores/' + sobj['plugin'] + '/' + sobj['name'] == so_path:
                current_so = current['storage_objects'][sidx]
                fetch_cur_so = True
                break

        # Get the given block current target configuration
        if fetch_cur_so:
            for tidx, tobj in enumerate(current.get('targets', [])):
                if fetch_cur_tg:
                    break
                for luns in tobj.get('tpgs', []):
                    if fetch_cur_tg:
                        break
                    for lun in luns.get('luns', []):
                        if lun['storage_object'] == so_path:
                            current_tg = current['targets'][tidx]
                            fetch_cur_tg = True
                            break

        fetch_sav_so = False
        fetch_sav_tg = False
        # Get the given block storageObj from saved configuration
        for sidx, sobj in enumerate(saveconf.get('storage_objects', [])):
            if '/backstores/' + sobj['plugin'] + '/' + sobj['name'] == so_path:
                # Merge StorageObj
                if fetch_cur_so:
                    saveconf['storage_objects'][sidx] = current_so
                # Remove StorageObj
                else:
                    saveconf['storage_objects'].remove(saveconf['storage_objects'][sidx])
                fetch_sav_so = True
                break

        # Get the given block target from saved configuration
        if fetch_sav_so:
            for tidx, tobj in enumerate(saveconf.get('targets', [])):
                if fetch_sav_tg:
                    break
                for luns in tobj.get('tpgs', []):
                    if fetch_sav_tg:
                        break
                    for lun in luns.get('luns', []):
                        if lun['storage_object'] == so_path:
                            # Merge target
                            if fetch_cur_tg:
                                saveconf['targets'][tidx] = current_tg
                            # Remove target
                            else:
                                saveconf['targets'].remove(saveconf['targets'][tidx])
                            fetch_sav_tg = True
                            break

        # Insert storageObj
        if fetch_cur_so and not fetch_sav_so:
            saveconf['storage_objects'].append(current_so)
        # Insert target
        if fetch_cur_tg and not fetch_sav_tg:
            saveconf['targets'].append(current_tg)

        return saveconf

        Fetch the configuration of all the blocks and return conf with
        updated storageObject info and its related target configuraion of
        given storage object path
        
Fetch the configuration of all the blocks and return conf with
updated storageObject info and its related target configuraion of
given storage object path
Fetch the configuration of all the blocks and return conf with updated storageObject info and its related target configuraion of given storage object path
def _get_saveconf(self, so_path, save_file):
        current = self.dump()
        try:
            with open(save_file, "r") as f:
                saveconf = json.loads(f.read())
        except IOError as e:
            if e.errno == errno.ENOENT:
                saveconf = {'storage_objects': [], 'targets': []}
            else:
                raise ExecutionError("Could not open %s" % save_file)
        fetch_cur_so = False
        fetch_cur_tg = False
        for sidx, sobj in enumerate(current.get('storage_objects', [])):
            if '/backstores/' + sobj['plugin'] + '/' + sobj['name'] == so_path:
                current_so = current['storage_objects'][sidx]
                fetch_cur_so = True
                break
        if fetch_cur_so:
            for tidx, tobj in enumerate(current.get('targets', [])):
                if fetch_cur_tg:
                    break
                for luns in tobj.get('tpgs', []):
                    if fetch_cur_tg:
                        break
                    for lun in luns.get('luns', []):
                        if lun['storage_object'] == so_path:
                            current_tg = current['targets'][tidx]
                            fetch_cur_tg = True
                            break
        fetch_sav_so = False
        fetch_sav_tg = False
        for sidx, sobj in enumerate(saveconf.get('storage_objects', [])):
            if '/backstores/' + sobj['plugin'] + '/' + sobj['name'] == so_path:
                if fetch_cur_so:
                    saveconf['storage_objects'][sidx] = current_so
                else:
                    saveconf['storage_objects'].remove(saveconf['storage_objects'][sidx])
                fetch_sav_so = True
                break
        if fetch_sav_so:
            for tidx, tobj in enumerate(saveconf.get('targets', [])):
                if fetch_sav_tg:
                    break
                for luns in tobj.get('tpgs', []):
                    if fetch_sav_tg:
                        break
                    for lun in luns.get('luns', []):
                        if lun['storage_object'] == so_path:
                            if fetch_cur_tg:
                                saveconf['targets'][tidx] = current_tg
                            else:
                                saveconf['targets'].remove(saveconf['targets'][tidx])
                            fetch_sav_tg = True
                            break
        if fetch_cur_so and not fetch_sav_so:
            saveconf['storage_objects'].append(current_so)
        if fetch_cur_tg and not fetch_sav_tg:
            saveconf['targets'].append(current_tg)
        return saveconf
def _get_saveconf ( self , so_path , save_file ) : current = self . dump ( ) try : with open ( save_file , "r" ) as f : saveconf = json . loads ( f . read ( ) ) except IOError as e : if e . errno == errno . ENOENT : saveconf = { 'storage_objects' : [ ] , 'targets' : [ ] } else : raise ExecutionError ( "Could not open %s" % save_file ) fetch_cur_so = False fetch_cur_tg = False for sidx , sobj in enumerate ( current . get ( 'storage_objects' , [ ] ) ) : if '/backstores/' + sobj [ 'plugin' ] + '/' + sobj [ 'name' ] == so_path : current_so = current [ 'storage_objects' ] [ sidx ] fetch_cur_so = True break if fetch_cur_so : for tidx , tobj in enumerate ( current . get ( 'targets' , [ ] ) ) : if fetch_cur_tg : break for luns in tobj . get ( 'tpgs' , [ ] ) : if fetch_cur_tg : break for lun in luns . get ( 'luns' , [ ] ) : if lun [ 'storage_object' ] == so_path : current_tg = current [ 'targets' ] [ tidx ] fetch_cur_tg = True break fetch_sav_so = False fetch_sav_tg = False for sidx , sobj in enumerate ( saveconf . get ( 'storage_objects' , [ ] ) ) : if '/backstores/' + sobj [ 'plugin' ] + '/' + sobj [ 'name' ] == so_path : if fetch_cur_so : saveconf [ 'storage_objects' ] [ sidx ] = current_so else : saveconf [ 'storage_objects' ] . remove ( saveconf [ 'storage_objects' ] [ sidx ] ) fetch_sav_so = True break if fetch_sav_so : for tidx , tobj in enumerate ( saveconf . get ( 'targets' , [ ] ) ) : if fetch_sav_tg : break for luns in tobj . get ( 'tpgs' , [ ] ) : if fetch_sav_tg : break for lun in luns . get ( 'luns' , [ ] ) : if lun [ 'storage_object' ] == so_path : if fetch_cur_tg : saveconf [ 'targets' ] [ tidx ] = current_tg else : saveconf [ 'targets' ] . remove ( saveconf [ 'targets' ] [ tidx ] ) fetch_sav_tg = True break if fetch_cur_so and not fetch_sav_so : saveconf [ 'storage_objects' ] . append ( current_so ) if fetch_cur_tg and not fetch_sav_tg : saveconf [ 'targets' ] . append ( current_tg ) return saveconf
Fetch the configuration of all the blocks and return conf with
updated storageObject info and its related target configuraion of
given storage object path
Fetch the configuration of all the blocks and return conf with updated storageObject info and its related target configuraion of given storage object path
'''
        Fetch the configuration of all the blocks and return conf with
        updated storageObject info and its related target configuraion of
        given storage object path
        ''' # Get the given block current storageObj configuration # Get the given block current target configuration # Get the given block storageObj from saved configuration # Merge StorageObj # Remove StorageObj # Get the given block target from saved configuration # Merge target # Remove target # Insert storageObj # Insert target
self
so_path
save_file