Skip to content

Commit 2ff9535

Browse files
authored
Merge pull request #31 from marcelmamula/planid
maintenance_planner modules: Add option to use Display ID instead of name
2 parents 19096c7 + 7578647 commit 2ff9535

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

plugins/module_utils/sap_launchpad_maintenance_planner_runner.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,26 @@ def _get_transaction_name(trans_id):
281281
return transaction['trans_name']
282282

283283

284+
def get_transaction_id(name):
285+
"""
286+
Search transaction ID using transaction Name or Display ID.
287+
288+
Args:
289+
name: transaction name or display id.
290+
"""
291+
transactions = get_transactions()
292+
transaction_name = [t for t in transactions if t['trans_name'] == name]
293+
if not transaction_name:
294+
# Repeat search using Display ID
295+
transaction_display_id = [t for t in transactions if t['trans_display_id'] == name]
296+
if not transaction_display_id:
297+
raise KeyError(f'Name or Display ID {name} not found in transactionsX')
298+
else:
299+
return transaction_display_id[0]['trans_id']
300+
else:
301+
return transaction_name[0]['trans_id']
302+
303+
284304
def _get_transaction(key, value):
285305
transactions = get_transactions()
286306
trans = [t for t in transactions if t[key] == value]

plugins/modules/maintenance_planner_files.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
type: str
2828
transaction_name:
2929
description:
30-
- Transaction name of your Maintenance Planner session.
30+
- Transaction Name or Transaction Display ID from Maintenance Planner.
3131
required: true
3232
type: str
3333
author:
34-
- Lab for SAP Solutions
34+
- SAP LinuxLab
3535
3636
'''
3737

@@ -115,7 +115,7 @@ def run_module():
115115
auth_userapps()
116116

117117
# EXEC: Get MP stack transaction id from transaction name
118-
transaction_id = get_transaction_id_by_name(transaction_name)
118+
transaction_id = get_transaction_id(transaction_name)
119119

120120
# EXEC: Get a json list of download_links and download_filenames
121121
download_basket_details = get_transaction_filename_url(transaction_id)

plugins/modules/maintenance_planner_stack_xml_download.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@
2727
type: str
2828
transaction_name:
2929
description:
30-
- Transaction name of your Maintenance Planner session.
30+
- Transaction Name or Transaction Display ID from Maintenance Planner.
3131
required: true
3232
type: str
33-
dest:
33+
download_path:
3434
description:
35-
- Destination folder.
35+
- Destination folder path.
3636
required: true
3737
type: str
3838
author:
39-
- Lab for SAP Solutions
39+
- SAP LinuxLab
4040
4141
'''
4242

@@ -46,7 +46,7 @@
4646
suser_id: 'SXXXXXXXX'
4747
suser_password: 'password'
4848
transaction_name: 'MP_NEW_INST_20211015_044854'
49-
dest: "/tmp/"
49+
download_path: "/tmp/"
5050
register: sap_mp_register
5151
- name: Display the list of download links and filenames
5252
debug:
@@ -79,7 +79,7 @@ def run_module():
7979
suser_id=dict(type='str', required=True),
8080
suser_password=dict(type='str', required=True, no_log=True),
8181
transaction_name=dict(type='str', required=True),
82-
dest=dict(type='str', required=True)
82+
download_path=dict(type='str', required=True)
8383
)
8484

8585
# Define result dictionary objects to be passed back to Ansible
@@ -102,7 +102,7 @@ def run_module():
102102
username = module.params.get('suser_id')
103103
password = module.params.get('suser_password')
104104
transaction_name = module.params.get('transaction_name')
105-
dest = module.params.get('dest')
105+
download_path = module.params.get('download_path')
106106

107107
# Main run
108108

@@ -115,10 +115,10 @@ def run_module():
115115
auth_userapps()
116116

117117
# EXEC: Get MP stack transaction id from transaction name
118-
transaction_id = get_transaction_id_by_name(transaction_name)
118+
transaction_id = get_transaction_id(transaction_name)
119119

120120
# EXEC: Download the MP Stack XML file
121-
get_transaction_stack_xml(transaction_id, dest)
121+
get_transaction_stack_xml(transaction_id, download_path)
122122

123123
# Process return dictionary for Ansible
124124
result['changed'] = True

0 commit comments

Comments
 (0)