forked from rubrikinc/rubrik-modules-for-ansible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collection_dev.py
79 lines (59 loc) · 3.06 KB
/
collection_dev.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# This file will update the module_utils import path in all modules to support Ansible Collections and then create the collection .tar
import fileinput
import os
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-a', '--action', choices=['build', 'update_path'], required=True, help='Specify which action (build or test) you wish to use.')
parser.add_argument('-p', '--platform', choices=['vscode', 'circleci'], default="vscode", required=False, help='The platform you wish to run the script against.')
arguments = parser.parse_args()
collections_path = "from ansible_collections.rubrikinc.cdm.plugins.module_utils.rubrik_cdm import credentials, load_provider_variables, rubrik_argument_spec"
standard_path = "from ansible.module_utils.rubrik_cdm import credentials, load_provider_variables, rubrik_argument_spec"
if arguments.action == 'build':
# Create a list of all modules for processing
modules = []
for dir_path, _, file_name in os.walk('./rubrikinc/cdm/plugins/modules'):
for file in file_name:
modules.append(os.path.join(dir_path, file))
# Update import path to support Ansible Collections
for m in modules:
with fileinput.FileInput(m, inplace=True) as file:
for line in file:
print(line.replace(standard_path, collections_path), end='')
# Switch to the Collection directory and build the collection
os.chdir('./rubrikinc/cdm')
os.system('mv ./docs/create_documentation_block.py /tmp')
os.system('mv ./docs/README.md /tmp')
os.system('mv ./docs/SUMMARY.md /tmp')
os.system('mv ./docs/template.md /tmp')
os.system('mv ./docs/rubrik_module_template.py /tmp')
os.system('ansible-galaxy collection build')
os.system('mv /tmp/create_documentation_block.py ./docs')
os.system('mv /tmp/README.md ./docs')
os.system('mv /tmp/SUMMARY.md ./docs')
os.system('mv /tmp/template.md ./docs')
os.system('mv /tmp/rubrik_module_template.py ./docs')
# Switch back to the root dir
os.chdir('../..')
# Revert changes to the import paths
for m in modules:
with fileinput.FileInput(m, inplace=True) as file:
for line in file:
print(line.replace(collections_path, standard_path), end='')
else:
# Create a list of all modules for processing
modules = []
if arguments.platform == 'circleci':
search_directory = os.walk("/home/circleci/.ansible/collections/ansible_collections/rubrikinc/cdm")
else:
search_directory = os.walk("/root/.ansible/collections/ansible_collections/rubrikinc/cdm/plugins/modules")
print("VS Code")
for dir_path, _, file_name in search_directory:
for file in file_name:
if '__pycache__' not in dir_path:
modules.append(os.path.join(dir_path, file))
# Update import path to support Ansible Collections
for m in modules:
print(m)
with fileinput.FileInput(m, inplace=True) as file:
for line in file:
print(line.replace(standard_path, collections_path), end='')