Coverage for sm/core/libiscsi : 83%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
"""Temporary module to mock libiscsi"""
"""Executes via util.doexec the command specified. If the return code is non-zero, raises an ISCSIError with the given message"""
# _lock = None # if os.path.basename(cmd[0]) == 'iscsiadm': # _lock = lock.Lock(LOCK_TYPE_RUNNING, 'iscsiadm') # _lock.acquire()
# if _lock <> None and _lock.held(): # _lock.release() else:
interface_array=("default",)): """Run iscsiadm in discovery mode to obtain a list of the TargetIQNs available on the specified target and port. Returns a list of triples - the portal (ip:port), the tpgt (target portal group tag) and the target name"""
# Save configuration of root LUN nodes and restore after discovery # otherwise when we do a discovery on the same filer as is hosting # our root disk we'll reset the config of the root LUNs # save_rootdisk_nodes()
targetstring = "[%s]:%s" % (target, str(port)) else: "-n", "discovery.sendtargets.auth.username", "-v", chapuser, "-n", "discovery.sendtargets.auth.password", "-v", chappass] "username/password (if applicable)" else: except Exception as exc: # restore_rootdisk_nodes() raise f_exceptions.XenError('ISCSILogin', message=exc.message) # else: # restore_rootdisk_nodes()
"""Sets the username and password on the session identified by the portal/targetIQN combination"""
failuremessage = "Failed to set CHAP settings" cmd = ["iscsiadm", "-m", "node", "-p", portal, "-T", targetIQN, "--op", "update", "-n", "node.session.auth.authmethod","-v", "CHAP"] (stdout,stderr) = exn_on_failure(cmd, failuremessage)
cmd = ["iscsiadm", "-m", "node", "-p", portal, "-T", targetIQN, "--op", "update", "-n", "node.session.auth.username","-v", username] (stdout,stderr) = exn_on_failure(cmd, failuremessage)
cmd = ["iscsiadm", "-m", "node", "-p", portal, "-T", targetIQN, "--op", "update", "-n", "node.session.auth.password","-v", password] (stdout,stderr) = exn_on_failure(cmd, failuremessage)
"""doc placeholder""" # Extract IQN from iscsiadm -m session # Ex: tcp: [17] 10.220.98.9:3260,1 iqn.2009-01.xenrt.test:iscsi4181a93e siqn = tgt_string.split(",")[1].split()[1] return siqn == tgt_iqn
"""helper function - parses the output of iscsiadm for discovery and get_node_records""" match_target_iqn(target_iqn, x)]
# We need to filter duplicates orignating from doing the discovery using # multiple interfaces
"""This is a slightly revised version of iscsilib.login in SM.
We are trying to stick as close as possible to the original one but fixing or improving whatever can be improved, in order to later fix it to the original one and start using that one both for the transport code and the old SM code.
For example, 'uuid' is a new addition in order to be able to automatically refcount in here, instead of relying on the caller to do that. """
set_chap_settings(portal, target, username, password)
# Increment portal/target ref count
# Increment legacy refcounter except Exception as exc: util.SMlog("Failed: {}".format(" ".join(cmd)), ident="Transport") # Rollback refcount if needed if uuid: # This should be in its own try/block and be chained # with main exception below util._decr_iscsiSR_refcount(portal_target_ref, uuid) raise f_exceptions.XenError('ISCSILogin', message=exc.message)
# Rescan if requested and more than one refcount of either form format(target))
"""Modified version of iscsilib.py:logout to handle refcounting
Given the nature of this refcounting, it is not possible to specifically logout from one ip/iqn pair without breaking the refcounting. For this reason, this version does not accept a specific ip and the parameter 'all'. """ format(target, uuid), ident="Transport")
# still logged in
# Decrement the legacy refcount format(target, uuid), ident="Transport") except Exception as exc: raise f_exceptions.XenError('ISCSILogout', message=exc.message)
""" Rescan the given iscsi portal and target """
# Get all configured iscsiadm interfaces "Failure occured querying iscsi daemon") # Get the interface (first column) from a line such as default # tcp,<empty>,<empty>,<empty>,<empty> # ignore interfaces which aren't marked as starting with # c_. # Ignore exception from exn on failure, still return the default # interface # In case there are no configured interfaces, still add the default # interface |