def export_destroy(req, pool, vol, initiator_wwn): mod = pool_module(pool) fm = FabricModule('iscsi') t = Target(fm, target_name) tpg = TPG(t, 1) na = NodeACL(tpg, initiator_wwn) pool_dev_name = mod.pool2dev_name(pool) for mlun in na.mapped_luns: # all SOs are Block so we can access udev_path safely if mod.has_udev_path(mlun.tpg_lun.storage_object.udev_path): mlun_vg, mlun_name = \ mod.split_udev_path(mlun.tpg_lun.storage_object.udev_path) if mlun_vg == pool_dev_name and mlun_name == vol: tpg_lun = mlun.tpg_lun mlun.delete() # be tidy and delete unused tpg lun mappings? if not any(tpg_lun.mapped_luns): so = tpg_lun.storage_object tpg_lun.delete() so.delete() break else: raise TargetdError(TargetdError.NOT_FOUND_VOLUME_EXPORT, "Volume '%s' not found in %s exports" % (vol, initiator_wwn)) # Clean up tree if branch has no leaf if not any(na.mapped_luns): na.delete() if not any(tpg.node_acls): tpg.delete() if not any(t.tpgs): t.delete() RTSRoot().save_to_file()
def destroy(req, pool, name): with ignored(RTSLibNotInCFS): fm = FabricModule('iscsi') t = Target(fm, target_name, mode='lookup') tpg = TPG(t, 1, mode='lookup') so_name = get_so_name(pool, name) if so_name in (lun.storage_object.name for lun in tpg.luns): raise TargetdError( TargetdError.VOLUME_MASKED, "Volume '%s' cannot be " "removed while exported" % name) pool_module(pool).destroy(req, pool, name)
def destroy(req, pool, name): with ignored(RTSLibNotInCFS): fm = FabricModule('iscsi') t = Target(fm, target_name, mode='lookup') tpg = TPG(t, 1, mode='lookup') so_name = "%s:%s" % (pool, name) if so_name in (lun.storage_object.name for lun in tpg.luns): raise TargetdError( -303, "Volume '%s' cannot be " "removed while exported" % name) with vgopen(get_vg_lv(pool)[0]) as vg: vg.lvFromName(name).remove()
def export_destroy(req, pool, vol, initiator_wwn): pool_check(pool) fm = FabricModule('iscsi') t = Target(fm, target_name) tpg = TPG(t, 1) na = NodeACL(tpg, initiator_wwn) vg_name, thin_pool = get_vg_lv(pool) for mlun in na.mapped_luns: # all SOs are Block so we can access udev_path safely mlun_vg, mlun_name = \ mlun.tpg_lun.storage_object.udev_path.split("/")[2:] if mlun_vg == vg_name and mlun_name == vol: tpg_lun = mlun.tpg_lun mlun.delete() # be tidy and delete unused tpg lun mappings? if not any(tpg_lun.mapped_luns): so = tpg_lun.storage_object tpg_lun.delete() so.delete() break else: raise TargetdError(-151, "Volume '%s' not found in %s exports" % (vol, initiator_wwn)) # Clean up tree if branch has no leaf if not any(na.mapped_luns): na.delete() if not any(tpg.node_acls): tpg.delete() if not any(t.tpgs): t.delete() RTSRoot().save_to_file()
def export_destroy(req, pool, vol, initiator_wwn): pool_check(pool) fm = FabricModule('iscsi') t = Target(fm, target_name) tpg = TPG(t, 1) na = NodeACL(tpg, initiator_wwn) vg_name, thin_pool = get_vg_lv(pool) for mlun in na.mapped_luns: # all SOs are Block so we can access udev_path safely mlun_vg, mlun_name = \ mlun.tpg_lun.storage_object.udev_path.split("/")[2:] if mlun_vg == vg_name and mlun_name == vol: tpg_lun = mlun.tpg_lun mlun.delete() # be tidy and delete unused tpg lun mappings? if not any(tpg_lun.mapped_luns): so = tpg_lun.storage_object tpg_lun.delete() so.delete() break else: raise TargetdError( -151, "Volume '%s' not found in %s exports" % (vol, initiator_wwn)) # Clean up tree if branch has no leaf if not any(na.mapped_luns): na.delete() if not any(tpg.node_acls): tpg.delete() if not any(t.tpgs): t.delete() RTSRoot().save_to_file()
def create_target(self, wwn): target_dict = self.target.get(wwn, None) target = None if target_dict is None: Log.info('creating target with wwn %s' % (wwn)) # The wwn will be lowercased automatically by something # outside this library. I'm not sure if its RTSLib or # the underlying Linux target system target = Target(self.iscsi, wwn) # Add target to data structure, initialize empty child nodes self.target[wwn] = {'target': target, 'tpg': {}} else: Log.info('target %s already exists, not creating' % (wwn)) target = target_dict['target'] return target
def destroy(req, pool, name): mod = pool_module(pool) if not check_vol_exists(req, pool, name): raise TargetdError(TargetdError.NOT_FOUND_VOLUME, "Volume %s not found in pool %s" % (name, pool)) with ignored(RTSLibNotInCFS): fm = FabricModule('iscsi') t = Target(fm, target_name, mode='lookup') tpg = TPG(t, 1, mode='lookup') so_name = get_so_name(pool, name) if so_name in (lun.storage_object.name for lun in tpg.luns): raise TargetdError(TargetdError.VOLUME_MASKED, "Volume '%s' cannot be " "removed while exported" % name) pool_module(pool).destroy(req, pool, name)
def export_create(req, pool, vol, initiator_wwn, lun): fm = FabricModule('iscsi') t = Target(fm, target_name) tpg = TPG(t, 1) tpg.enable = True tpg.set_attribute("authentication", '0') NetworkPortal(tpg, "0.0.0.0") na = NodeACL(tpg, initiator_wwn) tpg_lun = _tpg_lun_of(tpg, pool, vol) # only add mapped lun if it doesn't exist for tmp_mlun in tpg_lun.mapped_luns: if tmp_mlun.mapped_lun == lun and tmp_mlun.parent_nodeacl == na: break else: MappedLUN(na, lun, tpg_lun) RTSRoot().save_to_file()
def initiator_set_auth(req, initiator_wwn, in_user, in_pass, out_user, out_pass): fm = FabricModule('iscsi') t = Target(fm, target_name) tpg = TPG(t, 1) na = NodeACL(tpg, initiator_wwn) if not in_user or not in_pass: # rtslib treats '' as its NULL value for these in_user = in_pass = '' if not out_user or not out_pass: out_user = out_pass = '' na.chap_userid = in_user na.chap_password = in_pass na.chap_mutual_userid = out_user na.chap_mutual_password = out_pass RTSRoot().save_to_file()
def export_list(req): try: fm = FabricModule('iscsi') t = Target(fm, target_name, mode='lookup') tpg = TPG(t, 1, mode='lookup') except RTSLibNotInCFS: return [] exports = [] for na in tpg.node_acls: for mlun in na.mapped_luns: mod = udev_path_module(mlun.tpg_lun.storage_object.udev_path) mlun_pool, mlun_name = \ mod.split_udev_path(mlun.tpg_lun.storage_object.udev_path) vinfo = mod.vol_info(mod.dev2pool_name(mlun_pool), mlun_name) exports.append( dict(initiator_wwn=na.node_wwn, lun=mlun.mapped_lun, vol_name=mlun_name, pool=mlun_pool, vol_uuid=vinfo.uuid, vol_size=vinfo.size)) return exports
def export_list(req): try: fm = FabricModule('iscsi') t = Target(fm, target_name, mode='lookup') tpg = TPG(t, 1, mode='lookup') except RTSLibNotInCFS: return [] exports = [] for na in tpg.node_acls: for mlun in na.mapped_luns: mlun_vg, mlun_name = \ mlun.tpg_lun.storage_object.udev_path.split("/")[2:] with vgopen(get_vg_lv(mlun_vg)[0]) as vg: lv = vg.lvFromName(mlun_name) exports.append( dict(initiator_wwn=na.node_wwn, lun=mlun.mapped_lun, vol_name=mlun_name, pool=mlun_vg, vol_uuid=lv.getUuid(), vol_size=lv.getSize())) return exports
def export_list(req): try: fm = FabricModule('iscsi') t = Target(fm, target_name, mode='lookup') tpg = TPG(t, 1, mode='lookup') except RTSLibNotInCFS: return [] exports = [] for na in tpg.node_acls: for mlun in na.mapped_luns: mlun_vg, mlun_name = \ mlun.tpg_lun.storage_object.udev_path.split("/")[2:] lv = bd.lvm.lvinfo(mlun_vg, mlun_name) exports.append( dict(initiator_wwn=na.node_wwn, lun=mlun.mapped_lun, vol_name=mlun_name, pool=mlun_vg, vol_uuid=lv.uuid, vol_size=lv.size)) return exports
def _get_iscsi_tpg(): fabric_module = FabricModule('iscsi') target = Target(fabric_module, target_name) return TPG(target, 1)