def check_cli(module, cli): """ This method checks if vRouter exists on the target node. This method also checks for idempotency using the show command. If the given vRouter exists, return VROUTER_EXISTS as True else False. If an OSPF network with the given ip exists on the given vRouter, return NETWORK_EXISTS as True else False. :param module: The Ansible module to fetch input parameters :return Booleans: VROUTER_EXISTS, NETWORK_EXISTS """ vrouter_name = module.params['pn_vrouter_name'] network = module.params['pn_network'] show_cli = pn_cli(module) # Check for vRouter check_vrouter = cli + ' vrouter-show format name no-show-headers ' out = run_commands(module, check_vrouter)[1] if out: out = out.split() VROUTER_EXISTS = True if vrouter_name in out else False # Check for OSPF networks check_network = cli + ' vrouter-ospf-show vrouter-name %s ' % vrouter_name check_network += 'format network no-show-headers' out = run_commands(module, check_network)[1] if out and network in out: NETWORK_EXISTS = True else: NETWORK_EXISTS = False return VROUTER_EXISTS, NETWORK_EXISTS
def main(): """ This section is for arguments parsing """ state_map = dict(update='admin-session-timeout-modify') module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_timeout=dict(required=False, type='str'), ), required_together=[['state', 'pn_timeout']], ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] timeout = module.params['pn_timeout'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) if command == 'admin-session-timeout-modify': cli += ' %s ' % command if timeout: cli += ' timeout ' + timeout run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(present='snmp-community-create', absent='snmp-community-delete', update='snmp-community-modify') module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_community_type=dict(required=False, type='str', choices=['read-only', 'read-write']), pn_community_string=dict(required=False, type='str'), ), required_if=( ["state", "present", ["pn_community_type", "pn_community_string"]], ["state", "absent", ["pn_community_string"]], ["state", "update", ["pn_community_type", "pn_community_string"]], )) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] community_type = module.params['pn_community_type'] comm_str = module.params['pn_community_string'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) COMMUNITY_EXISTS = check_cli(module, cli) if command == 'snmp-community-modify': if COMMUNITY_EXISTS is False: module.fail_json(failed=True, msg='snmp community name %s does not exist' % comm_str) if command == 'snmp-community-delete': if COMMUNITY_EXISTS is False: module.exit_json(skipped=True, msg='snmp community name %s does not exist' % comm_str) if command == 'snmp-community-create': if COMMUNITY_EXISTS is True: module.exit_json(skipped=True, msg='snmp community with name %s already exists' % comm_str) cli += ' %s community-string %s ' % (command, comm_str) if command != 'snmp-community-delete' and community_type: cli += ' community-type ' + community_type run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(present='vrouter-bgp-network-add', absent='vrouter-bgp-network-remove') module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_netmask=dict(required=False, type='str'), pn_network=dict(required=False, type='str'), pn_vrouter_name=dict(required=False, type='str'), ), required_if=( [ 'state', 'present', ['pn_vrouter_name', 'pn_netmask', 'pn_network'] ], ['state', 'absent', ['pn_vrouter_name', 'pn_network']], ), ) # Accessing the arguments state = module.params['state'] cliswitch = module.params['pn_cliswitch'] netmask = module.params['pn_netmask'] network = module.params['pn_network'] vrouter_name = module.params['pn_vrouter_name'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) NETWORK_EXISTS, VROUTER_EXISTS = check_cli(module, cli) if VROUTER_EXISTS is None: module.fail_json(failed=True, msg='vRouter %s does not exists' % vrouter_name) if command == 'vrouter-bgp-network-add': if NETWORK_EXISTS is True: module.exit_json(skipped=True, msg='Network %s already added to bgp' % network) if command == 'vrouter-bgp-network-remove': if NETWORK_EXISTS is False: module.exit_json(skipped=True, msg='Network %s does not exists' % network) cli += ' %s vrouter-name %s ' % (command, vrouter_name) if netmask: cli += ' netmask ' + netmask if network: cli += ' network ' + network run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict( present='vrouter-packet-relay-add', absent='vrouter-packet-relay-remove' ) argument_spec = dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=False, type='str', choices=state_map.keys(), default='present'), pn_forward_ip=dict(required=True, type='str'), pn_nic=dict(required=True, type='str'), pn_forward_proto=dict(required=False, type='str', choices=['dhcp'], default='dhcp'), pn_vrouter_name=dict(required=True, type='str'), ) module = AnsibleModule( argument_spec=argument_spec, required_if=( ["state", "present", ["pn_vrouter_name", "pn_forward_ip", "pn_nic", "pn_forward_proto"]], ["state", "absent", ["pn_vrouter_name", "pn_forward_ip", "pn_nic", "pn_forward_proto"]], ), ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] forward_ip = module.params['pn_forward_ip'] nic = module.params['pn_nic'] forward_proto = module.params['pn_forward_proto'] vrouter_name = module.params['pn_vrouter_name'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) VROUTER_EXISTS, NIC_EXISTS = check_cli(module, cli) if VROUTER_EXISTS is False: module.fail_json( failed=True, msg='vRouter %s does not exist' % vrouter_name ) if NIC_EXISTS is False: module.fail_json( failed=True, msg='vRouter with nic %s does not exist' % nic ) if command == 'vrouter-packet-relay-add' or command == 'vrouter-packet-relay-remove': cli += ' %s' % command cli += ' vrouter-name %s nic %s' % (vrouter_name, nic) cli += ' forward-proto %s forward-ip %s' % (forward_proto, forward_ip) run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(present='prefix-list-network-add', absent='prefix-list-network-remove') module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_netmask=dict(required=False, type='str'), pn_name=dict(required=False, type='str'), pn_network=dict(required=False, type='str'), ), required_if=( ["state", "present", ["pn_name", "pn_network", "pn_netmask"]], ["state", "absent", ["pn_name", "pn_network", "pn_netmask"]], ), required_together=(["pn_network", "pn_netmask"], ), ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] netmask = module.params['pn_netmask'] name = module.params['pn_name'] network = module.params['pn_network'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) NETWORK_EXISTS = check_cli(module, cli) cli += ' %s ' % command if command == 'prefix-list-network-remove': if NETWORK_EXISTS is False: module.exit_json(skipped=True, msg='Prefix list with network %s does not exist' % network) if command == 'prefix-list-network-add': if NETWORK_EXISTS is True: module.exit_json(skipped=True, msg='Prefix list with network %s already exists' % network) if name: cli += ' name ' + name if network: cli += ' network ' + network if netmask: cli += ' netmask ' + netmask run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict( present='prefix-list-create', absent='prefix-list-delete' ) argument_spec = dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=False, type='str', choices=state_map.keys(), default='present'), pn_name=dict(required=True, type='str'), pn_scope=dict(required=False, type='str', choices=['local', 'fabric']), ) module = AnsibleModule( argument_spec=argument_spec, required_if=( ["state", "present", ["pn_name", "pn_scope"]], ["state", "absent", ["pn_name"]], ), ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] name = module.params['pn_name'] scope = module.params['pn_scope'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) NAME_EXISTS = check_cli(module, cli) cli += ' %s name %s ' % (command, name) if command == 'prefix-list-delete': if NAME_EXISTS is False: module.exit_json( skipped=True, msg='prefix-list with name %s does not exist' % name ) else: if command == 'prefix-list-create': if NAME_EXISTS is True: module.exit_json( skipped=True, msg='prefix list with name %s already exists' % name ) cli += ' scope %s ' % scope run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(present='vrouter-ospf6-add', absent='vrouter-ospf6-remove') module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_ospf6_area=dict(required=False, type='str'), pn_nic=dict(required=False, type='str'), pn_vrouter_name=dict(required=False, type='str'), ), required_if=([ "state", "present", ["pn_vrouter_name", "pn_nic", "pn_ospf6_area"] ], ["state", "absent", ["pn_vrouter_name", "pn_nic"]]), ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] ospf6_area = module.params['pn_ospf6_area'] nic = module.params['pn_nic'] vrouter_name = module.params['pn_vrouter_name'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) VROUTER_EXISTS, NIC_EXISTS = check_cli(module, cli) if VROUTER_EXISTS is False: module.fail_json(failed=True, msg='vRouter %s does not exist' % vrouter_name) cli += ' %s vrouter-name %s ' % (command, vrouter_name) if command == 'vrouter-ospf6-add': if NIC_EXISTS is True: module.exit_json(skipped=True, msg='OSPF6 with nic %s already exist' % nic) if nic: cli += ' nic %s' % nic if ospf6_area: cli += ' ospf6-area %s ' % ospf6_area if command == 'vrouter-ospf6-remove': if NIC_EXISTS is False: module.exit_json(skipped=True, msg='OSPF6 with nic %s does not exist' % nic) if nic: cli += ' nic %s' % nic run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(present='dhcp-filter-create', absent='dhcp-filter-delete', update='dhcp-filter-modify') module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_trusted_ports=dict(required=False, type='str'), pn_name=dict(required=False, type='str'), ), required_if=[["state", "present", ["pn_name", "pn_trusted_ports"]], ["state", "absent", ["pn_name"]], ["state", "update", ["pn_name", "pn_trusted_ports"]]]) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] trusted_ports = module.params['pn_trusted_ports'] name = module.params['pn_name'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) USER_EXISTS = check_cli(module, cli) cli += ' %s name %s ' % (command, name) if command == 'dhcp-filter-modify': if USER_EXISTS is False: module.fail_json(failed=True, msg='dhcp-filter with name %s does not exist' % name) if command == 'dhcp-filter-delete': if USER_EXISTS is False: module.exit_json(skipped=True, msg='dhcp-filter with name %s does not exist' % name) if command == 'dhcp-filter-create': if USER_EXISTS is True: module.exit_json(skipped=True, msg='dhcp-filter with name %s already exists' % name) if command != 'dhcp-filter-delete': if trusted_ports: cli += ' trusted-ports ' + trusted_ports run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict( present='access-list-ip-add', absent='access-list-ip-remove', ) module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_ip=dict(required=False, type='str', default='::'), pn_name=dict(required=False, type='str'), ), required_if=( ["state", "present", ["pn_name"]], ["state", "absent", ["pn_name", "pn_ip"]], ), ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] ip = module.params['pn_ip'] name = module.params['pn_name'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) IP_EXISTS = check_cli(module, cli) cli += ' %s name %s ' % (command, name) if command == 'access-list-ip-remove': if IP_EXISTS is False: module.exit_json(skipped=True, msg='access-list with ip %s does not exist' % ip) if ip: cli += ' ip ' + ip else: if command == 'access-list-ip-add': if IP_EXISTS is True: module.exit_json(skipped=True, msg='access list with ip %s already exists' % ip) if ip: cli += ' ip ' + ip run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(update='port-cos-bw-modify') module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_max_bw_limit=dict(required=False, type='str'), pn_cos=dict(required=False, type='str'), pn_port=dict(required=False, type='str'), pn_weight=dict(required=False, type='str', choices=['priority', 'no-priority']), pn_min_bw_guarantee=dict(required=False, type='str'), ), required_if=(['state', 'update', ['pn_cos', 'pn_port']], ), required_one_of=[[ 'pn_max_bw_limit', 'pn_min_bw_guarantee', 'pn_weight' ]], ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] max_bw_limit = module.params['pn_max_bw_limit'] cos = module.params['pn_cos'] port = module.params['pn_port'] weight = module.params['pn_weight'] min_bw_guarantee = module.params['pn_min_bw_guarantee'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) if command == 'port-cos-bw-modify': cli += ' %s ' % command if max_bw_limit: cli += ' max-bw-limit ' + max_bw_limit if cos: cli += ' cos ' + cos if port: cli += ' port ' + port if weight: cli += ' weight ' + weight if min_bw_guarantee: cli += ' min-bw-guarantee ' + min_bw_guarantee run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict( update='dscp-map-pri-map-modify' ) module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_pri=dict(required=False, type='str'), pn_name=dict(required=False, type='str'), pn_dsmap=dict(required=False, type='str'), ), required_if=( ['state', 'update', ['pn_name', 'pn_pri']], ) ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] pri = module.params['pn_pri'] name = module.params['pn_name'] dsmap = module.params['pn_dsmap'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) NAME_EXISTS = check_cli(module, cli) if command == 'dscp-map-pri-map-modify': if NAME_EXISTS is False: module.fail_json( failed=True, msg='Create dscp map with name %s before updating' % name ) cli += ' %s ' % command if pri: cli += ' pri ' + pri if name: cli += ' name ' + name if dsmap: cli += ' dsmap ' + dsmap run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(update='vrouter-pim-config-modify') module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_query_interval=dict(required=False, type='str'), pn_querier_timeout=dict(required=False, type='str'), pn_hello_interval=dict(required=False, type='str'), pn_vrouter_name=dict(required=True, type='str'), ), required_if=(['state', 'update', ['pn_vrouter_name']], ), required_one_of=[[ 'pn_query_interval', 'pn_querier_timeout', 'pn_hello_interval' ]]) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] query_interval = module.params['pn_query_interval'] querier_timeout = module.params['pn_querier_timeout'] hello_interval = module.params['pn_hello_interval'] vrouter_name = module.params['pn_vrouter_name'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) if command == 'vrouter-pim-config-modify': PIM_SSM_CONFIG = check_cli(module, cli) if PIM_SSM_CONFIG is False: module.exit_json( skipped=True, msg= 'vrouter proto-multi is not configured/vrouter is not created') cli += ' %s vrouter-name %s ' % (command, vrouter_name) if querier_timeout: cli += ' querier-timeout ' + querier_timeout if hello_interval: cli += ' hello-interval ' + hello_interval if query_interval: cli += ' query-interval ' + query_interval run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict( update='vflow-table-profile-modify' ) module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_profile=dict(required=False, type='str', choices=['application', 'ipv6', 'qos']), pn_hw_tbl=dict(required=False, type='str', choices=['switch-main', 'switch-hash', 'npu-main', 'npu-hash']), pn_enable=dict(required=False, type='bool'), ), required_if=( ['state', 'update', ['pn_profile', 'pn_hw_tbl']], ), ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] profile = module.params['pn_profile'] hw_tbl = module.params['pn_hw_tbl'] enable = module.params['pn_enable'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) if command == 'vflow-table-profile-modify': cli += ' %s ' % command if profile: cli += ' profile ' + profile if hw_tbl: cli += ' hw-tbl ' + hw_tbl cli += booleanArgs(enable, 'enable', 'disable') run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(present='ipv6security-raguard-port-add', absent='ipv6security-raguard-port-remove') argument_spec = dict(pn_cliswitch=dict(required=False, type='str'), state=dict(required=False, type='str', choices=state_map.keys(), default='present'), pn_name=dict(required=True, type='str'), pn_ports=dict(required=True, type='str')) module = AnsibleModule(argument_spec=argument_spec) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] name = module.params['pn_name'] ports = module.params['pn_ports'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) NAME_EXISTS = check_cli(module) if command: if NAME_EXISTS is False: module.fail_json( failed=True, msg= 'ipv6 security raguard with name %s does not exist to add ports' % name) cli += ' %s name %s ports %s' % (command, name, ports) run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(update='cpu-mgmt-class-modify') module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_burst_size=dict(required=False, type='str'), pn_name=dict(required=False, type='str', choices=[ 'arp', 'icmp', 'ssh', 'snmp', 'fabric', 'bcast', 'nfs', 'web', 'web-ssl', 'net-api' ]), pn_rate_limit=dict(required=False, type='str'), ), required_if=([[ 'state', 'update', ['pn_name', 'pn_burst_size', 'pn_rate_limit'] ]]), ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] burst_size = module.params['pn_burst_size'] name = module.params['pn_name'] rate_limit = module.params['pn_rate_limit'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) if command == 'cpu-mgmt-class-modify': cli += ' %s name %s ' % (command, name) cli += ' burst-size %s rate-limit %s' % (burst_size, rate_limit) run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(update='igmp-snooping-modify') module = AnsibleModule(argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_enable=dict(required=False, type='bool'), pn_query_interval=dict(required=False, type='str'), pn_igmpv2_vlans=dict(required=False, type='str'), pn_igmpv3_vlans=dict(required=False, type='str'), pn_enable_vlans=dict(required=False, type='str'), pn_vxlan=dict(required=False, type='bool'), pn_query_max_response_time=dict(required=False, type='str'), pn_scope=dict(required=False, type='str', choices=['local', 'fabric']), pn_no_snoop_linklocal_vlans=dict(required=False, type='str'), pn_snoop_linklocal_vlans=dict(required=False, type='str'), ), required_one_of=[[ 'pn_enable', 'pn_query_interval', 'pn_igmpv2_vlans', 'pn_igmpv3_vlans', 'pn_enable_vlans', 'pn_vxlan', 'pn_query_max_response_time', 'pn_scope', 'pn_no_snoop_linklocal_vlans', 'pn_snoop_linklocal_vlans' ]]) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] enable = module.params['pn_enable'] query_interval = module.params['pn_query_interval'] igmpv2_vlans = module.params['pn_igmpv2_vlans'] igmpv3_vlans = module.params['pn_igmpv3_vlans'] enable_vlans = module.params['pn_enable_vlans'] vxlan = module.params['pn_vxlan'] query_max_response_time = module.params['pn_query_max_response_time'] scope = module.params['pn_scope'] no_snoop_linklocal_vlans = module.params['pn_no_snoop_linklocal_vlans'] snoop_linklocal_vlans = module.params['pn_snoop_linklocal_vlans'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) if command == 'igmp-snooping-modify': cli += ' %s ' % command cli += booleanArgs(enable, 'enable', 'disable') cli += booleanArgs(vxlan, 'vxlan', 'no-vxlan') if query_interval: cli += ' query-interval ' + query_interval if igmpv2_vlans: cli += ' igmpv2-vlans ' + igmpv2_vlans if igmpv3_vlans: cli += ' igmpv3-vlans ' + igmpv3_vlans if enable_vlans: cli += ' enable-vlans ' + enable_vlans if query_max_response_time: cli += ' query-max-response-time ' + query_max_response_time if scope: cli += ' scope ' + scope if no_snoop_linklocal_vlans: cli += ' no-snoop-linklocal-vlans ' + no_snoop_linklocal_vlans if snoop_linklocal_vlans: cli += ' snoop-linklocal-vlans ' + snoop_linklocal_vlans run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(update='stp-modify') module = AnsibleModule(argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_hello_time=dict(required=False, type='str', default='2'), pn_enable=dict(required=False, type='bool'), pn_root_guard_wait_time=dict(required=False, type='str', default='20'), pn_bpdus_bridge_ports=dict(required=False, type='bool'), pn_mst_max_hops=dict(required=False, type='str', default='20'), pn_bridge_id=dict(required=False, type='str'), pn_max_age=dict(required=False, type='str', default='20'), pn_stp_mode=dict(required=False, type='str', choices=['rstp', 'mstp']), pn_mst_config_name=dict(required=False, type='str'), pn_forwarding_delay=dict(required=False, type='str', default='15'), pn_bridge_priority=dict(required=False, type='str', default='32768'), ), required_one_of=[[ 'pn_enable', 'pn_hello_time', 'pn_root_guard_wait_time', 'pn_bpdus_bridge_ports', 'pn_mst_max_hops', 'pn_bridge_id', 'pn_max_age', 'pn_stp_mode', 'pn_mst_config_name', 'pn_forwarding_delay', 'pn_bridge_priority' ]]) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] hello_time = module.params['pn_hello_time'] enable = module.params['pn_enable'] root_guard_wait_time = module.params['pn_root_guard_wait_time'] bpdus_bridge_ports = module.params['pn_bpdus_bridge_ports'] mst_max_hops = module.params['pn_mst_max_hops'] bridge_id = module.params['pn_bridge_id'] max_age = module.params['pn_max_age'] stp_mode = module.params['pn_stp_mode'] mst_config_name = module.params['pn_mst_config_name'] forwarding_delay = module.params['pn_forwarding_delay'] bridge_priority = module.params['pn_bridge_priority'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) if command == 'stp-modify': cli += ' %s ' % command if hello_time: cli += ' hello-time ' + hello_time if root_guard_wait_time: cli += ' root-guard-wait-time ' + root_guard_wait_time if mst_max_hops: cli += ' mst-max-hops ' + mst_max_hops if bridge_id: cli += ' bridge-id ' + bridge_id if max_age: cli += ' max-age ' + max_age if stp_mode: cli += ' stp-mode ' + stp_mode if mst_config_name: cli += ' mst-config-name ' + mst_config_name if forwarding_delay: cli += ' forwarding-delay ' + forwarding_delay if bridge_priority: cli += ' bridge-priority ' + bridge_priority cli += booleanArgs(enable, 'enable', 'disable') cli += booleanArgs(bpdus_bridge_ports, 'bpdus-bridge-ports', 'bpdus-all-ports') run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict( update='fabric-local-modify' ) argument_spec = dict( pn_cliswitch=dict(required=True, type='str'), state=dict(required=False, type='str', choices=state_map.keys(), default='update'), pn_fabric_network=dict(required=False, type='str', choices=['mgmt', 'in-band', 'vmgmt'], default='mgmt'), pn_vlan=dict(required=False, type='str'), pn_control_network=dict(required=False, type='str', choices=['in-band', 'mgmt', 'vmgmt']), pn_fabric_advertisement_network=dict(required=False, type='str', choices=['inband-mgmt', 'inband-only', 'inband-vmgmt', 'mgmt-only']), ) module = AnsibleModule( argument_spec=argument_spec, required_one_of=[['pn_fabric_network', 'pn_vlan', 'pn_control_network', 'pn_fabric_advertisement_network']], ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] fabric_network = module.params['pn_fabric_network'] vlan = module.params['pn_vlan'] control_network = module.params['pn_control_network'] fabric_adv_network = module.params['pn_fabric_advertisement_network'] command = state_map[state] if vlan: if int(vlan) < 1 or int(vlan) > 4092: module.fail_json( failed=True, msg='Valid vlan range is 1 to 4092' ) cli = pn_cli(module, cliswitch) cli += ' vlan-show format id no-show-headers' out = run_commands(module, cli)[1].split() if vlan in out and vlan != '1': module.fail_json( failed=True, msg='vlan %s is already in used. Specify unused vlan' % vlan ) # Building the CLI command string cli = pn_cli(module, cliswitch) if command == 'fabric-local-modify': cli += ' %s ' % command if fabric_network: cli += ' fabric-network ' + fabric_network if vlan: cli += ' vlan ' + vlan if control_network: cli += ' control-network ' + control_network if fabric_adv_network: cli += ' fabric-advertisement-network ' + fabric_adv_network run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(present='vrouter-interface-ip-add', absent='vrouter-interface-ip-remove') module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_bd=dict(required=False, type='str'), pn_netmask=dict(required=False, type='str'), pn_vnet=dict(required=False, type='str'), pn_ip=dict(required=False, type='str'), pn_nic=dict(required=False, type='str'), pn_vrouter_name=dict(required=False, type='str'), ), required_if=([ "state", "present", ["pn_vrouter_name", "pn_nic", "pn_ip", "pn_netmask"] ], ["state", "absent", ["pn_vrouter_name", "pn_nic", "pn_ip"]]), ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] bd = module.params['pn_bd'] netmask = module.params['pn_netmask'] vnet = module.params['pn_vnet'] ip = module.params['pn_ip'] nic = module.params['pn_nic'] vrouter_name = module.params['pn_vrouter_name'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) VROUTER_EXISTS, INTERFACE_EXISTS, NIC_EXISTS = check_cli(module, cli) if VROUTER_EXISTS is False: module.fail_json(failed=True, msg='vRouter %s does not exist' % vrouter_name) if NIC_EXISTS is False: module.fail_json(failed=True, msg='vRouter with nic %s does not exist' % nic) cli += ' %s vrouter-name %s ' % (command, vrouter_name) if command == 'vrouter-interface-ip-add': if INTERFACE_EXISTS is True: module.exit_json(skipped=True, msg='vRouter with interface ip %s exist' % ip) cli += ' nic %s ip %s ' % (nic, ip) if bd: cli += ' bd ' + bd if netmask: cli += ' netmask ' + netmask if vnet: cli += ' vnet ' + vnet if command == 'vrouter-interface-ip-remove': if INTERFACE_EXISTS is False: module.exit_json( skipped=True, msg='vRouter with interface ip %s does not exist' % ip) if nic: cli += ' nic %s ' % nic if ip: cli += ' ip %s ' % ip.split('/')[0] run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(present='snmp-vacm-create', absent='snmp-vacm-delete', update='snmp-vacm-modify') module = AnsibleModule(argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_oid_restrict=dict(required=False, type='str'), pn_priv=dict(required=False, type='bool'), pn_auth=dict(required=False, type='bool'), pn_user_type=dict(required=False, type='str', choices=['rouser', 'rwuser']), pn_user_name=dict(required=False, type='str'), ), required_if=(["state", "present", ["pn_user_name"]], ["state", "absent", ["pn_user_name"]], ["state", "update", ["pn_user_name"]])) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] oid_restrict = module.params['pn_oid_restrict'] priv = module.params['pn_priv'] auth = module.params['pn_auth'] user_type = module.params['pn_user_type'] user_name = module.params['pn_user_name'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) USER_EXISTS = check_cli(module, cli) cli += ' %s user-name %s ' % (command, user_name) if command == 'snmp-vacm-modify': if USER_EXISTS is None: module.fail_json(failed=True, msg='snmp user with name %s does not exists' % user_name) if USER_EXISTS is False: module.fail_json(failed=True, msg='snmp vacm with name %s does not exists' % user_name) if command == 'snmp-vacm-delete': if USER_EXISTS is None: module.fail_json(failed=True, msg='snmp user with name %s does not exists' % user_name) if USER_EXISTS is False: module.exit_json(skipped=True, msg='snmp vacm with name %s does not exist' % user_name) if command == 'snmp-vacm-create': if USER_EXISTS is None: module.fail_json(failed=True, msg='snmp user with name %s does not exists' % user_name) if USER_EXISTS is True: module.exit_json(skipped=True, msg='snmp vacm with name %s already exists' % user_name) if command != 'snmp-vacm-delete': if oid_restrict: cli += ' oid-restrict ' + oid_restrict if user_type: cli += ' user-type ' + user_type cli += booleanArgs(auth, 'auth', 'no-auth') cli += booleanArgs(priv, 'priv', 'no-priv') run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(present='role-create', absent='role-delete', update='role-modify') module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_scope=dict(required=False, type='str', choices=['local', 'fabric']), pn_access=dict(required=False, type='str', choices=['read-only', 'read-write']), pn_shell=dict(required=False, type='bool'), pn_sudo=dict(required=False, type='bool'), pn_running_config=dict(required=False, type='bool'), pn_name=dict(required=False, type='str'), pn_delete_from_users=dict(required=False, type='bool'), ), required_if=( ["state", "present", ["pn_name", "pn_scope"]], ["state", "absent", ["pn_name"]], ["state", "update", ["pn_name"]], ), ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] scope = module.params['pn_scope'] access = module.params['pn_access'] shell = module.params['pn_shell'] sudo = module.params['pn_sudo'] running_config = module.params['pn_running_config'] name = module.params['pn_name'] delete_from_users = module.params['pn_delete_from_users'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) ROLE_EXISTS = check_cli(module, cli) cli += ' %s name %s ' % (command, name) if shell is (False or '') and sudo is True: module.fail_json(failed=True, msg='sudo access requires shell access') if command == 'role-modify': if ROLE_EXISTS is False: module.fail_json(failed=True, msg='Role with name %s does not exist' % name) if command == 'role-delete': if ROLE_EXISTS is False: module.exit_json(skipped=True, msg='Role with name %s does not exist' % name) if command == 'role-create': if ROLE_EXISTS is True: module.exit_json(skipped=True, msg='Role with name %s already exists' % name) if scope: cli += ' scope ' + scope if command != 'role-delete': if access: cli += ' access ' + access cli += booleanArgs(shell, 'shell', 'no-shell') cli += booleanArgs(sudo, 'sudo', 'no-sudo') cli += booleanArgs(running_config, 'running-config', 'no-running-config') if command == 'role-modify': if delete_from_users: cli += ' delete-from-users ' + delete_from_users run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(present='admin-syslog-create', absent='admin-syslog-delete', update='admin-syslog-modify') module = AnsibleModule(argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_scope=dict(required=False, type='str', choices=['local', 'fabric']), pn_host=dict(required=False, type='str'), pn_port=dict(required=False, type='str'), pn_transport=dict(required=False, type='str', choices=['tcp-tls', 'udp'], default='udp'), pn_message_format=dict(required=False, type='str', choices=['structured', 'legacy']), pn_name=dict(required=False, type='str'), ), required_if=([ 'state', 'present', ['pn_name', 'pn_host', 'pn_scope'] ], ['state', 'absent', ['pn_name']], ['state', 'update', ['pn_name']]), required_one_of=[[ 'pn_port', 'pn_message_format', 'pn_host', 'pn_transport', 'pn_scope' ]]) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] scope = module.params['pn_scope'] host = module.params['pn_host'] port = module.params['pn_port'] transport = module.params['pn_transport'] message_format = module.params['pn_message_format'] name = module.params['pn_name'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) SYSLOG_EXISTS = check_cli(module, cli) cli += ' %s name %s ' % (command, name) if command == 'admin-syslog-modify': if SYSLOG_EXISTS is False: module.fail_json(failed=True, msg='admin syslog with name %s does not exist' % name) if command == 'admin-syslog-delete': if SYSLOG_EXISTS is False: module.exit_json(skipped=True, msg='admin syslog with name %s does not exist' % name) if command == 'admin-syslog-create': if SYSLOG_EXISTS is True: module.exit_json( skipped=True, msg='admin syslog user with name %s already exists' % name) if command == 'admin-syslog-create': if scope: cli += ' scope ' + scope if command != 'admin-syslog-delete': if host: cli += ' host ' + host if port: cli += ' port ' + port if transport: cli += ' transport ' + transport if message_format: cli += ' message-format ' + message_format run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(present='vrouter-bgp-add', absent='vrouter-bgp-remove', update='vrouter-bgp-modify') argument_spec = dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=False, type='str', choices=state_map.keys(), default='present'), pn_neighbor=dict(required=True, type='str'), pn_vrouter_name=dict(required=True, type='str'), pn_send_community=dict(required=False, type='bool'), pn_weight=dict(required=False, type='str'), pn_multi_protocol=dict(required=False, type='str', choices=['ipv4-unicast', 'ipv6-unicast']), pn_prefix_list_in=dict(required=False, type='str'), pn_route_reflector_client=dict(required=False, type='bool'), pn_default_originate=dict(required=False, type='bool'), pn_neighbor_holdtime=dict(required=False, type='str'), pn_connect_retry_interval=dict(required=False, type='str'), pn_advertisement_interval=dict(required=False, type='str'), pn_route_map_out=dict(required=False, type='str'), pn_update_source=dict(required=False, type='str'), pn_bfd=dict(required=False, type='bool', default=False), pn_next_hop_self=dict(required=False, type='bool'), pn_allowas_in=dict(required=False, type='bool'), pn_neighbor_keepalive_interval=dict(required=False, type='str'), pn_max_prefix=dict(required=False, type='str'), pn_bfd_multihop=dict(required=False, type='bool'), pn_interface=dict(required=False, type='str'), pn_password=dict(required=False, type='str', no_log=True), pn_route_map_in=dict(required=False, type='str'), pn_soft_reconfig_inbound=dict(required=False, type='bool'), pn_override_capability=dict(required=False, type='bool'), pn_max_prefix_warn_only=dict(required=False, type='bool'), pn_ebgp_multihop=dict(required=False, type='str'), pn_remote_as=dict(required=False, type='str'), pn_prefix_list_out=dict(required=False, type='str'), pn_no_route_map_out=dict(required=False, type='str'), pn_no_route_map_in=dict(required=False, type='str'), ) module = AnsibleModule( argument_spec=argument_spec, required_if=([ "state", "present", ["pn_vrouter_name", "pn_neighbor", "pn_remote_as"] ], ["state", "absent", ["pn_vrouter_name", "pn_neighbor"]], ["state", "update", ["pn_vrouter_name", "pn_neighbor"]]), required_one_of=[[ 'pn_send_community', 'pn_weight', 'pn_multi_protocol', 'pn_prefix_list_in', 'pn_route_reflector_client', 'pn_default_originate', 'pn_neighbor_holdtime', 'pn_connect_retry_interval', 'pn_advertisement_interval', 'pn_route_map_out', 'pn_update_source', 'pn_bfd', 'pn_next_hop_self', 'pn_allowas_in', 'pn_neighbor_keepalive_interval', 'pn_max_prefix', 'pn_bfd_multihop', 'pn_interface', 'pn_password', 'pn_route_map_in', 'pn_soft_reconfig_inbound', 'pn_override_capability', 'pn_max_prefix_warn_only', 'pn_ebgp_multihop', 'pn_remote_as', 'pn_prefix_list_out', 'pn_no_route_map_out', 'pn_no_route_map_in' ]], ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] neighbor = module.params['pn_neighbor'] vrouter_name = module.params['pn_vrouter_name'] send_community = module.params['pn_send_community'] weight = module.params['pn_weight'] multi_protocol = module.params['pn_multi_protocol'] prefix_list_in = module.params['pn_prefix_list_in'] route_reflector_client = module.params['pn_route_reflector_client'] default_originate = module.params['pn_default_originate'] neighbor_holdtime = module.params['pn_neighbor_holdtime'] connect_retry_interval = module.params['pn_connect_retry_interval'] advertisement_interval = module.params['pn_advertisement_interval'] route_map_out = module.params['pn_route_map_out'] update_source = module.params['pn_update_source'] bfd = module.params['pn_bfd'] next_hop_self = module.params['pn_next_hop_self'] allowas_in = module.params['pn_allowas_in'] neighbor_keepalive_interval = module.params[ 'pn_neighbor_keepalive_interval'] max_prefix = module.params['pn_max_prefix'] bfd_multihop = module.params['pn_bfd_multihop'] interface = module.params['pn_interface'] password = module.params['pn_password'] route_map_in = module.params['pn_route_map_in'] soft_reconfig_inbound = module.params['pn_soft_reconfig_inbound'] override_capability = module.params['pn_override_capability'] max_prefix_warn_only = module.params['pn_max_prefix_warn_only'] ebgp_multihop = module.params['pn_ebgp_multihop'] remote_as = module.params['pn_remote_as'] prefix_list_out = module.params['pn_prefix_list_out'] no_route_map_out = module.params['pn_no_route_map_out'] no_route_map_in = module.params['pn_no_route_map_in'] command = state_map[state] if weight and weight != 'none': if int(weight) < 1 or int(weight) > 65535: module.fail_json(failed=True, msg='Valid weight range is 1 to 65535') # Building the CLI command string cli = pn_cli(module, cliswitch) VROUTER_EXISTS, NEIGHBOR_EXISTS = check_cli(module, cli) if state: if VROUTER_EXISTS is False: module.exit_json(skipped=True, msg='vRouter %s does not exist' % vrouter_name) if command == 'vrouter-bgp-remove' or command == 'vrouter-bgp-modify': if NEIGHBOR_EXISTS is False: module.exit_json( skipped=True, msg='BGP neighbor with IP %s does not exist on %s' % (neighbor, vrouter_name)) if command == 'vrouter-bgp-add': if NEIGHBOR_EXISTS is True: module.exit_json( skipped=True, msg='BGP neighbor with IP %s already exists on %s' % (neighbor, vrouter_name)) cli += ' %s vrouter-name %s neighbor %s ' % (command, vrouter_name, neighbor) if command == 'vrouter-bgp-add' or command == 'vrouter-bgp-modify': if weight: cli += ' weight ' + weight if multi_protocol: cli += ' multi-protocol ' + multi_protocol if prefix_list_in: cli += ' prefix-list-in ' + prefix_list_in if neighbor_holdtime: is_valid(module, 'neighbor holdtime', neighbor_holdtime, '0', '65535') cli += ' neighbor-holdtime ' + neighbor_holdtime if connect_retry_interval: is_valid(module, 'connect retry interval', connect_retry_interval, '0', '65535') cli += ' connect-retry-interval ' + connect_retry_interval if advertisement_interval: is_valid(module, 'advertisement interval', advertisement_interval, '0', '65535') cli += ' advertisement-interval ' + advertisement_interval if route_map_out: cli += ' route-map-out ' + route_map_out if update_source: cli += ' update-source ' + update_source if neighbor_keepalive_interval: is_valid(module, 'neighbor keepalive interval', neighbor_keepalive_interval, '0', '65535') cli += ' neighbor-keepalive-interval ' + neighbor_keepalive_interval if max_prefix: cli += ' max-prefix ' + max_prefix if interface: cli += ' interface ' + interface if password: cli += ' password ' + password if route_map_in: cli += ' route-map-in ' + route_map_in if ebgp_multihop: is_valid(module, 'ebgp_multihop', ebgp_multihop, '1', '255') cli += ' ebgp-multihop ' + ebgp_multihop if remote_as: cli += ' remote-as ' + remote_as if prefix_list_out: cli += ' prefix-list-out ' + prefix_list_out cli += booleanArgs(send_community, 'send-community', 'no-send-community') cli += booleanArgs(route_reflector_client, 'route-reflector-client', 'no-route-reflector-client') cli += booleanArgs(default_originate, 'default-originate', 'no-default-originate') cli += booleanArgs(bfd, 'bfd', 'no-bfd') cli += booleanArgs(next_hop_self, 'next-hop-self', 'no-next-hop-self') cli += booleanArgs(allowas_in, 'allowas-in', 'no-allowas-in') cli += booleanArgs(bfd_multihop, 'bfd-multihop', 'no-bfd-multihop') cli += booleanArgs(soft_reconfig_inbound, 'soft-reconfig-inbound', 'no-soft-reconfig-inbound') cli += booleanArgs(override_capability, 'override-capability', 'no-override-capability') cli += booleanArgs(max_prefix_warn_only, 'max-prefix-warn-only', 'no-max-prefix-warn-only') if command == 'vrouter-bgp-modify': if no_route_map_out: cli += ' no-route-map-out ' + no_route_map_out if no_route_map_in: cli += ' no-route-map-in ' + no_route_map_in run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict( present='cpu-class-create', absent='cpu-class-delete', update='cpu-class-modify' ) module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_scope=dict(required=False, type='str', choices=['local', 'fabric']), pn_hog_protect=dict(required=False, type='str', choices=['disable', 'enable', 'enable-and-drop']), pn_rate_limit=dict(required=False, type='str'), pn_name=dict(required=False, type='str'), ), required_if=( ['state', 'present', ['pn_name', 'pn_scope', 'pn_rate_limit']], ['state', 'absent', ['pn_name']], ['state', 'update', ['pn_name']], ) ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] scope = module.params['pn_scope'] hog_protect = module.params['pn_hog_protect'] rate_limit = module.params['pn_rate_limit'] name = module.params['pn_name'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) NAME_EXISTS = check_cli(module, cli) cli += ' %s name %s ' % (command, name) if command == 'cpu-class-modify': if NAME_EXISTS is False: module.fail_json( failed=True, msg='cpu class with name %s does not exist' % name ) if command == 'cpu-class-delete': if NAME_EXISTS is False: module.exit_json( skipped=True, msg='cpu class with name %s does not exist' % name ) if command == 'cpu-class-create': if NAME_EXISTS is True: module.exit_json( skipped=True, msg='cpu class with name %s already exists' % name ) if scope: cli += ' scope %s ' % scope if command != 'cpu-class-delete': if hog_protect: cli += ' hog-protect %s ' % hog_protect if rate_limit: cli += ' rate-limit %s ' % rate_limit run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(present='vrouter-loopback-interface-add', absent='vrouter-loopback-interface-remove') argument_spec = dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=False, type='str', choices=state_map.keys(), default='present'), pn_ip=dict(required=True, type='str'), pn_index=dict(required=False, type='str'), pn_vrouter_name=dict(required=True, type='str'), ) module = AnsibleModule( argument_spec=argument_spec, required_if=(["state", "present", ["pn_vrouter_name", "pn_ip"]], [ "state", "absent", ["pn_vrouter_name", "pn_ip", "pn_index"] ]), ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] ip = module.params['pn_ip'] index = module.params['pn_index'] vrouter_name = module.params['pn_vrouter_name'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) VROUTER_EXISTS, INTERFACE_EXISTS = check_cli(module, cli) cli += ' %s vrouter-name %s ' % (command, vrouter_name) if index and (int(index) < 1 or int(index) > 255): module.fail_json(failed=True, msg='index should be in range 1 to 255') if index and state == 'present': show = 'vrouter-loopback-interface-show format index parsable-delim ,' out = run_commands(module, show)[1] if out: out = out.split() for res in out: res = res.strip().split(',') if index in res: module.fail_json(failed=True, msg='index with value %s exist' % index) if command == 'vrouter-loopback-interface-add': if VROUTER_EXISTS is False: module.fail_json(failed=True, msg='vRouter %s does not exist' % vrouter_name) if INTERFACE_EXISTS is True: module.exit_json(skipped=True, msg='vRouter with loopback ip %s exist' % ip) if ip: cli += ' ip ' + ip if index: cli += ' index ' + index if command == 'vrouter-loopback-interface-remove': if VROUTER_EXISTS is False: module.fail_json(failed=True, msg='vRouter %s does not exist' % vrouter_name) if INTERFACE_EXISTS is False: module.exit_json(skipped=True, msg='vRouter with loopback ip %s doesnt exist' % ip) if index: cli += ' index ' + index run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(update='stp-port-modify') module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_priority=dict(required=False, type='str', default='128'), pn_cost=dict(required=False, type='str', default='2000'), pn_root_guard=dict(required=False, type='bool'), pn_filter=dict(required=False, type='bool'), pn_edge=dict(required=False, type='bool'), pn_bpdu_guard=dict(required=False, type='bool'), pn_port=dict(required=False, type='str'), pn_block=dict(required=False, type='bool'), ), required_if=(["state", "update", ["pn_port"]], ), required_one_of=([ 'pn_cost', 'pn_root_guard', 'pn_filter', 'pn_edge', 'pn_bpdu_guard', 'pn_block' ], ), ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] priority = module.params['pn_priority'] cost = module.params['pn_cost'] root_guard = module.params['pn_root_guard'] pn_filter = module.params['pn_filter'] edge = module.params['pn_edge'] bpdu_guard = module.params['pn_bpdu_guard'] port = module.params['pn_port'] block = module.params['pn_block'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) if command == 'stp-port-modify': cli += ' %s ' % command if priority and (int(priority) % 16 == 0 and int(priority) < 240): cli += ' priority ' + priority else: module.fail_json( failed=True, msg= 'Priority must be increment of 16 and should be less that 240') if cost and (int(cost) < 200000000): cli += ' cost ' + cost else: module.fail_json(failed=True, msg='cost must be between 1 and 200000000') if port: cli += ' port ' + port cli += booleanArgs(root_guard, 'root-guard', 'no-root-guard') cli += booleanArgs(pn_filter, 'filter', 'no-filter') cli += booleanArgs(edge, 'edge', 'no-edge') cli += booleanArgs(bpdu_guard, 'bpdu-guard', 'no-bpdu-guard') cli += booleanArgs(block, 'block', 'no-block') run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict( present='log-audit-exception-create', absent='log-audit-exception-delete', ) argument_spec = dict( pn_cliswitch=dict(required=False, type='str'), pn_pattern=dict(required=True, type='str'), state=dict(required=False, type='str', choices=state_map.keys(), default='present'), pn_access=dict(required=True, type='str', choices=['any', 'read-only', 'read-write']), pn_audit_type=dict(required=True, type='str', choices=['cli', 'shell', 'vtysh']), pn_scope=dict(required=False, type='str', choices=['local', 'fabric']), ) module = AnsibleModule( argument_spec=argument_spec, required_if=(["state", "present", ["pn_scope"]], ), ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] access = module.params['pn_access'] audit_type = module.params['pn_audit_type'] pattern = module.params['pn_pattern'] scope = module.params['pn_scope'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) audit_log_exists = check_cli(module, cli) cli += ' %s %s pattern %s %s' % (command, audit_type, pattern, access) if state == 'absent': if audit_log_exists is False: module.exit_json( skipped=True, msg='This audit log exception entry does not exist') run_cli(module, cli, state_map) elif state == 'present': if audit_log_exists is True: module.exit_json( skipped=True, msg='This audit log exception entry already exists') cli += ' scope %s ' % scope run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(update='port-config-modify') module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=['update']), pn_intf=dict(required=False, type='str'), pn_crc_check_enable=dict(required=False, type='bool'), pn_dscp_map=dict(required=False, type='str'), pn_autoneg=dict(required=False, type='bool'), pn_speed=dict(required=False, type='str', choices=[ 'disable', '10m', '100m', '1g', '2.5g', '10g', '25g', '40g', '50g', '100g' ]), pn_port=dict(required=False, type='str'), pn_vxlan_termination=dict(required=False, type='bool'), pn_pause=dict(required=False, type='bool'), pn_loopback=dict(required=False, type='bool'), pn_loop_vlans=dict(required=False, type='str'), pn_routing=dict(required=False, type='bool'), pn_edge_switch=dict(required=False, type='bool'), pn_enable=dict(required=False, type='bool'), pn_description=dict(required=False, type='str'), pn_host_enable=dict(required=False, type='bool'), pn_allowed_tpid=dict(required=False, type='str', choices=['vlan', 'q-in-q', 'q-in-q-old']), pn_mirror_only=dict(required=False, type='bool'), pn_reflect=dict(required=False, type='bool'), pn_jumbo=dict(required=False, type='bool'), pn_egress_rate_limit=dict(required=False, type='str'), pn_eth_mode=dict( required=False, type='str', choices=['1000base-x', 'sgmii', 'disabled', 'GMII']), pn_fabric_guard=dict(required=False, type='bool'), pn_local_switching=dict(required=False, type='bool'), pn_lacp_priority=dict(required=False, type='str'), pn_send_port=dict(required=False, type='str'), pn_port_mac_address=dict(required=False, type='str'), pn_defer_bringup=dict(required=False, type='bool'), ), required_if=(['state', 'update', ['pn_port']], ), required_one_of=[[ 'pn_intf', 'pn_crc_check_enable', 'pn_dscp_map', 'pn_speed', 'pn_autoneg', 'pn_vxlan_termination', 'pn_pause', 'pn_fec', 'pn_loopback', 'pn_loop_vlans', 'pn_routing', 'pn_edge_switch', 'pn_enable', 'pn_description', 'pn_host_enable', 'pn_allowed_tpid', 'pn_mirror_only', 'pn_reflect', 'pn_jumbo', 'pn_egress_rate_limit', 'pn_eth_mode', 'pn_fabric_guard', 'pn_local_switching', 'pn_lacp_priority', 'pn_send_port', 'pn_port_mac_address', 'pn_defer_bringup' ]], ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] intf = module.params['pn_intf'] crc_check_enable = module.params['pn_crc_check_enable'] dscp_map = module.params['pn_dscp_map'] autoneg = module.params['pn_autoneg'] speed = module.params['pn_speed'] port = module.params['pn_port'] vxlan_termination = module.params['pn_vxlan_termination'] pause = module.params['pn_pause'] loopback = module.params['pn_loopback'] loop_vlans = module.params['pn_loop_vlans'] routing = module.params['pn_routing'] edge_switch = module.params['pn_edge_switch'] enable = module.params['pn_enable'] description = module.params['pn_description'] host_enable = module.params['pn_host_enable'] allowed_tpid = module.params['pn_allowed_tpid'] mirror_only = module.params['pn_mirror_only'] reflect = module.params['pn_reflect'] jumbo = module.params['pn_jumbo'] egress_rate_limit = module.params['pn_egress_rate_limit'] eth_mode = module.params['pn_eth_mode'] fabric_guard = module.params['pn_fabric_guard'] local_switching = module.params['pn_local_switching'] lacp_priority = module.params['pn_lacp_priority'] send_port = module.params['pn_send_port'] port_mac_address = module.params['pn_port_mac_address'] defer_bringup = module.params['pn_defer_bringup'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) if dscp_map: NAME_EXISTS = check_cli(module, cli) if command == 'port-config-modify': cli += ' %s ' % command if dscp_map: if NAME_EXISTS is False: module.fail_json( failed=True, msg='Create dscp map with name %s before updating' % dscp_map) cli += ' dscp-map ' + dscp_map if intf: cli += ' intf ' + intf if speed: cli += ' speed ' + speed if port: cli += ' port ' + port if allowed_tpid: cli += ' allowed-tpid ' + allowed_tpid if egress_rate_limit: cli += ' egress-rate-limit ' + egress_rate_limit if eth_mode: cli += ' eth-mode ' + eth_mode if lacp_priority: cli += ' lacp-priority ' + lacp_priority if send_port: cli += ' send-port ' + send_port if port_mac_address: cli += ' port-mac-address ' + port_mac_address cli += booleanArgs(crc_check_enable, 'crc-check-enable', 'crc-check-disable') cli += booleanArgs(autoneg, 'autoneg', 'no-autoneg') cli += booleanArgs(vxlan_termination, 'vxlan-termination', 'no-vxlan-termination') cli += booleanArgs(pause, 'pause', 'no-pause') cli += booleanArgs(loopback, 'loopback', 'no-loopback') cli += booleanArgs(routing, 'routing', 'no-routing') cli += booleanArgs(edge_switch, 'edge-switch', 'no-edge-switch') cli += booleanArgs(enable, 'enable', 'disable') cli += booleanArgs(host_enable, 'host-enable', 'host-disable') cli += booleanArgs(mirror_only, 'mirror-only', 'no-mirror-receive-only') cli += booleanArgs(reflect, 'reflect', 'no-reflect') cli += booleanArgs(jumbo, 'jumbo', 'no-jumbo') cli += booleanArgs(fabric_guard, 'fabric-guard', 'no-fabric-guard') cli += booleanArgs(local_switching, 'local-switching', 'no-local-switching') cli += booleanArgs(defer_bringup, 'defer-bringup', 'no-defer-bringup') run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(update='port-cos-rate-setting-modify') module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_cos1_rate=dict(required=False, type='str'), pn_cos5_rate=dict(required=False, type='str'), pn_cos2_rate=dict(required=False, type='str'), pn_cos0_rate=dict(required=False, type='str'), pn_cos6_rate=dict(required=False, type='str'), pn_cos3_rate=dict(required=False, type='str'), pn_cos4_rate=dict(required=False, type='str'), pn_cos7_rate=dict(required=False, type='str'), pn_port=dict(required=False, type='str', choices=['control-port', 'data-port', 'span-ports']), ), required_if=(['state', 'update', ['pn_port']], ), required_one_of=[[ 'pn_cos0_rate', 'pn_cos1_rate', 'pn_cos2_rate', 'pn_cos3_rate', 'pn_cos4_rate', 'pn_cos5_rate', 'pn_cos6_rate', 'pn_cos7_rate' ]], ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] cos1_rate = module.params['pn_cos1_rate'] cos5_rate = module.params['pn_cos5_rate'] cos2_rate = module.params['pn_cos2_rate'] cos0_rate = module.params['pn_cos0_rate'] cos6_rate = module.params['pn_cos6_rate'] cos3_rate = module.params['pn_cos3_rate'] cos4_rate = module.params['pn_cos4_rate'] cos7_rate = module.params['pn_cos7_rate'] port = module.params['pn_port'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) if command == 'port-cos-rate-setting-modify': cli += ' %s ' % command if cos1_rate: cli += ' cos1-rate ' + cos1_rate if cos5_rate: cli += ' cos5-rate ' + cos5_rate if cos2_rate: cli += ' cos2-rate ' + cos2_rate if cos0_rate: cli += ' cos0-rate ' + cos0_rate if cos6_rate: cli += ' cos6-rate ' + cos6_rate if cos3_rate: cli += ' cos3-rate ' + cos3_rate if cos4_rate: cli += ' cos4-rate ' + cos4_rate if cos7_rate: cli += ' cos7-rate ' + cos7_rate if port: cli += ' port ' + port run_cli(module, cli, state_map)