Skip to content

Commit

Permalink
Merge 0fd0bde into 45c4009
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSmithCtx committed May 21, 2020
2 parents 45c4009 + 0fd0bde commit 177ded9
Show file tree
Hide file tree
Showing 3 changed files with 297 additions and 83 deletions.
177 changes: 94 additions & 83 deletions drivers/mpathcount.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import glob
import json

supported = ['iscsi','lvmoiscsi','rawhba','lvmohba', 'ocfsohba', 'ocfsoiscsi', 'netapp','lvmofcoe', 'gfs2']
supported = ['iscsi','lvmoiscsi','rawhba','lvmohba', 'ocfsohba', 'ocfsoiscsi', 'netapp', 'lvmofcoe', 'gfs2']

LOCK_TYPE_HOST = "host"
LOCK_NS1 = "mpathcount1"
Expand All @@ -34,14 +34,9 @@
mpp_path_update = False
match_bySCSIid = False
mpath_enabled = True
SCSIid = 'NOTSUPPLIED'
mpp_entry = 'NOTSUPPLIED'

if len(sys.argv) == 3:
match_bySCSIid = True
SCSIid = sys.argv[1]
mpp_path_update = True
mpp_entry = sys.argv[2]

cached_DM_maj = None
def get_dm_major():
global cached_DM_maj
if not cached_DM_maj:
Expand Down Expand Up @@ -162,31 +157,8 @@ def get_SCSIidlist(devconfig, sm_config):
SCSIidlist.append(re.sub("^scsi-","",key))
return SCSIidlist

try:
session = util.get_localAPI_session()
except:
print "Unable to open local XAPI session"
sys.exit(-1)

localhost = session.xenapi.host.get_by_uuid(get_localhost_uuid())
# Check whether multipathing is enabled (either for root dev or SRs)
try:
if get_root_dev_major() != get_dm_major():
hconf = session.xenapi.host.get_other_config(localhost)
assert(hconf['multipathing'] == 'true')
mpath_enabled = True
except:
mpath_enabled = False

# Check root disk if multipathed
try:
def check_root_disk(config, maps, remove, add):
if get_root_dev_major() == get_dm_major():
def _remove(key):
session.xenapi.host.remove_from_other_config(localhost,key)
def _add(key, val):
session.xenapi.host.add_to_other_config(localhost,key,val)
config = session.xenapi.host.get_other_config(localhost)
maps = mpath_cli.list_maps()
# Ensure output headers are not in the list
if 'name' in maps:
maps.remove('name')
Expand All @@ -195,57 +167,96 @@ def _add(key, val):
i = maps[0]
if (not match_bySCSIid) or i == SCSIid:
util.SMlog("Matched SCSIid %s, updating " \
" Host.other-config:mpath-boot " % i)
" Host.other-config:mpath-boot " % i)
key="mpath-boot"
if not config.has_key(key):
update_config(key, i, "", _remove, _add)
update_config(key, i, "", remove, add)
else:
update_config(key, i, config[key], remove, add)

def check_devconfig(devconfig, sm_config, config, remove, add):
SCSIidlist = get_SCSIidlist(devconfig, sm_config)
if not len(SCSIidlist):
return
for i in SCSIidlist:
if match_bySCSIid and i != SCSIid:
continue
util.SMlog("Matched SCSIid, updating %s" % i)
key = "mpath-" + i
if not mpath_enabled:
remove(key)
remove('multipathed')
elif mpp_path_update:
util.SMlog("Matched SCSIid, updating entry %s" % str(mpp_entry))
update_config(key, i, mpp_entry, remove, add, mpp_path_update)
else:
if not config.has_key(key):
update_config(key, i, "", remove, add)
else:
update_config(key, i, config[key], _remove, _add)
except:
util.SMlog("MPATH: Failure updating Host.other-config:mpath-boot db")
mpc_exit(session, -1)

try:
pbds = session.xenapi.PBD.get_all_records_where("field \"host\" = \"%s\"" % localhost)
except:
mpc_exit(session,-1)

try:
for pbd in pbds:
def remove(key):
session.xenapi.PBD.remove_from_other_config(pbd,key)
def add(key, val):
session.xenapi.PBD.add_to_other_config(pbd,key,val)
record = pbds[pbd]
config = record['other_config']
SR = record['SR']
srtype = session.xenapi.SR.get_type(SR)
if srtype in supported:
devconfig = record["device_config"]
sm_config = session.xenapi.SR.get_sm_config(SR)
SCSIidlist = get_SCSIidlist(devconfig, sm_config)
if not len(SCSIidlist):
continue
for i in SCSIidlist:
if match_bySCSIid and i != SCSIid:
continue
util.SMlog("Matched SCSIid, updating %s" % i)
key = "mpath-" + i
if not mpath_enabled:
remove(key)
remove('multipathed')
elif mpp_path_update:
util.SMlog("Matched SCSIid, updating entry %s" % str(mpp_entry))
update_config(key, i, mpp_entry, remove, add, mpp_path_update)
else:
if not config.has_key(key):
update_config(key, i, "", remove, add)
else:
update_config(key, i, config[key], remove, add)
except:
util.SMlog("MPATH: Failure updating db. %s" % sys.exc_info())
mpc_exit(session, -1)

util.SMlog("MPATH: Update done")

mpc_exit(session,0)
update_config(key, i, config[key], remove, add)

if __name__ == '__main__':
if len(sys.argv) == 3:
match_bySCSIid = True
SCSIid = sys.argv[1]
mpp_path_update = True
mpp_entry = sys.argv[2]

cached_DM_maj = None

try:
session = util.get_localAPI_session()
except:
print "Unable to open local XAPI session"
sys.exit(-1)

localhost = session.xenapi.host.get_by_uuid(get_localhost_uuid())
# Check whether multipathing is enabled (either for root dev or SRs)
try:
if get_root_dev_major() != get_dm_major():
hconf = session.xenapi.host.get_other_config(localhost)
assert(hconf['multipathing'] == 'true')
mpath_enabled = True
except:
mpath_enabled = False

# Check root disk if multipathed
try:
def _remove(key):
session.xenapi.host.remove_from_other_config(localhost,key)
def _add(key, val):
session.xenapi.host.add_to_other_config(localhost,key,val)
config = session.xenapi.host.get_other_config(localhost)
maps = mpath_cli.list_maps()
check_root_disk(config, maps, _add, _remove)

except:
util.SMlog("MPATH: Failure updating Host.other-config:mpath-boot db")
mpc_exit(session, -1)

try:
pbds = session.xenapi.PBD.get_all_records_where("field \"host\" = \"%s\"" % localhost)
except:
mpc_exit(session,-1)

try:
for pbd in pbds:
def remove(key):
session.xenapi.PBD.remove_from_other_config(pbd,key)
def add(key, val):
session.xenapi.PBD.add_to_other_config(pbd,key,val)
record = pbds[pbd]
config = record['other_config']
SR = record['SR']
srtype = session.xenapi.SR.get_type(SR)
if srtype in supported:
devconfig = record["device_config"]
sm_config = session.xenapi.SR.get_sm_config(SR)
check_devconfig(devconfig, sm_config, config, remove, add)
except:
util.SMlog("MPATH: Failure updating db. %s" % sys.exc_info())
mpc_exit(session, -1)

util.SMlog("MPATH: Update done")

mpc_exit(session,0)
Empty file.

0 comments on commit 177ded9

Please sign in to comment.