����JFIF���������
__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or
# https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
DOCUMENTATION = """
module: nxos_vsan
short_description: Configuration of vsan for Cisco NXOS MDS Switches.
description:
- Configuration of vsan for Cisco MDS NXOS.
version_added: 1.0.0
author:
- Suhas Bharadwaj (@srbharadwaj) (subharad@cisco.com)
notes:
- Tested against Cisco MDS NX-OS 8.4(1)
options:
vsan:
description:
- List of vsan details to be added or removed
type: list
elements: dict
suboptions:
id:
description:
- Vsan id
required: true
type: int
name:
description:
- Name of the vsan
type: str
suspend:
description:
- suspend the vsan if True
type: bool
remove:
description:
- Removes the vsan if True
type: bool
interface:
description:
- List of vsan's interfaces to be added
type: list
elements: str
"""
EXAMPLES = """
- name: Test that vsan module works
cisco.nxos.nxos_vsan:
vsan:
- id: 922
interface:
- fc1/1
- fc1/2
- port-channel 1
name: vsan-SAN-A
remove: false
suspend: false
- id: 923
interface:
- fc1/11
- fc1/21
- port-channel 2
name: vsan-SAN-B
remove: false
suspend: true
- id: 1923
name: vsan-SAN-Old
remove: true
"""
RETURN = """
commands:
description: commands sent to the device
returned: always
type: list
sample:
- terminal dont-ask
- vsan database
- vsan 922 interface fc1/40
- vsan 922 interface port-channel 155
- no terminal dont-ask
"""
import re
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxos import (
load_config,
run_commands,
)
__metaclass__ = type
class Vsan(object):
def __init__(self, vsanid):
self.vsanid = vsanid
self.vsanname = None
self.vsanstate = None
self.vsanoperstate = None
self.vsaninterfaces = []
class GetVsanInfoFromSwitch(object):
"""docstring for GetVsanInfoFromSwitch"""
def __init__(self, module):
self.module = module
self.vsaninfo = {}
self.processShowVsan()
self.processShowVsanMembership()
def execute_show_vsan_cmd(self):
output = execute_show_command("show vsan", self.module)[0]
return output
def execute_show_vsan_mem_cmd(self):
output = execute_show_command("show vsan membership", self.module)[0]
return output
def processShowVsan(self):
patv = r"^vsan\s+(\d+)\s+information"
patnamestate = "name:(.*)state:(.*)"
patoperstate = "operational state:(.*)"
output = self.execute_show_vsan_cmd().split("\n")
for o in output:
z = re.match(patv, o.strip())
if z:
v = z.group(1).strip()
self.vsaninfo[v] = Vsan(v)
z1 = re.match(patnamestate, o.strip())
if z1:
n = z1.group(1).strip()
s = z1.group(2).strip()
self.vsaninfo[v].vsanname = n
self.vsaninfo[v].vsanstate = s
z2 = re.match(patoperstate, o.strip())
if z2:
oper = z2.group(1).strip()
self.vsaninfo[v].vsanoperstate = oper
# 4094/4079 vsan is always present
self.vsaninfo["4079"] = Vsan("4079")
self.vsaninfo["4094"] = Vsan("4094")
def processShowVsanMembership(self):
patv = r"^vsan\s+(\d+).*"
output = self.execute_show_vsan_mem_cmd().split("\n")
memlist = []
v = None
for o in output:
z = re.match(patv, o.strip())
if z:
if v is not None:
self.vsaninfo[v].vsaninterfaces = memlist
memlist = []
v = z.group(1)
if "interfaces" not in o:
llist = o.strip().split()
memlist = memlist + llist
self.vsaninfo[v].vsaninterfaces = memlist
def getVsanInfoObjects(self):
return self.vsaninfo
def execute_show_command(command, module, command_type="cli_show"):
output = "text"
commands = [{"command": command, "output": output}]
return run_commands(module, commands)
def flatten_list(command_lists):
flat_command_list = []
for command in command_lists:
if isinstance(command, list):
flat_command_list.extend(command)
else:
flat_command_list.append(command)
return flat_command_list
def main():
vsan_element_spec = dict(
id=dict(required=True, type="int"),
name=dict(type="str"),
remove=dict(type="bool"),
suspend=dict(type="bool"),
interface=dict(type="list", elements="str"),
)
argument_spec = dict(vsan=dict(type="list", elements="dict", options=vsan_element_spec))
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
warnings = list()
messages = list()
commands_executed = list()
result = {"changed": False}
obj = GetVsanInfoFromSwitch(module)
dictSwVsanObjs = obj.getVsanInfoObjects()
commands = []
vsan_list = module.params["vsan"]
for eachvsan in vsan_list:
vsanid = str(eachvsan["id"])
vsanname = eachvsan["name"]
vsanremove = eachvsan["remove"]
vsansuspend = eachvsan["suspend"]
vsaninterface_list = eachvsan["interface"]
if int(vsanid) < 1 or int(vsanid) >= 4095:
module.fail_json(
msg=vsanid + " - This is an invalid vsan. Supported vsan range is 1-4094",
)
if vsanid in dictSwVsanObjs.keys():
sw_vsanid = vsanid
sw_vsanname = dictSwVsanObjs[vsanid].vsanname
sw_vsanstate = dictSwVsanObjs[vsanid].vsanstate
sw_vsaninterfaces = dictSwVsanObjs[vsanid].vsaninterfaces
else:
sw_vsanid = None
sw_vsanname = None
sw_vsanstate = None
sw_vsaninterfaces = []
if vsanremove:
# Negative case:
if vsanid == "4079" or vsanid == "4094":
messages.append(str(vsanid) + " is a reserved vsan, hence cannot be removed")
continue
if vsanid == sw_vsanid:
commands.append("no vsan " + str(vsanid))
messages.append("deleting the vsan " + str(vsanid))
else:
messages.append(
"There is no vsan "
+ str(vsanid)
+ " present in the switch. Hence there is nothing to delete",
)
continue
else:
# Negative case:
if vsanid == "4079" or vsanid == "4094":
messages.append(
str(vsanid) + " is a reserved vsan, and always present on the switch",
)
else:
if vsanid == sw_vsanid:
messages.append(
"There is already a vsan "
+ str(vsanid)
+ " present in the switch. Hence there is nothing to configure",
)
else:
commands.append("vsan " + str(vsanid))
messages.append("creating vsan " + str(vsanid))
if vsanname is not None:
# Negative case:
if vsanid == "4079" or vsanid == "4094":
messages.append(str(vsanid) + " is a reserved vsan, and cannot be renamed")
else:
if vsanname == sw_vsanname:
messages.append(
"There is already a vsan "
+ str(vsanid)
+ " present in the switch, which has the name "
+ vsanname
+ " Hence there is nothing to configure",
)
else:
commands.append("vsan " + str(vsanid) + " name " + vsanname)
messages.append("setting vsan name to " + vsanname + " for vsan " + str(vsanid))
if vsansuspend:
# Negative case:
if vsanid == "4079" or vsanid == "4094":
messages.append(str(vsanid) + " is a reserved vsan, and cannot be suspended")
else:
if sw_vsanstate == "suspended":
messages.append(
"There is already a vsan "
+ str(vsanid)
+ " present in the switch, which is in suspended state ",
)
else:
commands.append("vsan " + str(vsanid) + " suspend")
messages.append("suspending the vsan " + str(vsanid))
else:
if sw_vsanstate == "active":
messages.append(
"There is already a vsan "
+ str(vsanid)
+ " present in the switch, which is in active state ",
)
else:
commands.append("no vsan " + str(vsanid) + " suspend")
messages.append("no suspending the vsan " + str(vsanid))
if vsaninterface_list is not None:
for each_interface_name in vsaninterface_list:
# For fcip,port-channel,vfc-port-channel need to remove the
# extra space to compare
temp = re.sub(" +", "", each_interface_name)
if temp in sw_vsaninterfaces:
messages.append(
each_interface_name
+ " is already present in the vsan "
+ str(vsanid)
+ " interface list",
)
else:
commands.append("vsan " + str(vsanid) + " interface " + each_interface_name)
messages.append(
"adding interface " + each_interface_name + " to vsan " + str(vsanid),
)
if len(commands) != 0:
commands = ["terminal dont-ask"] + ["vsan database"] + commands + ["no terminal dont-ask"]
cmds = flatten_list(commands)
commands_executed = cmds
if commands_executed:
if module.check_mode:
module.exit_json(
changed=False,
commands=commands_executed,
msg="Check Mode: No cmds issued to the hosts",
)
else:
result["changed"] = True
load_config(module, commands_executed)
result["messages"] = messages
result["commands"] = commands_executed
result["warnings"] = warnings
module.exit_json(**result)
if __name__ == "__main__":
main()
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| __pycache__ | Folder | 0755 |
|
|
| storage | Folder | 0755 |
|
|
| __init__.py | File | 0 B | 0644 |
|
| nxos_aaa_server.py | File | 10.19 KB | 0644 |
|
| nxos_aaa_server_host.py | File | 10.92 KB | 0644 |
|
| nxos_acl_interfaces.py | File | 10.21 KB | 0644 |
|
| nxos_acls.py | File | 28.71 KB | 0644 |
|
| nxos_banner.py | File | 6.44 KB | 0644 |
|
| nxos_bfd_global.py | File | 9.08 KB | 0644 |
|
| nxos_bfd_interfaces.py | File | 6.84 KB | 0644 |
|
| nxos_bgp.py | File | 25.3 KB | 0644 |
|
| nxos_bgp_address_family.py | File | 30.41 KB | 0644 |
|
| nxos_bgp_af.py | File | 31.01 KB | 0644 |
|
| nxos_bgp_global.py | File | 48.43 KB | 0644 |
|
| nxos_bgp_neighbor.py | File | 18.79 KB | 0644 |
|
| nxos_bgp_neighbor_address_family.py | File | 33.62 KB | 0644 |
|
| nxos_bgp_neighbor_af.py | File | 26.84 KB | 0644 |
|
| nxos_command.py | File | 7.41 KB | 0644 |
|
| nxos_config.py | File | 22.51 KB | 0644 |
|
| nxos_devicealias.py | File | 18.33 KB | 0644 |
|
| nxos_evpn_global.py | File | 2.62 KB | 0644 |
|
| nxos_evpn_vni.py | File | 9.44 KB | 0644 |
|
| nxos_facts.py | File | 8.52 KB | 0644 |
|
| nxos_feature.py | File | 9.21 KB | 0644 |
|
| nxos_file_copy.py | File | 17.39 KB | 0644 |
|
| nxos_gir.py | File | 11.5 KB | 0644 |
|
| nxos_gir_profile_management.py | File | 5.84 KB | 0644 |
|
| nxos_hostname.py | File | 5.63 KB | 0644 |
|
| nxos_hsrp.py | File | 15.02 KB | 0644 |
|
| nxos_hsrp_interfaces.py | File | 6.16 KB | 0644 |
|
| nxos_igmp.py | File | 4.49 KB | 0644 |
|
| nxos_igmp_interface.py | File | 21.88 KB | 0644 |
|
| nxos_igmp_snooping.py | File | 9.72 KB | 0644 |
|
| nxos_install_os.py | File | 21.07 KB | 0644 |
|
| nxos_interfaces.py | File | 13.69 KB | 0644 |
|
| nxos_l2_interfaces.py | File | 12.05 KB | 0644 |
|
| nxos_l3_interfaces.py | File | 15.12 KB | 0644 |
|
| nxos_lacp.py | File | 6.39 KB | 0644 |
|
| nxos_lacp_interfaces.py | File | 9.13 KB | 0644 |
|
| nxos_lag_interfaces.py | File | 8.66 KB | 0644 |
|
| nxos_lldp_global.py | File | 8.68 KB | 0644 |
|
| nxos_lldp_interfaces.py | File | 6.21 KB | 0644 |
|
| nxos_logging.py | File | 27.52 KB | 0644 |
|
| nxos_logging_global.py | File | 21.08 KB | 0644 |
|
| nxos_ntp.py | File | 12.98 KB | 0644 |
|
| nxos_ntp_auth.py | File | 9.17 KB | 0644 |
|
| nxos_ntp_global.py | File | 19.63 KB | 0644 |
|
| nxos_ntp_options.py | File | 4.53 KB | 0644 |
|
| nxos_nxapi.py | File | 14.01 KB | 0644 |
|
| nxos_ospf_interfaces.py | File | 43.32 KB | 0644 |
|
| nxos_ospfv2.py | File | 62.64 KB | 0644 |
|
| nxos_ospfv3.py | File | 53.01 KB | 0644 |
|
| nxos_overlay_global.py | File | 5.64 KB | 0644 |
|
| nxos_pim.py | File | 6.15 KB | 0644 |
|
| nxos_pim_interface.py | File | 19.74 KB | 0644 |
|
| nxos_pim_rp_address.py | File | 7.61 KB | 0644 |
|
| nxos_ping.py | File | 7.05 KB | 0644 |
|
| nxos_prefix_lists.py | File | 26.39 KB | 0644 |
|
| nxos_reboot.py | File | 2.24 KB | 0644 |
|
| nxos_rollback.py | File | 3.51 KB | 0644 |
|
| nxos_route_maps.py | File | 57.7 KB | 0644 |
|
| nxos_rpm.py | File | 12.29 KB | 0644 |
|
| nxos_snapshot.py | File | 12.17 KB | 0644 |
|
| nxos_snmp_community.py | File | 6.6 KB | 0644 |
|
| nxos_snmp_contact.py | File | 3.81 KB | 0644 |
|
| nxos_snmp_host.py | File | 15.1 KB | 0644 |
|
| nxos_snmp_location.py | File | 3.91 KB | 0644 |
|
| nxos_snmp_server.py | File | 50.27 KB | 0644 |
|
| nxos_snmp_traps.py | File | 7.97 KB | 0644 |
|
| nxos_snmp_user.py | File | 12.34 KB | 0644 |
|
| nxos_static_routes.py | File | 20.79 KB | 0644 |
|
| nxos_system.py | File | 12.77 KB | 0644 |
|
| nxos_telemetry.py | File | 8.98 KB | 0644 |
|
| nxos_udld.py | File | 7.09 KB | 0644 |
|
| nxos_udld_interface.py | File | 8.51 KB | 0644 |
|
| nxos_user.py | File | 15.37 KB | 0644 |
|
| nxos_vlans.py | File | 10.6 KB | 0644 |
|
| nxos_vpc.py | File | 15.59 KB | 0644 |
|
| nxos_vpc_interface.py | File | 9.92 KB | 0644 |
|
| nxos_vrf.py | File | 19.78 KB | 0644 |
|
| nxos_vrf_af.py | File | 7.71 KB | 0644 |
|
| nxos_vrf_interface.py | File | 7.37 KB | 0644 |
|
| nxos_vrrp.py | File | 12 KB | 0644 |
|
| nxos_vsan.py | File | 10.8 KB | 0644 |
|
| nxos_vtp_domain.py | File | 5.73 KB | 0644 |
|
| nxos_vtp_password.py | File | 7.8 KB | 0644 |
|
| nxos_vtp_version.py | File | 5.54 KB | 0644 |
|
| nxos_vxlan_vtep.py | File | 16.86 KB | 0644 |
|
| nxos_vxlan_vtep_vni.py | File | 15.7 KB | 0644 |
|
| nxos_zone_zoneset.py | File | 33.96 KB | 0644 |
|