def rollbackIscsiLogin(param): '''回滚iscsi login的操作,即执行logout的操作 @param param 存储了操作过程中多个参数的一个列表 ''' try: osCmd = "iscsiadm -m node -T %s -p %s:%d --logout" % (param[0], param[1], param[2]) runExec(osCmd) except Exception, e: iSCSILogger.error("rollback failed: %s " % str(e))
def rollbackLioAddLun(param): '''lio中增加lun的回滚函数 @param param 存储了lio中增加lun的多个参数的一个列表 ''' osCmd = "lio_node --deliqn=%s" % param[0] try: runExec(osCmd) except Exception, e: iSCSILogger.error("rollback failed: run %s failed : %s " % (osCmd, repr(e)))
def rollbackIscsiLogin(param): '''回滚iscsi login的操作,即执行logout的操作 @param param 存储了操作过程中多个参数的一个列表 ''' try: osCmd = "iscsiadm -m node -T %s -p %s:%d --logout" % ( param[0], param[1], param[2]) runExec(osCmd) except Exception, e: iSCSILogger.error("rollback failed: %s " % str(e))
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: iSCSILogger.error("rollback tcm_node %s_%s failed: %s " % (param[0], param[1], str(e)))
def sendTarget(self, lvName, initiatorName): '''输出Target @param lvName 输出target @param initiatorName 允许访问此逻辑卷的iscsi initor的名称 @return 返回一个TargetInfo的结构体 ''' iSCSILogger.info("Call interface sendTarget(%s, %s)..." % (lvName, initiatorName)) try: rollback = ActionRollback() # 执行 tcm_node --block iblock_0/%s_%s /dev/%s" % (param[0], param[1], param[1]) actionTcmCreate(rollback, ('test', lvName)) # 定义iqn前缀 iqn = "test" # 组装targetName iqn+ 倒装域名 + lvName #targetName = "%s:%d:%s" % (iqn, time.time() * 1000, lvName) targetName = "%s:%d:%s" % (iqn, 123456, lvName) 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, 'test', lvName)) osCmd = "lio_node --addnp %s 1 %s:%d" % (targetName, "0.0.0.0", 3260) runExec(osCmd) osCmd = "lio_node --enableauth %s 1" % (targetName) runExec(osCmd) osCmd = "lio_node --addlunacl %s 1 %s 0 0" % (targetName, initiatorName) runExec(osCmd) osCmd = "lio_node --setchapauth %s 1 %s %s %s" % ( targetName, initiatorName, targetInfo.chapUser, targetInfo.chapPass) runExec(osCmd) osCmd = "lio_node --settpgattr=%s 1 cache_dynamic_acls 0" % ( targetName) runExec(osCmd) osCmd = "lio_node --enabletpg %s 1" % (targetName) runExec(osCmd) print "sendTarget success" iSCSILogger.info("sendTarget success") except Exception, e: errMsg = traceback.format_exc() rollback.rollback() iSCSILogger.error(errMsg) raise Exception
def sendTarget(self, lvName, initiatorName): '''输出Target @param lvName 输出target @param initiatorName 允许访问此逻辑卷的iscsi initor的名称 @return 返回一个TargetInfo的结构体 ''' iSCSILogger.info("Call interface sendTarget(%s, %s)..." % (lvName, initiatorName)) try: rollback = ActionRollback() # 执行 tcm_node --block iblock_0/%s_%s /dev/%s" % (param[0], param[1], param[1]) actionTcmCreate(rollback, ('test', lvName)) # 定义iqn前缀 iqn ="test" # 组装targetName iqn+ 倒装域名 + lvName #targetName = "%s:%d:%s" % (iqn, time.time() * 1000, lvName) targetName = "%s:%d:%s" % (iqn, 123456, lvName) 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, 'test', lvName)) osCmd = "lio_node --addnp %s 1 %s:%d" % (targetName, "0.0.0.0",3260) runExec(osCmd) osCmd = "lio_node --enableauth %s 1" % (targetName) runExec(osCmd) osCmd = "lio_node --addlunacl %s 1 %s 0 0" % (targetName, initiatorName) runExec(osCmd) osCmd = "lio_node --setchapauth %s 1 %s %s %s" % (targetName, initiatorName, targetInfo.chapUser, targetInfo.chapPass) runExec(osCmd) osCmd = "lio_node --settpgattr=%s 1 cache_dynamic_acls 0" % (targetName) runExec(osCmd) osCmd = "lio_node --enabletpg %s 1" % (targetName) runExec(osCmd) print "sendTarget success" iSCSILogger.info("sendTarget success") except Exception, e: errMsg = traceback.format_exc() rollback.rollback() iSCSILogger.error(errMsg) raise Exception