Debian Codegraph @

ansible_collections/cisco/nxos/plugins/modules/nxos_zone_zoneset.py

raw
1 #!/usr/bin/python
2 # Copyright: Ansible Project
3 # GNU General Public License v3.0+ (see COPYING or
4 # https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7
8
9 DOCUMENTATION = """
10 module: nxos_zone_zoneset
11 short_description: Configuration of zone/zoneset for Cisco NXOS MDS Switches.
12 description:
13 - Configuration of zone/zoneset for Cisco MDS NXOS.
14 version_added: 1.0.0
15 author:
16 - Suhas Bharadwaj (@srbharadwaj) ([email protected])
17 notes:
18 - Tested against Cisco MDS NX-OS 8.4(1)
19 options:
20 zone_zoneset_details:
21 description:
22 - List of zone/zoneset details to be added or removed
23 type: list
24 elements: dict
25 suboptions:
26 vsan:
27 description:
28 - vsan id
29 required: true
30 type: int
31 mode:
32 description:
33 - mode of the zone for the vsan
34 choices:
35 - enhanced
36 - basic
37 type: str
38 default_zone:
39 description:
40 - default zone behaviour for the vsan
41 choices:
42 - permit
43 - deny
44 type: str
45 smart_zoning:
46 description:
47 - Removes the vsan if True
48 type: bool
49 zone:
50 description:
51 - List of zone options for that vsan
52 type: list
53 elements: dict
54 suboptions:
55 name:
56 description:
57 - name of the zone
58 required: true
59 type: str
60 remove:
61 description:
62 - Deletes the zone if True
63 type: bool
64 default: false
65 members:
66 description:
67 - Members of the zone that needs to be removed or added
68 type: list
69 elements: dict
70 suboptions:
71 pwwn:
72 description:
73 - >-
74 pwwn member of the zone, use alias 'device_alias' as option
75 for device_alias member
76 aliases:
77 - device_alias
78 required: true
79 type: str
80 remove:
81 description:
82 - Removes member from the zone if True
83 type: bool
84 default: false
85 devtype:
86 description:
87 - >-
88 devtype of the zone member used along with Smart zoning
89 config
90 choices:
91 - initiator
92 - target
93 - both
94 type: str
95 zoneset:
96 description:
97 - List of zoneset options for the vsan
98 type: list
99 elements: dict
100 suboptions:
101 name:
102 description:
103 - name of the zoneset
104 required: true
105 type: str
106 remove:
107 description:
108 - Removes zoneset if True
109 type: bool
110 default: false
111 action:
112 description:
113 - activates/de-activates the zoneset
114 choices:
115 - activate
116 - deactivate
117 type: str
118 members:
119 description:
120 - Members of the zoneset that needs to be removed or added
121 type: list
122 elements: dict
123 suboptions:
124 name:
125 description:
126 - >-
127 name of the zone that needs to be added to the zoneset or
128 removed from the zoneset
129 required: true
130 type: str
131 remove:
132 description:
133 - Removes zone member from the zoneset
134 type: bool
135 default: false
136
137 """
138
139 EXAMPLES = """
140 - name: Test that zone/zoneset module works
141 cisco.nxos.nxos_zone_zoneset:
142 zone_zoneset_details:
143 - mode: enhanced
144 vsan: 22
145 zone:
146 - members:
147 - pwwn: 31314874576271
148 - device_alias: test123
149 - pwwn: '61:61:62:62:12:12:12:12'
150 remove: true
151 name: zoneA
152 - members:
153 - pwwn: 28515514576271
154 - pwwn: '62:62:62:62:21:21:21:21'
155 name: zoneB
156 - name: zoneC
157 remove: true
158 zoneset:
159 - action: activate
160 members:
161 - name: zoneA
162 - name: zoneB
163 - name: zoneC
164 remove: true
165 name: zsetname1
166 - action: deactivate
167 name: zsetTestExtra
168 remove: true
169 - mode: basic
170 smart_zoning: true
171 vsan: 21
172 zone:
173 - members:
174 - devtype: both
175 pwwn: 31314874576271
176 - pwwn: '62:62:62:62:12:12:12:12'
177 - devtype: both
178 pwwn: '92:62:62:62:12:12:1a:1a'
179 remove: true
180 name: zone21A
181 - members:
182 - pwwn: 28515514576271
183 - pwwn: '62:62:62:62:21:21:21:21'
184 name: zone21B
185 zoneset:
186 - action: activate
187 members:
188 - name: zone21A
189 - name: zone21B
190 name: zsetname212
191 """
192
193 RETURN = """
194 commands:
195 description: commands sent to the device
196 returned: always
197 type: list
198 sample:
199 - terminal dont-ask
200 - zone name zoneA vsan 923
201 - member pwwn 11:11:11:11:11:11:11:11
202 - no member device-alias test123
203 - zone commit vsan 923
204 - no terminal dont-ask
205 messages:
206 description: debug messages
207 returned: always
208 type: list
209 sample:
210 - "zone mode is already enhanced ,no change in zone mode configuration for vsan 922"
211 - "zone member '11:11:11:11:11:11:11:11' is already present in zone 'zoneA' in vsan 922 hence nothing to add"
212 - "zone member 'test123' is already present in zone 'zoneA' in vsan 922 hence nothing to add"
213 - "zone member '61:61:62:62:12:12:12:12' is not present in zone 'zoneA' in vsan 922 hence nothing to remove"
214 - "zone member '10:11:11:11:11:11:11:11' is already present in zone 'zoneB' in vsan 922 hence nothing to add"
215 - "zone member '62:62:62:62:21:21:21:21' is already present in zone 'zoneB' in vsan 922 hence nothing to add"
216 - "zone 'zoneC' is not present in vsan 922 , so nothing to remove"
217 """
218
219
220 import re
221
222 from ansible.module_utils.basic import AnsibleModule
223
224 from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import (
225 load_config,
226 run_commands,
227 )
228
229
230 __metaclass__ = type
231
232
233 class ShowZonesetActive(object):
234 """docstring for ShowZonesetActive"""
235
236 def __init__(self, module, vsan):
237 self.vsan = vsan
238 self.module = module
239 self.activeZSName = None
240 self.parseCmdOutput()
241
242 def execute_show_zoneset_active_cmd(self):
243 command = "show zoneset active vsan " + str(self.vsan) + " | grep zoneset"
244 output = execute_show_command(command, self.module)[0]
245 return output
246
247 def parseCmdOutput(self):
248 patZoneset = r"zoneset name (\S+) vsan " + str(self.vsan)
249 output = self.execute_show_zoneset_active_cmd().split("\n")
250 if len(output) == 0:
251 return
252 else:
253 for line in output:
254 line = line.strip()
255 mzs = re.match(patZoneset, line.strip())
256 if mzs:
257 self.activeZSName = mzs.group(1).strip()
258 return
259
260 def isZonesetActive(self, zsname):
261 if zsname == self.activeZSName:
262 return True
263 return False
264
265
266 class ShowZoneset(object):
267 """docstring for ShowZoneset"""
268
269 def __init__(self, module, vsan):
270 self.vsan = vsan
271 self.module = module
272 self.zsDetails = {}
273 self.parseCmdOutput()
274
275 def execute_show_zoneset_cmd(self):
276 command = "show zoneset vsan " + str(self.vsan)
277 output = execute_show_command(command, self.module)[0]
278 return output
279
280 def parseCmdOutput(self):
281 patZoneset = r"zoneset name (\S+) vsan " + str(self.vsan)
282 patZone = r"zone name (\S+) vsan " + str(self.vsan)
283 output = self.execute_show_zoneset_cmd().split("\n")
284 for line in output:
285 line = line.strip()
286 mzs = re.match(patZoneset, line.strip())
287 mz = re.match(patZone, line.strip())
288 if mzs:
289 zonesetname = mzs.group(1).strip()
290 self.zsDetails[zonesetname] = []
291 continue
292 elif mz:
293 zonename = mz.group(1).strip()
294 v = self.zsDetails[zonesetname]
295 v.append(zonename)
296 self.zsDetails[zonesetname] = v
297
298 def isZonesetPresent(self, zsname):
299 return zsname in self.zsDetails.keys()
300
301 def isZonePresentInZoneset(self, zsname, zname):
302 if zsname in self.zsDetails.keys():
303 return zname in self.zsDetails[zsname]
304 return False
305
306
307 class ShowZone(object):
308 """docstring for ShowZone"""
309
310 def __init__(self, module, vsan):
311 self.vsan = vsan
312 self.module = module
313 self.zDetails = {}
314 self.parseCmdOutput()
315
316 def execute_show_zone_vsan_cmd(self):
317 command = "show zone vsan " + str(self.vsan)
318 output = execute_show_command(command, self.module)[0]
319 return output
320
321 def parseCmdOutput(self):
322 patZone = r"zone name (\S+) vsan " + str(self.vsan)
323 output = self.execute_show_zone_vsan_cmd().split("\n")
324 for line in output:
325 line = re.sub(r"[\[].*?[\]]", "", line)
326 line = " ".join(line.strip().split())
327 if "init" in line:
328 line = line.replace("init", "initiator")
329 m = re.match(patZone, line)
330 if m:
331 zonename = m.group(1).strip()
332 self.zDetails[zonename] = []
333 continue
334 else:
335 # For now we support only pwwn and device-alias under zone
336 # Ideally should use 'supported_choices'....but maybe next
337 # time.
338 if "pwwn" in line or "device-alias" in line:
339 v = self.zDetails[zonename]
340 v.append(line)
341 self.zDetails[zonename] = v
342
343 def isZonePresent(self, zname):
344 return zname in self.zDetails.keys()
345
346 def isZoneMemberPresent(self, zname, cmd):
347 if zname in self.zDetails.keys():
348 zonememlist = self.zDetails[zname]
349 for eachline in zonememlist:
350 if cmd in eachline:
351 return True
352 return False
353
354 def get_zDetails(self):
355 return self.zDetails
356
357
358 class ShowZoneStatus(object):
359 """docstring for ShowZoneStatus"""
360
361 def __init__(self, module, vsan):
362 self.vsan = vsan
363 self.vsanAbsent = False
364 self.module = module
365 self.default_zone = ""
366 self.mode = ""
367 self.session = ""
368 self.sz = ""
369 self.locked = False
370 self.update()
371
372 def execute_show_zone_status_cmd(self):
373 command = "show zone status vsan " + str(self.vsan)
374 output = execute_show_command(command, self.module)[0]
375 return output
376
377 def update(self):
378 output = self.execute_show_zone_status_cmd().split("\n")
379
380 patfordefzone = "VSAN: " + str(self.vsan) + r" default-zone:\s+(\S+).*"
381 patformode = r".*mode:\s+(\S+).*"
382 patforsession = r"^session:\s+(\S+).*"
383 patforsz = r".*smart-zoning:\s+(\S+).*"
384 for line in output:
385 if "is not configured" in line:
386 self.vsanAbsent = True
387 break
388 mdefz = re.match(patfordefzone, line.strip())
389 mmode = re.match(patformode, line.strip())
390 msession = re.match(patforsession, line.strip())
391 msz = re.match(patforsz, line.strip())
392
393 if mdefz:
394 self.default_zone = mdefz.group(1)
395 if mmode:
396 self.mode = mmode.group(1)
397 if msession:
398 self.session = msession.group(1)
399 if self.session != "none":
400 self.locked = True
401 if msz:
402 self.sz = msz.group(1)
403
404 def isLocked(self):
405 return self.locked
406
407 def getDefaultZone(self):
408 return self.default_zone
409
410 def getMode(self):
411 return self.mode
412
413 def getSmartZoningStatus(self):
414 return self.sz
415
416 def isVsanAbsent(self):
417 return self.vsanAbsent
418
419
420 def execute_show_command(command, module, command_type="cli_show"):
421 output = "text"
422 commands = [{"command": command, "output": output}]
423 return run_commands(module, commands)
424
425
426 def flatten_list(command_lists):
427 flat_command_list = []
428 for command in command_lists:
429 if isinstance(command, list):
430 flat_command_list.extend(command)
431 else:
432 flat_command_list.append(command)
433 return flat_command_list
434
435
436 def getMemType(supported_choices, allmemkeys, default="pwwn"):
437 for eachchoice in supported_choices:
438 if eachchoice in allmemkeys:
439 return eachchoice
440 return default
441
442
443 def main():
444 supported_choices = ["device_alias"]
445 zone_member_spec = dict(
446 pwwn=dict(required=True, type="str", aliases=["device_alias"]),
447 devtype=dict(type="str", choices=["initiator", "target", "both"]),
448 remove=dict(type="bool", default=False),
449 )
450
451 zone_spec = dict(
452 name=dict(required=True, type="str"),
453 members=dict(type="list", elements="dict", options=zone_member_spec),
454 remove=dict(type="bool", default=False),
455 )
456
457 zoneset_member_spec = dict(
458 name=dict(required=True, type="str"),
459 remove=dict(type="bool", default=False),
460 )
461
462 zoneset_spec = dict(
463 name=dict(type="str", required=True),
464 members=dict(type="list", elements="dict", options=zoneset_member_spec),
465 remove=dict(type="bool", default=False),
466 action=dict(type="str", choices=["activate", "deactivate"]),
467 )
468
469 zonedetails_spec = dict(
470 vsan=dict(required=True, type="int"),
471 mode=dict(type="str", choices=["enhanced", "basic"]),
472 default_zone=dict(type="str", choices=["permit", "deny"]),
473 smart_zoning=dict(type="bool"),
474 zone=dict(type="list", elements="dict", options=zone_spec),
475 zoneset=dict(type="list", elements="dict", options=zoneset_spec),
476 )
477
478 argument_spec = dict(
479 zone_zoneset_details=dict(
480 type="list",
481 elements="dict",
482 options=zonedetails_spec,
483 ),
484 )
485
486 module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
487
488 warnings = list()
489 messages = list()
490 commands = list()
491 result = {"changed": False}
492
493 commands_executed = []
494 listOfZoneDetails = module.params["zone_zoneset_details"]
495 for eachZoneZonesetDetail in listOfZoneDetails:
496 vsan = eachZoneZonesetDetail["vsan"]
497 op_mode = eachZoneZonesetDetail["mode"]
498 op_default_zone = eachZoneZonesetDetail["default_zone"]
499 op_smart_zoning = eachZoneZonesetDetail["smart_zoning"]
500 op_zone = eachZoneZonesetDetail["zone"]
501 op_zoneset = eachZoneZonesetDetail["zoneset"]
502
503 # Step1: execute show zone status and get
504 shZoneStatusObj = ShowZoneStatus(module, vsan)
505 sw_default_zone = shZoneStatusObj.getDefaultZone()
506 sw_mode = shZoneStatusObj.getMode()
507 sw_smart_zoning = shZoneStatusObj.getSmartZoningStatus()
508
509 if sw_smart_zoning.lower() == "Enabled".lower():
510 sw_smart_zoning_bool = True
511 else:
512 sw_smart_zoning_bool = False
513
514 if shZoneStatusObj.isVsanAbsent():
515 module.fail_json(
516 msg="Vsan " + str(vsan) + " is not present in the switch. Hence cannot procced.",
517 )
518
519 if shZoneStatusObj.isLocked():
520 module.fail_json(
521 msg="zone has acquired lock on the switch for vsan "
522 + str(vsan)
523 + ". Hence cannot procced.",
524 )
525
526 # Process zone default zone options
527 if op_default_zone is not None:
528 if op_default_zone != sw_default_zone:
529 if op_default_zone == "permit":
530 commands_executed.append(
531 "zone default-zone permit vsan " + str(vsan),
532 )
533 messages.append(
534 "default zone configuration changed from deny to permit for vsan "
535 + str(vsan),
536 )
537 else:
538 commands_executed.append(
539 "no zone default-zone permit vsan " + str(vsan),
540 )
541 messages.append(
542 "default zone configuration changed from permit to deny for vsan "
543 + str(vsan),
544 )
545 else:
546 messages.append(
547 "default zone is already "
548 + op_default_zone
549 + " ,no change in default zone configuration for vsan "
550 + str(vsan),
551 )
552
553 # Process zone mode options
554 if op_mode is not None:
555 if op_mode != sw_mode:
556 if op_mode == "enhanced":
557 commands_executed.append("zone mode enhanced vsan " + str(vsan))
558 messages.append(
559 "zone mode configuration changed from basic to enhanced for vsan "
560 + str(vsan),
561 )
562 else:
563 commands_executed.append("no zone mode enhanced vsan " + str(vsan))
564 messages.append(
565 "zone mode configuration changed from enhanced to basic for vsan "
566 + str(vsan),
567 )
568 else:
569 messages.append(
570 "zone mode is already "
571 + op_mode
572 + " ,no change in zone mode configuration for vsan "
573 + str(vsan),
574 )
575
576 # Process zone smart-zone options
577 if op_smart_zoning is not None:
578 if op_smart_zoning != sw_smart_zoning_bool:
579 if op_smart_zoning:
580 commands_executed.append(
581 "zone smart-zoning enable vsan " + str(vsan),
582 )
583 messages.append("smart-zoning enabled for vsan " + str(vsan))
584 else:
585 commands_executed.append(
586 "no zone smart-zoning enable vsan " + str(vsan),
587 )
588 messages.append("smart-zoning disabled for vsan " + str(vsan))
589 else:
590 messages.append(
591 "smart-zoning is already set to "
592 + sw_smart_zoning
593 + " , no change in smart-zoning configuration for vsan "
594 + str(vsan),
595 )
596
597 # Process zone member options
598 # TODO: Obviously this needs to be cleaned up properly, as there are a lot of ifelse statements which is bad
599 # Will take it up later becoz of time constraints
600 if op_zone is not None:
601 shZoneObj = ShowZone(module, vsan)
602 for eachzone in op_zone:
603 zname = eachzone["name"]
604 zmembers = eachzone["members"]
605 removeflag = eachzone["remove"]
606 if removeflag:
607 if shZoneObj.isZonePresent(zname):
608 messages.append(
609 "zone '" + zname + "' is removed from vsan " + str(vsan),
610 )
611 commands_executed.append(
612 "no zone name " + zname + " vsan " + str(vsan),
613 )
614 else:
615 messages.append(
616 "zone '"
617 + zname
618 + "' is not present in vsan "
619 + str(vsan)
620 + " , so nothing to remove",
621 )
622 else:
623 if zmembers is None:
624 if shZoneObj.isZonePresent(zname):
625 messages.append(
626 "zone '" + zname + "' is already present in vsan " + str(vsan),
627 )
628 else:
629 commands_executed.append(
630 "zone name " + zname + " vsan " + str(vsan),
631 )
632 messages.append(
633 "zone '" + zname + "' is created in vsan " + str(vsan),
634 )
635 else:
636 cmdmemlist = []
637 for eachmem in zmembers:
638 memtype = getMemType(supported_choices, eachmem.keys())
639 cmd = memtype.replace("_", "-") + " " + eachmem[memtype]
640 if op_smart_zoning or sw_smart_zoning_bool:
641 if eachmem["devtype"] is not None:
642 cmd = cmd + " " + eachmem["devtype"]
643 if eachmem["remove"]:
644 if shZoneObj.isZonePresent(zname):
645 if shZoneObj.isZoneMemberPresent(zname, cmd):
646 cmd = "no member " + cmd
647 cmdmemlist.append(cmd)
648 if op_smart_zoning and eachmem["devtype"] is not None:
649 messages.append(
650 "removing zone member '"
651 + eachmem[memtype]
652 + " of device type '"
653 + eachmem["devtype"]
654 + "' from zone '"
655 + zname
656 + "' in vsan "
657 + str(vsan),
658 )
659 else:
660 messages.append(
661 "removing zone member '"
662 + eachmem[memtype]
663 + "' from zone '"
664 + zname
665 + "' in vsan "
666 + str(vsan),
667 )
668 else:
669 if op_smart_zoning and eachmem["devtype"] is not None:
670 messages.append(
671 "zone member '"
672 + eachmem[memtype]
673 + "' of device type '"
674 + eachmem["devtype"]
675 + "' is not present in zone '"
676 + zname
677 + "' in vsan "
678 + str(vsan)
679 + " hence nothing to remove",
680 )
681 else:
682 messages.append(
683 "zone member '"
684 + eachmem[memtype]
685 + "' is not present in zone '"
686 + zname
687 + "' in vsan "
688 + str(vsan)
689 + " hence nothing to remove",
690 )
691 else:
692 messages.append(
693 "zone '"
694 + zname
695 + "' is not present in vsan "
696 + str(vsan)
697 + " , hence cannot remove the members",
698 )
699
700 else:
701 if shZoneObj.isZoneMemberPresent(zname, cmd):
702 if op_smart_zoning and eachmem["devtype"] is not None:
703 messages.append(
704 "zone member '"
705 + eachmem[memtype]
706 + "' of device type '"
707 + eachmem["devtype"]
708 + "' is already present in zone '"
709 + zname
710 + "' in vsan "
711 + str(vsan)
712 + " hence nothing to add",
713 )
714 else:
715 messages.append(
716 "zone member '"
717 + eachmem[memtype]
718 + "' is already present in zone '"
719 + zname
720 + "' in vsan "
721 + str(vsan)
722 + " hence nothing to add",
723 )
724 else:
725 cmd = "member " + cmd
726 cmdmemlist.append(cmd)
727 if op_smart_zoning and eachmem["devtype"] is not None:
728 messages.append(
729 "adding zone member '"
730 + eachmem[memtype]
731 + "' of device type '"
732 + eachmem["devtype"]
733 + "' to zone '"
734 + zname
735 + "' in vsan "
736 + str(vsan),
737 )
738 else:
739 messages.append(
740 "adding zone member '"
741 + eachmem[memtype]
742 + "' to zone '"
743 + zname
744 + "' in vsan "
745 + str(vsan),
746 )
747 if len(cmdmemlist) != 0:
748 commands_executed.append(
749 "zone name " + zname + " vsan " + str(vsan),
750 )
751 commands_executed = commands_executed + cmdmemlist
752
753 # Process zoneset member options
754 if op_zoneset is not None:
755 dactcmd = []
756 actcmd = []
757 shZonesetObj = ShowZoneset(module, vsan)
758 shZonesetActiveObj = ShowZonesetActive(module, vsan)
759 for eachzoneset in op_zoneset:
760 zsetname = eachzoneset["name"]
761 zsetmembers = eachzoneset["members"]
762 removeflag = eachzoneset["remove"]
763 actionflag = eachzoneset["action"]
764 if removeflag:
765 if shZonesetObj.isZonesetPresent(zsetname):
766 messages.append(
767 "zoneset '" + zsetname + "' is removed from vsan " + str(vsan),
768 )
769 commands_executed.append(
770 "no zoneset name " + zsetname + " vsan " + str(vsan),
771 )
772 else:
773 messages.append(
774 "zoneset '"
775 + zsetname
776 + "' is not present in vsan "
777 + str(vsan)
778 + " ,hence there is nothing to remove",
779 )
780 else:
781 if zsetmembers is not None:
782 cmdmemlist = []
783 for eachzsmem in zsetmembers:
784 zsetmem_name = eachzsmem["name"]
785 zsetmem_removeflag = eachzsmem["remove"]
786 if zsetmem_removeflag:
787 if shZonesetObj.isZonePresentInZoneset(
788 zsetname,
789 zsetmem_name,
790 ):
791 cmd = "no member " + zsetmem_name
792 cmdmemlist.append(cmd)
793 messages.append(
794 "removing zoneset member '"
795 + zsetmem_name
796 + "' from zoneset '"
797 + zsetname
798 + "' in vsan "
799 + str(vsan),
800 )
801 else:
802 messages.append(
803 "zoneset member '"
804 + zsetmem_name
805 + "' is not present in zoneset '"
806 + zsetname
807 + "' in vsan "
808 + str(vsan)
809 + " ,hence there is nothing to remove",
810 )
811 else:
812 if shZonesetObj.isZonePresentInZoneset(
813 zsetname,
814 zsetmem_name,
815 ):
816 messages.append(
817 "zoneset member '"
818 + zsetmem_name
819 + "' is already present in zoneset '"
820 + zsetname
821 + "' in vsan "
822 + str(vsan)
823 + " ,hence there is nothing to add",
824 )
825 else:
826 cmd = "member " + zsetmem_name
827 cmdmemlist.append(cmd)
828 messages.append(
829 "adding zoneset member '"
830 + zsetmem_name
831 + "' to zoneset '"
832 + zsetname
833 + "' in vsan "
834 + str(vsan),
835 )
836 if len(cmdmemlist) != 0:
837 commands_executed.append(
838 "zoneset name " + zsetname + " vsan " + str(vsan),
839 )
840 commands_executed = commands_executed + cmdmemlist
841 else:
842 if shZonesetObj.isZonesetPresent(zsetname):
843 messages.append(
844 "zoneset '"
845 + zsetname
846 + "' is already present in vsan "
847 + str(vsan),
848 )
849 else:
850 commands_executed.append(
851 "zoneset name " + zsetname + " vsan " + str(vsan),
852 )
853 messages.append(
854 "zoneset '" + zsetname + "' is created in vsan " + str(vsan),
855 )
856
857 # Process zoneset activate options
858 if actionflag == "deactivate":
859 if shZonesetActiveObj.isZonesetActive(zsetname):
860 messages.append(
861 "deactivating zoneset '" + zsetname + "' in vsan " + str(vsan),
862 )
863 dactcmd.append(
864 "no zoneset activate name " + zsetname + " vsan " + str(vsan),
865 )
866 else:
867 messages.append(
868 "zoneset '"
869 + zsetname
870 + "' in vsan "
871 + str(vsan)
872 + " is not activated, hence cannot deactivate",
873 )
874 elif actionflag == "activate":
875 if commands_executed:
876 messages.append(
877 "activating zoneset '" + zsetname + "' in vsan " + str(vsan),
878 )
879 actcmd.append(
880 "zoneset activate name " + zsetname + " vsan " + str(vsan),
881 )
882 else:
883 messages.append(
884 "no changes to existing zoneset '"
885 + zsetname
886 + "' in vsan "
887 + str(vsan)
888 + " hence activate action is ignored",
889 )
890 commands_executed = commands_executed + dactcmd + actcmd
891
892 if commands_executed:
893 if op_mode == "enhanced":
894 commands_executed.append("zone commit vsan " + str(vsan))
895 elif op_mode is None:
896 if sw_mode == "enhanced":
897 commands_executed.append("zone commit vsan " + str(vsan))
898
899 if commands_executed:
900 commands_executed = ["terminal dont-ask"] + commands_executed + ["no terminal dont-ask"]
901
902 cmds = flatten_list(commands_executed)
903 if cmds:
904 if module.check_mode:
905 module.exit_json(
906 changed=False,
907 commands=cmds,
908 msg="Check Mode: No cmds issued to the hosts",
909 )
910 else:
911 result["changed"] = True
912 commands = commands + cmds
913 load_config(module, cmds)
914
915 result["messages"] = messages
916 result["commands"] = commands_executed
917 result["warnings"] = warnings
918 module.exit_json(**result)
919
920
921 if __name__ == "__main__":
922 main()