|
|
@ -108,6 +108,7 @@ import time
|
|
|
|
|
|
|
|
|
|
|
|
ISCSIADM = 'iscsiadm'
|
|
|
|
ISCSIADM = 'iscsiadm'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def compare_nodelists(l1, l2):
|
|
|
|
def compare_nodelists(l1, l2):
|
|
|
|
|
|
|
|
|
|
|
|
l1.sort()
|
|
|
|
l1.sort()
|
|
|
@ -159,7 +160,7 @@ def target_loggedon(module, target):
|
|
|
|
|
|
|
|
|
|
|
|
cmd = '%s --mode session' % iscsiadm_cmd
|
|
|
|
cmd = '%s --mode session' % iscsiadm_cmd
|
|
|
|
(rc, out, err) = module.run_command(cmd)
|
|
|
|
(rc, out, err) = module.run_command(cmd)
|
|
|
|
|
|
|
|
|
|
|
|
if rc == 0:
|
|
|
|
if rc == 0:
|
|
|
|
return target in out
|
|
|
|
return target in out
|
|
|
|
elif rc == 21:
|
|
|
|
elif rc == 21:
|
|
|
@ -186,7 +187,7 @@ def target_login(module, target):
|
|
|
|
|
|
|
|
|
|
|
|
cmd = '%s --mode node --targetname %s --login' % (iscsiadm_cmd, target)
|
|
|
|
cmd = '%s --mode node --targetname %s --login' % (iscsiadm_cmd, target)
|
|
|
|
(rc, out, err) = module.run_command(cmd)
|
|
|
|
(rc, out, err) = module.run_command(cmd)
|
|
|
|
|
|
|
|
|
|
|
|
if rc > 0:
|
|
|
|
if rc > 0:
|
|
|
|
module.fail_json(cmd=cmd, rc=rc, msg=err)
|
|
|
|
module.fail_json(cmd=cmd, rc=rc, msg=err)
|
|
|
|
|
|
|
|
|
|
|
@ -195,7 +196,7 @@ def target_logout(module, target):
|
|
|
|
|
|
|
|
|
|
|
|
cmd = '%s --mode node --targetname %s --logout' % (iscsiadm_cmd, target)
|
|
|
|
cmd = '%s --mode node --targetname %s --logout' % (iscsiadm_cmd, target)
|
|
|
|
(rc, out, err) = module.run_command(cmd)
|
|
|
|
(rc, out, err) = module.run_command(cmd)
|
|
|
|
|
|
|
|
|
|
|
|
if rc > 0:
|
|
|
|
if rc > 0:
|
|
|
|
module.fail_json(cmd=cmd, rc=rc, msg=err)
|
|
|
|
module.fail_json(cmd=cmd, rc=rc, msg=err)
|
|
|
|
|
|
|
|
|
|
|
@ -206,25 +207,22 @@ def target_device_node(module, target):
|
|
|
|
# a given target...
|
|
|
|
# a given target...
|
|
|
|
|
|
|
|
|
|
|
|
devices = glob.glob('/dev/disk/by-path/*%s*' % target)
|
|
|
|
devices = glob.glob('/dev/disk/by-path/*%s*' % target)
|
|
|
|
if len(devices) == 0:
|
|
|
|
devdisks = []
|
|
|
|
return None
|
|
|
|
for dev in devices:
|
|
|
|
else:
|
|
|
|
# exclude partitions
|
|
|
|
devdisks = []
|
|
|
|
if "-part" not in dev:
|
|
|
|
for dev in devices:
|
|
|
|
devdisk = os.path.realpath(dev)
|
|
|
|
# exclude partitions
|
|
|
|
# only add once (multi-path?)
|
|
|
|
if "-part" not in dev:
|
|
|
|
if devdisk not in devdisks:
|
|
|
|
devdisk = os.path.realpath(dev)
|
|
|
|
devdisks.append(devdisk)
|
|
|
|
# only add once (multi-path?)
|
|
|
|
return devdisks
|
|
|
|
if devdisk not in devdisks:
|
|
|
|
|
|
|
|
devdisks.append(devdisk)
|
|
|
|
|
|
|
|
return devdisks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def target_isauto(module, target):
|
|
|
|
def target_isauto(module, target):
|
|
|
|
|
|
|
|
|
|
|
|
cmd = '%s --mode node --targetname %s' % (iscsiadm_cmd, target)
|
|
|
|
cmd = '%s --mode node --targetname %s' % (iscsiadm_cmd, target)
|
|
|
|
(rc, out, err) = module.run_command(cmd)
|
|
|
|
(rc, out, err) = module.run_command(cmd)
|
|
|
|
|
|
|
|
|
|
|
|
if rc == 0:
|
|
|
|
if rc == 0:
|
|
|
|
lines = out.splitlines()
|
|
|
|
lines = out.splitlines()
|
|
|
|
for line in lines:
|
|
|
|
for line in lines:
|
|
|
@ -239,7 +237,7 @@ def target_setauto(module, target):
|
|
|
|
|
|
|
|
|
|
|
|
cmd = '%s --mode node --targetname %s --op=update --name node.startup --value automatic' % (iscsiadm_cmd, target)
|
|
|
|
cmd = '%s --mode node --targetname %s --op=update --name node.startup --value automatic' % (iscsiadm_cmd, target)
|
|
|
|
(rc, out, err) = module.run_command(cmd)
|
|
|
|
(rc, out, err) = module.run_command(cmd)
|
|
|
|
|
|
|
|
|
|
|
|
if rc > 0:
|
|
|
|
if rc > 0:
|
|
|
|
module.fail_json(cmd=cmd, rc=rc, msg=err)
|
|
|
|
module.fail_json(cmd=cmd, rc=rc, msg=err)
|
|
|
|
|
|
|
|
|
|
|
@ -248,7 +246,7 @@ def target_setmanual(module, target):
|
|
|
|
|
|
|
|
|
|
|
|
cmd = '%s --mode node --targetname %s --op=update --name node.startup --value manual' % (iscsiadm_cmd, target)
|
|
|
|
cmd = '%s --mode node --targetname %s --op=update --name node.startup --value manual' % (iscsiadm_cmd, target)
|
|
|
|
(rc, out, err) = module.run_command(cmd)
|
|
|
|
(rc, out, err) = module.run_command(cmd)
|
|
|
|
|
|
|
|
|
|
|
|
if rc > 0:
|
|
|
|
if rc > 0:
|
|
|
|
module.fail_json(cmd=cmd, rc=rc, msg=err)
|
|
|
|
module.fail_json(cmd=cmd, rc=rc, msg=err)
|
|
|
|
|
|
|
|
|
|
|
@ -259,7 +257,7 @@ def main():
|
|
|
|
module = AnsibleModule(
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec = dict(
|
|
|
|
argument_spec = dict(
|
|
|
|
|
|
|
|
|
|
|
|
# target
|
|
|
|
# target
|
|
|
|
portal = dict(required=False, aliases=['ip']),
|
|
|
|
portal = dict(required=False, aliases=['ip']),
|
|
|
|
port = dict(required=False, default=3260),
|
|
|
|
port = dict(required=False, default=3260),
|
|
|
|
target = dict(required=False, aliases=['name', 'targetname']),
|
|
|
|
target = dict(required=False, aliases=['name', 'targetname']),
|
|
|
@ -272,14 +270,14 @@ def main():
|
|
|
|
auto_node_startup = dict(type='bool', aliases=['automatic']),
|
|
|
|
auto_node_startup = dict(type='bool', aliases=['automatic']),
|
|
|
|
discover = dict(type='bool', default=False),
|
|
|
|
discover = dict(type='bool', default=False),
|
|
|
|
show_nodes = dict(type='bool', default=False)
|
|
|
|
show_nodes = dict(type='bool', default=False)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
required_together=[['discover_user', 'discover_pass'],
|
|
|
|
required_together=[['discover_user', 'discover_pass'],
|
|
|
|
['node_user', 'node_pass']],
|
|
|
|
['node_user', 'node_pass']],
|
|
|
|
supports_check_mode=True
|
|
|
|
supports_check_mode=True
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
global iscsiadm_cmd
|
|
|
|
global iscsiadm_cmd
|
|
|
|
iscsiadm_cmd = module.get_bin_path('iscsiadm', required=True)
|
|
|
|
iscsiadm_cmd = module.get_bin_path('iscsiadm', required=True)
|
|
|
|
|
|
|
|
|
|
|
|
# parameters
|
|
|
|
# parameters
|
|
|
@ -295,7 +293,7 @@ def main():
|
|
|
|
|
|
|
|
|
|
|
|
cached = iscsi_get_cached_nodes(module, portal)
|
|
|
|
cached = iscsi_get_cached_nodes(module, portal)
|
|
|
|
|
|
|
|
|
|
|
|
# return json dict
|
|
|
|
# return json dict
|
|
|
|
result = {}
|
|
|
|
result = {}
|
|
|
|
result['changed'] = False
|
|
|
|
result['changed'] = False
|
|
|
|
|
|
|
|
|
|
|
@ -333,17 +331,17 @@ def main():
|
|
|
|
result['nodes'] = nodes
|
|
|
|
result['nodes'] = nodes
|
|
|
|
|
|
|
|
|
|
|
|
if login is not None:
|
|
|
|
if login is not None:
|
|
|
|
loggedon = target_loggedon(module,target)
|
|
|
|
loggedon = target_loggedon(module, target)
|
|
|
|
if (login and loggedon) or (not login and not loggedon):
|
|
|
|
if (login and loggedon) or (not login and not loggedon):
|
|
|
|
result['changed'] |= False
|
|
|
|
result['changed'] |= False
|
|
|
|
if login:
|
|
|
|
if login:
|
|
|
|
result['devicenodes'] = target_device_node(module,target)
|
|
|
|
result['devicenodes'] = target_device_node(module, target)
|
|
|
|
elif not check:
|
|
|
|
elif not check:
|
|
|
|
if login:
|
|
|
|
if login:
|
|
|
|
target_login(module, target)
|
|
|
|
target_login(module, target)
|
|
|
|
# give udev some time
|
|
|
|
# give udev some time
|
|
|
|
time.sleep(1)
|
|
|
|
time.sleep(1)
|
|
|
|
result['devicenodes'] = target_device_node(module,target)
|
|
|
|
result['devicenodes'] = target_device_node(module, target)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
target_logout(module, target)
|
|
|
|
target_logout(module, target)
|
|
|
|
result['changed'] |= True
|
|
|
|
result['changed'] |= True
|
|
|
@ -371,7 +369,6 @@ def main():
|
|
|
|
module.exit_json(**result)
|
|
|
|
module.exit_json(**result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# import module snippets
|
|
|
|
# import module snippets
|
|
|
|
from ansible.module_utils.basic import *
|
|
|
|
from ansible.module_utils.basic import *
|
|
|
|
|
|
|
|
|
|
|
|