Esempio n. 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)

    with vgopen(vg_name) as vg:
        vol_serial = vg.lvFromName(vol_name).getUuid()

    # 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)
Esempio n. 2
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)
Esempio n. 3
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)