1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
This commit is contained in:
abakanovskii 2024-08-12 14:11:09 +03:00
parent faf5da610e
commit ca4478f7bd
2 changed files with 39 additions and 17 deletions

View file

@ -1,2 +1,2 @@
minor_changes: minor_changes:
- open_iscsi - Allow login to a portal with multiple targets without specifying any of them (https://github.com/ansible-collections/community.general/pull/8719) - open_iscsi - allow login to a portal with multiple targets without specifying any of them (https://github.com/ansible-collections/community.general/pull/8719).

View file

@ -239,14 +239,14 @@ def target_login(module, target, check_rc, portal=None, port=None):
('node.session.auth.password', node_pass)] ('node.session.auth.password', node_pass)]
for (name, value) in params: for (name, value) in params:
cmd = [iscsiadm_cmd, '--mode', 'node', '--targetname', target, '--op=update', '--name', name, '--value', value] cmd = [iscsiadm_cmd, '--mode', 'node', '--targetname', target, '--op=update', '--name', name, '--value', value]
rc, out, err = module.run_command(cmd, check_rc=check_rc) module.run_command(cmd, check_rc=check_rc)
if node_user_in: if node_user_in:
params = [('node.session.auth.username_in', node_user_in), params = [('node.session.auth.username_in', node_user_in),
('node.session.auth.password_in', node_pass_in)] ('node.session.auth.password_in', node_pass_in)]
for (name, value) in params: for (name, value) in params:
cmd = '%s --mode node --targetname %s --op=update --name %s --value %s' % (iscsiadm_cmd, target, name, value) cmd = '%s --mode node --targetname %s --op=update --name %s --value %s' % (iscsiadm_cmd, target, name, value)
rc, out, err = module.run_command(cmd, check_rc=check_rc) module.run_command(cmd, check_rc=check_rc)
cmd = [iscsiadm_cmd, '--mode', 'node', '--targetname', target, '--login'] cmd = [iscsiadm_cmd, '--mode', 'node', '--targetname', target, '--login']
if portal is not None and port is not None: if portal is not None and port is not None:
@ -339,7 +339,11 @@ def main():
), ),
required_together=[['node_user', 'node_pass'], ['node_user_in', 'node_pass_in']], required_together=[['node_user', 'node_pass'], ['node_user_in', 'node_pass_in']],
required_if=[('discover', True, ['portal'])], required_if=[
('discover', True, ['portal']),
('auto_node_startup', True, ['target']),
('auto_portal_startup', True, ['target'])
],
supports_check_mode=True, supports_check_mode=True,
) )
@ -400,22 +404,22 @@ def main():
if show_nodes: if show_nodes:
result['nodes'] = nodes result['nodes'] = nodes
if login is not None: if login is not None and not check_rc:
result['devicenodes'] = [] result['devicenodes'] = []
for target in nodes: for index_target in nodes:
loggedon = target_loggedon(module, target, portal, port) loggedon = target_loggedon(module, index_target, portal, port)
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(target) result['devicenodes'] += target_device_node(index_target)
elif not check: elif not check:
if login: if login:
login_result = target_login(module, target, check_rc, portal, port) login_result = target_login(module, index_target, check_rc, portal, port)
# give udev some time # give udev some time
time.sleep(1) time.sleep(1)
result['devicenodes'] += target_device_node(target) result['devicenodes'] += target_device_node(index_target)
else: else:
target_logout(module, target) target_logout(module, index_target)
# Check if there are multiple targets on a single portal and # Check if there are multiple targets on a single portal and
# do not mark the task changed if host could not login to one of them # do not mark the task changed if host could not login to one of them
if len(nodes) > 1 and login_result == 24: if len(nodes) > 1 and login_result == 24:
@ -428,7 +432,27 @@ def main():
result['changed'] |= True result['changed'] |= True
result['connection_changed'] = True result['connection_changed'] = True
if automatic is not None: if login is not None and check_rc:
loggedon = target_loggedon(module, target, portal, port)
if (login and loggedon) or (not login and not loggedon):
result['changed'] |= False
if login:
result['devicenodes'] = target_device_node(target)
elif not check:
if login:
target_login(module, target, portal, port)
# give udev some time
time.sleep(1)
result['devicenodes'] = target_device_node(target)
else:
target_logout(module, target)
result['changed'] |= True
result['connection_changed'] = True
else:
result['changed'] |= True
result['connection_changed'] = True
if automatic is not None and check_rc:
isauto = target_isauto(module, target) isauto = target_isauto(module, target)
if (automatic and isauto) or (not automatic and not isauto): if (automatic and isauto) or (not automatic and not isauto):
result['changed'] |= False result['changed'] |= False
@ -444,7 +468,7 @@ def main():
result['changed'] |= True result['changed'] |= True
result['automatic_changed'] = True result['automatic_changed'] = True
if automatic_portal is not None: if automatic_portal is not None and check_rc:
isauto = target_isauto(module, target, portal, port) isauto = target_isauto(module, target, portal, port)
if (automatic_portal and isauto) or (not automatic_portal and not isauto): if (automatic_portal and isauto) or (not automatic_portal and not isauto):
result['changed'] |= False result['changed'] |= False
@ -461,10 +485,8 @@ def main():
result['automatic_portal_changed'] = True result['automatic_portal_changed'] = True
if rescan is not False: if rescan is not False:
result['sessions'] = [] result['changed'] = True
for target in nodes: result['sessions'] = iscsi_rescan(module, target)
result['changed'] = True
result['sessions'] += iscsi_rescan(module, target)
module.exit_json(**result) module.exit_json(**result)