Skip to content

Commit 6c070b4

Browse files
authored
Merge pull request #170 from IBM/dev
Dev => master : Refactoring and defect fixes for ansible modules
2 parents a794746 + 11c608a commit 6c070b4

22 files changed

+2934
-754
lines changed

roles/custom_module/inventory/hosts

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,28 @@
1-
[clsuter01]
2-
host-01
1+
[scale_cluster]
2+
node1.domain.com
3+
node2.domain.com
4+
node3.doamin.com
5+
node4.domain.com
6+
7+
[controller]
8+
node1.domain.com
9+
10+
[quorum_nodes]
11+
node1.domain.com
12+
node2.domain.com
13+
node3.doamin.com
14+
15+
[manager_nodes]
16+
node1.domain.com
17+
node2.domain.com
18+
19+
[test_remove_storage_nodes]
20+
node3.doamin.com filesystem="FS1" nsds="nsd3;nsd7"
21+
node4.domain.com filesystem="FS1" nsds="nsd4;nsd8"
22+
23+
[test_remove_nodes]
24+
node3.doamin.com
25+
node4.domain.com
26+
27+
[test_add_nodes]
28+
node3.doamin.com designation=client

roles/custom_module/library/ibm_ss_cluster.py

+72-55
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
3-
4-
# author: IBM Corporation
5-
# description: Highly-customizable Ansible module
6-
# for installing and configuring IBM Spectrum Scale (GPFS)
7-
# company: IBM
8-
# license: Apache-2.0
3+
#
4+
# Copyright 2020 IBM Corporation
5+
# and other contributors as indicated by the @author tags.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
919

1020
ANSIBLE_METADATA = {
1121
'status': ['preview'],
@@ -59,13 +69,13 @@
5969
ibm_ss_cluster:
6070
state: present
6171
stanza: "/tmp/stanza"
62-
name: "host-01"
72+
name: "node1.domain.com"
6373
6474
# Delete an existing IBM Spectrum Scale Cluster
6575
- name: Delete an IBM Spectrum Scale Cluster
6676
ibm_ss_cluster:
6777
state: absent
68-
name: "host-01"
78+
name: "node1.domain.com"
6979
'''
7080

7181
RETURN = '''
@@ -93,54 +103,27 @@
93103
import os
94104
import json
95105
import sys
106+
import traceback
96107
from ansible.module_utils.basic import AnsibleModule
97108

98-
#TODO: FIX THIS. If the modules and utils are located in a non standard
99-
# path, the PYTHONPATH will need to be exported in the .bashrc
100-
#from ansible.module_utils.ibm_ss_utils import runCmd, parse_aggregate_cmd_output, RC_SUCCESS
101-
from ansible.module_utils.ibm_ss_utils import runCmd, parse_aggregate_cmd_output, RC_SUCCESS
102-
103-
MMLSCLUSTER_SUMMARY_FIELDS=['clusterSummary','cnfsSummary', 'cesSummary']
104-
105-
106-
def get_cluster_info():
107-
msg = result_json = ""
108-
stdout, stderr, rc = runCmd(["/usr/lpp/mmfs/bin/mmlscluster","-Y"], sh=False)
109-
110-
if rc == RC_SUCCESS:
111-
result_dict = parse_aggregate_cmd_output(stdout,
112-
MMLSCLUSTER_SUMMARY_FIELDS)
113-
result_json = json.dumps(result_dict)
114-
msg = "mmlscluster successfully executed"
115-
else:
116-
msg = stderr
117-
118-
return rc, msg, result_json
119-
109+
try:
110+
from ansible.module_utils.ibm_ss_utils import RC_SUCCESS, SpectrumScaleLogger
111+
except:
112+
from ibm_ss_utils import RC_SUCCESS, SpectrumScaleLogger
120113

121-
def create_cluster(name, stanza_path):
122-
# TODO: Make This idempotent
123-
stdout, stderr, rc = runCmd(["/usr/lpp/mmfs/bin/mmcrcluster",
124-
"-N", stanza_path,
125-
"-C", name],
126-
sh=False)
114+
try:
115+
from ansible.module_utils.ibm_ss_cluster_utils import SpectrumScaleCluster
116+
except:
117+
from ibm_ss_cluster_utils import SpectrumScaleCluster
127118

128-
if rc == RC_SUCCESS:
129-
msg = stdout
130-
else:
131-
msg = stderr
132119

133-
return rc, msg
134-
135-
136-
def delete_cluster(name):
137-
# TODO: Implement
138-
rc = RC_SUCCESS
139-
msg = ""
140-
return rc, msg
120+
def main():
121+
logger = SpectrumScaleLogger.get_logger()
141122

123+
logger.debug("------------------------------------")
124+
logger.debug("Function Entry: ibm_ss_cluster.main()")
125+
logger.debug("------------------------------------")
142126

143-
def main():
144127
# Setup the module argument specifications
145128
scale_arg_spec = dict(
146129
op = dict(
@@ -185,21 +168,55 @@ def main():
185168
state_changed = False
186169
if module.params['op'] and "get" in module.params['op']:
187170
# Retrieve the IBM Spectrum Scale cluster information
188-
rc, msg, result_json = get_cluster_info()
171+
try:
172+
scale_cluster = SpectrumScaleCluster()
173+
cluster_info_dict = {}
174+
cluster_info_dict["cluster_info"] = scale_cluster.get_cluster_dict()
175+
result_json = json.dumps(cluster_info_dict)
176+
msg = "Retrieve Cluster information successfully executed"
177+
except Exception as e:
178+
st = traceback.format_exc()
179+
e_msg = ("Exception: {0} StackTrace: {1}".format(str(e), st))
180+
module.fail_json(msg=e_msg)
189181
elif module.params['state']:
190182
if "present" in module.params['state']:
191183
# Create a new IBM Spectrum Scale cluster
192-
rc, msg = create_cluster(
193-
module.params['name'],
194-
module.params['stanza']
195-
)
184+
try:
185+
cmd_rc, stdout = SpectrumScaleCluster.create_cluster(
186+
module.params['name'],
187+
module.params['stanza']
188+
)
189+
rc = cmd_rc
190+
msg = "Create Cluster successfully executed"
191+
result_json = stdout
192+
except Exception as e:
193+
st = traceback.format_exc()
194+
e_msg = ("Exception: {0} StackTrace: {1}".format(str(e), st))
195+
module.fail_json(msg=e_msg)
196196
else:
197197
# Delete the existing IBM Spectrum Scale cluster
198-
rc, msg = delete_cluster(module.params['name'])
198+
try:
199+
cmd_rc, stdout = SpectrumScaleCluster.delete_cluster(
200+
module.params['name']
201+
)
202+
rc = cmd_rc
203+
msg = "Delete Cluster successfully executed"
204+
result_json = stdout
205+
except Exception as e:
206+
st = traceback.format_exc()
207+
e_msg = ("Exception: {0} StackTrace: {1}".format(str(e), st))
208+
module.fail_json(msg=e_msg)
209+
199210

200211
if rc == RC_SUCCESS:
201212
state_changed = True
202213

214+
logger.debug("------------------------------------")
215+
logger.debug("Function Exit: ibm_ss_cluster.main()")
216+
logger.debug("------------------------------------")
217+
218+
SpectrumScaleLogger.shutdown()
219+
203220
# Module is done. Return back the result
204221
module.exit_json(changed=state_changed, msg=msg, rc=rc, result=result_json)
205222

roles/custom_module/library/ibm_ss_filesystem.py

+81-71
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
3-
4-
# author: IBM Corporation
5-
# description: Highly-customizable Ansible module
6-
# for installing and configuring IBM Spectrum Scale (GPFS)
7-
# company: IBM
8-
# license: Apache-2.0
3+
#
4+
# Copyright 2020 IBM Corporation
5+
# and other contributors as indicated by the @author tags.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
#
919

1020
ANSIBLE_METADATA = {
1121
'status': ['preview'],
@@ -116,65 +126,27 @@
116126

117127
import json
118128
import sys
129+
import traceback
119130
from ansible.module_utils.basic import AnsibleModule
120131

121-
#TODO: FIX THIS. If the modules and utils are located in a non standard
122-
# path, the PYTHONPATH will need to be exported in the .bashrc
123-
from ansible.module_utils.ibm_ss_utils import runCmd, parse_simple_cmd_output, RC_SUCCESS
132+
try:
133+
from ansible.module_utils.ibm_ss_utils import RC_SUCCESS, SpectrumScaleLogger
134+
except:
135+
from ibm_ss_utils import RC_SUCCESS, SpectrumScaleLogger
124136

137+
try:
138+
from ansible.module_utils.ibm_ss_filesystem_utils import SpectrumScaleFS
139+
except:
140+
from ibm_ss_filesystem_utils import SpectrumScaleFS
125141

126-
MMLSFS_DATATYPE="filesystems"
127-
MMLSFS_KEY="deviceName"
128-
MMLSFS_PROPERTY_NAME="properties"
129142

130-
def get_filesystem_info():
131-
msg = result_json = ""
132-
stdout, stderr, rc = runCmd(["/usr/lpp/mmfs/bin/mmlsfs","all","-Y"], sh=False)
133-
134-
if rc == RC_SUCCESS:
135-
result_dict = parse_simple_cmd_output(
136-
stdout,
137-
MMLSFS_KEY,
138-
MMLSFS_PROPERTY_NAME,
139-
MMLSFS_DATATYPE
140-
)
141-
result_json = json.dumps(result_dict)
142-
msg = "The command \"mmlsfs\" executed successfully"
143-
else:
144-
msg = stderr
145-
146-
return rc, msg, result_json
147-
148-
149-
def create_filesystem(name, stanza_path):
150-
# TODO: Make This idempotent
151-
stdout, stderr, rc = runCmd(["/usr/lpp/mmfs/bin/mmcrfs",
152-
name,
153-
"-F", stanza_path,
154-
"-B", block_size,
155-
"-m", default_metadata_replicas,
156-
"-r", default_data_replicas,
157-
"-n", num_nodes,
158-
"-A", automatic_mount_option,
159-
"-T", default_mount_point],
160-
sh=False)
161-
162-
if rc == RC_SUCCESS:
163-
msg = stdout
164-
else:
165-
msg = stderr
166-
167-
return rc, msg
168-
169-
170-
def delete_filesystem(name):
171-
# TODO: Implement
172-
rc = RC_SUCCESS
173-
msg = ""
174-
return rc, msg
143+
def main():
144+
logger = SpectrumScaleLogger.get_logger()
175145

146+
logger.debug("---------------------------------------")
147+
logger.debug("Function Entry: ibm_ss_filesystem.main()")
148+
logger.debug("---------------------------------------")
176149

177-
def main():
178150
# Setup the module argument specifications
179151
scale_arg_spec = dict(
180152
op = dict(
@@ -250,28 +222,66 @@ def main():
250222
msg = result_json = ""
251223
state_changed = False
252224
if module.params['op'] and "get" in module.params['op']:
253-
# Retrieve the IBM Spectrum Scae filesystem information
254-
rc, msg, result_json = get_filesystem_info()
225+
# Retrieve the IBM Spectrum Scale filesystem information
226+
try:
227+
result_dict = {}
228+
filesystem_list = []
229+
230+
filesystems = SpectrumScaleFS.get_filesystems()
231+
for fs in filesystems:
232+
filesystem_info = {}
233+
filesystem_info["deviceName"] = fs.get_device_name()
234+
filesystem_info["properties"] = fs.get_properties_list()
235+
filesystem_list.append(filesystem_info)
236+
237+
result_dict["filesystems"] = filesystem_list
238+
result_json = json.dumps(result_dict)
239+
240+
msg = "Successfully retrieved filesystem information"
241+
except Exception as e:
242+
st = traceback.format_exc()
243+
e_msg = ("Exception: {0} StackTrace: {1}".format(str(e), st))
244+
module.fail_json(msg=e_msg)
255245
elif module.params['state']:
256246
if "present" in module.params['state']:
257247
# Create a new IBM Spectrum Scale cluster
258-
rc, msg = create_filesystem(
259-
module.params['stanza'],
260-
module.params['name'],
261-
module.params["block_size"],
262-
module.params["num_nodes"],
263-
module.params["default_metadata_replicas"],
264-
module.params["default_data_replicas"],
265-
module.params["automatic_mount_option"],
266-
module.params["default_mount_point"]
267-
)
248+
try:
249+
rc, result_json = SpectrumScaleFS.create_filesystem(
250+
module.params['stanza'],
251+
module.params['name'],
252+
module.params["block_size"],
253+
module.params["num_nodes"],
254+
module.params["default_metadata_replicas"],
255+
module.params["default_data_replicas"],
256+
module.params["automatic_mount_option"],
257+
module.params["default_mount_point"]
258+
)
259+
msg = "Successfully created filesystem"
260+
except Exception as e:
261+
st = traceback.format_exc()
262+
e_msg = ("Exception: {0} StackTrace: {1}".format(str(e), st))
263+
module.fail_json(msg=e_msg)
268264
else:
269265
# Delete the existing IBM Spectrum Scale cluster
270-
rc, msg = delete_filesystem(module.params['name'])
266+
try:
267+
rc, result_json = SpectrumScaleFS.delete_filesystem(
268+
module.params['name']
269+
)
270+
msg = "Successfully deleted filesystem"
271+
except Exception as e:
272+
st = traceback.format_exc()
273+
e_msg = ("Exception: {0} StackTrace: {1}".format(str(e), st))
274+
module.fail_json(msg=e_msg)
271275

272276
if rc == RC_SUCCESS:
273277
state_changed = True
274278

279+
logger.debug("---------------------------------------")
280+
logger.debug("Function Exit: ibm_ss_filesystem.main()")
281+
logger.debug("---------------------------------------")
282+
283+
logger = SpectrumScaleLogger.shutdown()
284+
275285
# Module is done. Return back the result
276286
module.exit_json(changed=state_changed, msg=msg, rc=rc, result=result_json)
277287

0 commit comments

Comments
 (0)