Exemple #1
0
def _tpg_lun_of(tpg, pool_name, vol_name):
    """
    Return a object of LUN for given lvm lv.
    If not exist, create one.
    """
    # get wwn of volume so LIO can export as vpd83 info
    vg_name, thin_pool = get_vg_lv(pool_name)
    vol_serial = bd.lvm.lvinfo(vg_name, vol_name).uuid

    # only add new SO if it doesn't exist
    # so.name concats pool & vol names separated by ':'
    so_name = "%s:%s" % (vg_name, vol_name)
    try:
        so = BlockStorageObject(so_name)
    except RTSLibError:
        so = BlockStorageObject(
            so_name, dev="/dev/%s/%s" % (vg_name, vol_name))
        so.wwn = vol_serial

    # export useful scsi model if kernel > 3.8
    with ignored(RTSLibError):
        so.set_attribute("emulate_model_alias", '1')

    # only add tpg lun if it doesn't exist
    for tmp_lun in tpg.luns:
        if tmp_lun.storage_object.name == so.name and \
           tmp_lun.storage_object.plugin == 'block':
            return tmp_lun
    else:
        return LUN(tpg, storage_object=so)
Exemple #2
0
def _tpg_lun_of(tpg, pool_name, vol_name):
    """
    Return a object of LUN for given pool and volume.
    If not exist, create one.
    """
    mod = pool_module(pool_name)
    # get wwn of volume so LIO can export as vpd83 info
    vol_serial = mod.vol_info(pool_name, vol_name).uuid

    # only add new SO if it doesn't exist
    # so.name concats pool & vol names separated by ':'
    so_name = mod.get_so_name(pool_name, vol_name)
    try:
        so = BlockStorageObject(so_name)
    except RTSLibError:
        so = BlockStorageObject(
            so_name, dev=mod.get_dev_path(pool_name, vol_name))
        so.wwn = vol_serial

    # export useful scsi model if kernel > 3.8
    with ignored(RTSLibError):
        so.set_attribute("emulate_model_alias", '1')

    # only add tpg lun if it doesn't exist
    for tmp_lun in tpg.luns:
        if tmp_lun.storage_object.name == so.name and \
                tmp_lun.storage_object.plugin == 'block':
            return tmp_lun
    else:
        return LUN(tpg, storage_object=so)
Exemple #3
0
    def create_lun(self, tpg, blockstore):
        wwn = tpg.parent_target.wwn
        lun_list = self.target[wwn]['tpg'][tpg.tag]['lun']
        lun = lun_list.get(blockstore.name, None)

        if lun is None:
            Log.info('creating lun %s, blockstore %s' % (tpg, blockstore))
            # Create the LUN
            lun = LUN(tpg, 0, blockstore)
            # Add it to the local data structure for tracking LUNs
            lun_list[blockstore.name] = lun
        else:
            # LUN already exists
            Log.info('lun %s already exists, not creating' % (blockstore.name))

        return lun