Пример #1
0
    def sendTarget(self, lvName, tpgt, lun, initiatorName, suffix):
        """服务接口,挂载逻辑卷
        
        @param lvName 输出target 
        @param initiatorName 允许访问此逻辑卷的iscsi initor的名称
        @return 返回一个TargetInfo的结构体
        """

        VSLogger.info("Call interface attachLV(%s, %s)..." % (lvName, initiatorName))

        try:
            rollback = VSActionRollback()
            actionTcmCreate(rollback, ("test", lvName))
            # iqn = dnsName2IQN(VSConfig.getHost())
            iqn = "test"
            # targetName = "%s:%d:%s" % (iqn, time.time() * 1000, lvName)
            targetName = "%s:%d:%s" % (iqn, 123456, suffix)
            targetInfo = TargetInfo()
            targetInfo.targetName = targetName
            # targetInfo.targetPort = VSConfig.getIscsiPort()
            targetInfo.chapUser = "******"
            # targetInfo.chapPass = getRandomPass()
            targetInfo.chapPass = "******"
            # "lio_node --addlun %s 1 0 iscsi00 iblock_0/%s_%s" %(targetName, VSConfig.getVgName(), lvName)
            actionLioAddLun(rollback, (targetName, tpgt, lun, "test", lvName))
            # --addnp=TARGET_IQN TPGT IP:PORT
            osCmd = "lio_node --addnp %s %d %s:%d" % (targetName, tpgt, "0.0.0.0", 3260)
            runExec(osCmd)
            # --enableauth=TARGET_IQN TPGT
            osCmd = "lio_node --enableauth %s %d" % (targetName, tpgt)
            runExec(osCmd)
            # lio_node --addlunacl <TargetIQN> <TPG#> <InitiatorIQN> <LUN#> <MappedLUN#>
            osCmd = "lio_node --addlunacl %s %d %s %d 0" % (targetName, tpgt, initiatorName, lun)
            runExec(osCmd)
            # lio_node --setchapauth <TargetIQN> <TPG#><InitiatorIQN> <LoginName> <Password>
            osCmd = "lio_node --setchapauth %s %d %s %s %s" % (
                targetName,
                tpgt,
                initiatorName,
                targetInfo.chapUser,
                targetInfo.chapPass,
            )
            runExec(osCmd)
            #    --settpgattr=TARGET_IQN TPGT <ATTRIB> <VALUE>
            osCmd = "lio_node --settpgattr=%s %d cache_dynamic_acls 0" % (targetName, tpgt)
            runExec(osCmd)
            #     --enabletpg=TARGET_IQN TPGT
            osCmd = "lio_node --enabletpg %s %d" % (targetName, tpgt)
            runExec(osCmd)
            print "sendTarget success"
            VSLogger.info("sendTarget success")
        except Exception, e:
            errMsg = traceback.format_exc()
            rollback.rollback()
            VSLogger.error(errMsg)
            raise VSException(-1, getExceptionErrorMessage(e))
Пример #2
0
def rollbackLioAddLun(param):
    """lio中增加lun的回滚函数
    @param param 存储了lio中增加lun的多个参数的一个列表
    """

    osCmd = "lio_node --deliqn=%s" % param[0]
    try:
        runExec(osCmd)
    except Exception, e:
        VSLogger.error("rollback failed: run %s failed : %s " % (osCmd, repr(e)))
Пример #3
0
def rollbackTcmCreate(param):
    """定义创建lio中tcm后端存储的回滚操作
    @param param 存储了创建lio中tcm的多个参数的一个列表
    """

    lioCfgDir = "/sys/kernel/config/target/core/iblock_0/%s_%s" % (param[0], param[1])
    if os.path.exists(lioCfgDir):
        try:
            osCmd = "tcm_node --freedev iblock_0/%s_%s" % (param[0], param[1])
            runExec(osCmd)
        except Exception, e:
            VSLogger.error("rollback tcm_node %s_%s failed: %s " % (param[0], param[1], str(e)))
Пример #4
0
    def detachLV(self, lvName):
        """服务接口,卸载逻辑卷
        
        @param lvName 逻辑卷名称
        """

        VSLogger.debug("Detach LV(%s) begin..." % (lvName))
        try:
            self.__purgeAttachLV(lvName)
        except Exception, e:
            errMsg = traceback.format_exc()
            VSLogger.error(errMsg)
            raise VSException(-1, getExceptionErrorMessage(e))