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))
def cleanTarget(self, lvName, targetName, tpgt): # 先后顺序很重要, self.purgeIqn(targetName, tpgt) VSLogger.info("purgeIqn success") print "purgeIqn success" self.purgeTcm(lvName) VSLogger.debug("purgeTcm success") print "purgeTcm success" self.purgeIscsi(targetName) VSLogger.debug("purgeIscsi success") print "purgeIscsi success"
return targetInfo 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)) VSLogger.info("Successfully detach LV %s." % (lvName)) def cleanTarget(self, lvName, targetName, tpgt): # 先后顺序很重要, self.purgeIqn(targetName, tpgt) VSLogger.info("purgeIqn success") print "purgeIqn success" self.purgeTcm(lvName) VSLogger.debug("purgeTcm success") print "purgeTcm success" self.purgeIscsi(targetName) VSLogger.debug("purgeIscsi success") print "purgeIscsi success" def startTarget(lvName, tpgt, lun, suffix):