示例#1
0
文件: block.py 项目: MPSTOR/Konnector
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)
示例#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)
示例#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)
示例#4
0
    def ui_command_create(self, name, dev, readonly=None, wwn=None):
        '''
        Creates an Block Storage object. I{dev} is the path to the TYPE_DISK
        block device to use.
        '''
        self.assert_root()

        readonly = self.ui_eval_param(readonly, 'bool', False)
        wwn = self.ui_eval_param(wwn, 'string', None)

        so = BlockStorageObject(name, dev, readonly=readonly, wwn=wwn)
        ui_so = UIBlockStorageObject(so, self)
        self.setup_model_alias(so)
        self.shell.log.info("Created block storage object %s using %s." %
                            (name, dev))
        return self.new_node(ui_so)
示例#5
0
    def create_block_store(self, wwn, device):
        """Create a blockstore with the given wwn. It is assumed that the
        blockstore does not already exists. Calling this method when the
        storage already exists can potentially result in an exception being
        thrown. Call get_block_store first to check for existence.

        Parameters
        ----------
        wwn : string
            World Wide Name for the block store
        device : string
            Path to a block device

        Returns:
        --------
        blockstore object, if it was successfully created
        """
        Log.info('creating block backstore %s for device %s' % (wwn, device))
        storage = BlockStorageObject(wwn, device, wwn)
        self.block_store[wwn] = storage
        return storage
示例#6
0
    def add_dev_to_lio(self, in_wwn=None):
        """
        Add an rbd device to the LIO configuration
        :param in_wwn: optional wwn identifying the rbd image to clients - must match across gateways
        :return: LIO LUN object
        """

        self.logger.info(
            "(LUN.add_dev_to_lio) Adding image '{}' with path {} to LIO".
            format(self.image, self.dm_device))
        new_lun = None
        try:
            new_lun = BlockStorageObject(name=self.config_key,
                                         dev=self.dm_device,
                                         wwn=in_wwn)
        except RTSLibError as err:
            self.error = True
            self.error_msg = "failed to add {} to LIO - error({})".format(
                self.image, str(err))

        return new_lun
示例#7
0
def rbd_add_device(module, image, device_path, in_wwn=None):
    """
    Add an rbd device to the LIO configuration
    :param module: ansible module used to run CLI commands
    :param image: rbd image name (str)
    :param device_path: path for the device e.g. /dev/rbdX
    :param in_wwn: optional wwn identifying the rbd image to clients - must match across gateways
    :return: LIO LUN object
    """

    logger.info("(add_device) Adding image '{}' with path {} to LIO".format(
        image, device_path))
    new_lun = None
    try:
        new_lun = BlockStorageObject(name=image, dev=device_path, wwn=in_wwn)
        set_alua(new_lun, "standby")
    except RTSLibError as err:
        module.fail_json(
            msg="failed to add {} to LIO - error({})".format(image, str(err)))

    return new_lun
示例#8
0
    def ui_command_create(self, name, dev, readonly=None, wwn=None):
        '''
        Creates an Block Storage object. "dev" is the path to the TYPE_DISK
        block device to use.
        '''
        self.assert_root()

        ro_string = self.ui_eval_param(readonly, 'string', None)
        if ro_string == None:
            # attempt to detect block device readonly state via ioctl
            readonly = self._ui_block_ro_check(dev)
        else:
            readonly = self.ui_eval_param(readonly, 'bool', False)

        wwn = self.ui_eval_param(wwn, 'string', None)

        so = BlockStorageObject(name, dev, readonly=readonly, wwn=wwn)
        ui_so = UIBlockStorageObject(so, self)
        self.setup_model_alias(so)
        self.shell.log.info("Created block storage object %s using %s." %
                            (name, dev))
        return self.new_node(ui_so)
示例#9
0
def main():
    f = BlockStorageObject()