Skip to content

Commit

Permalink
check_mode support
Browse files Browse the repository at this point in the history
  • Loading branch information
tvarohohlavy committed Dec 10, 2024
1 parent 59cf5e6 commit 9a83f68
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions plugins/modules/cml_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ def run_module():

if cml.params['state'] in ['present', 'started']:
if lab is None:
if module.check_mode:
module.exit_json(changed=True)
# create the lab
if cml.params['topology']:
lab = cml.client.import_lab(cml.params['topology'], title=cml.params['lab'])
Expand All @@ -154,11 +156,15 @@ def run_module():
lab.title = cml.params['lab']
cml.result['changed'] = True
elif lab.state() == "STOPPED" and cml.params['state'] == 'started':
if module.check_mode:
module.exit_json(changed=True)
# start existing stopped lab
lab.start(wait=cml.params['wait'])
cml.result['changed'] = True
elif cml.params['state'] == 'absent':
if lab:
if module.check_mode:
module.exit_json(changed=True)
# remove existing lab
cml.result['changed'] = True
if lab.state() == "STARTED":
Expand All @@ -170,12 +176,16 @@ def run_module():
elif cml.params['state'] == 'stopped':
if lab:
if lab.state() == "STARTED":
if module.check_mode:
module.exit_json(changed=True)
# stop existing running lab
cml.result['changed'] = True
lab.stop(wait=True)
elif cml.params['state'] == 'wiped':
if lab:
if lab.state() == "STOPPED":
if module.check_mode:
module.exit_json(changed=True)
# wipe existing stopped lab
cml.result['changed'] = True
lab.wipe(wait=True)
Expand Down
8 changes: 8 additions & 0 deletions plugins/modules/cml_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,16 @@ def run_module():
node = cml.get_node_by_name(lab, cml.params['name'])
if cml.params['state'] == 'present':
if node is None:
if module.check_mode:
module.exit_json(changed=True)
node = lab.create_node(label=cml.params['name'], node_definition=cml.params['node_definition'])
cml.result['changed'] = True
elif cml.params['state'] == 'started':
if node is None:
cml.fail_json("Node must be created before it is started")
if node.state not in ['STARTED', 'BOOTED']:
if module.check_mode:
module.exit_json(changed=True)
if node.state == 'DEFINED_ON_CORE' and cml.params['config']:
node.config = cml.params['config']
if cml.params['image_definition']:
Expand All @@ -171,6 +175,8 @@ def run_module():
if node is None:
cml.fail_json("Node must be created before it is stopped")
if node.state not in ['STOPPED', 'DEFINED_ON_CORE']:
if module.check_mode:
module.exit_json(changed=True)
if cml.params['wait'] is False:
lab.wait_for_covergence = False
node.stop()
Expand All @@ -179,6 +185,8 @@ def run_module():
if node is None:
cml.fail_json("Node must be created before it is wiped")
if node.state not in ['DEFINED_ON_CORE']:
if module.check_mode:
module.exit_json(changed=True)
node.wipe(wait=cml.params['wait'])
cml.result['changed'] = True
cml.exit_json(**cml.result)
Expand Down

0 comments on commit 9a83f68

Please sign in to comment.