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='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-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='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( 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( present='access-list-create', absent='access-list-delete', ) module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_name=dict(required=False, type='str'), pn_scope=dict(required=False, type='str', choices=['local', 'fabric']), ), required_if=( ["state", "present", ["pn_name", "pn_scope"]], ["state", "absent", ["pn_name"]], ), ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] list_name = module.params['pn_name'] scope = module.params['pn_scope'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) ACC_LIST_EXISTS = check_cli(module, cli) cli += ' %s name %s ' % (command, list_name) if command == 'access-list-delete': if ACC_LIST_EXISTS is False: module.exit_json( skipped=True, msg='access-list with name %s does not exist' % list_name ) else: if command == 'access-list-create': if ACC_LIST_EXISTS is True: module.exit_json( skipped=True, msg='access list with name %s already exists' % list_name ) cli += ' scope %s ' % scope 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(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='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-vlan-add', absent='ipv6security-raguard-vlan-remove' ) module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=False, type='str', choices=state_map.keys(), default='present'), pn_vlans=dict(required=True, type='str'), pn_name=dict(required=True, type='str'), ) ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] vlans = module.params['pn_vlans'] 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: if NAME_EXISTS is False: module.exit_json( skipped=True, msg='ipv6security raguard with name %s does not exist' % name ) if vlans: cli += ' vlans ' + vlans 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='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(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(update='connection-stats-settings-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_connection_backup_enable=dict(required=False, type='bool'), pn_client_server_stats_max_memory=dict(required=False, type='str'), pn_connection_stats_log_disk_space=dict(required=False, type='str'), pn_client_server_stats_log_enable=dict(required=False, type='bool'), pn_service_stat_max_memory=dict(required=False, type='str'), pn_connection_stats_log_interval=dict(required=False, type='str'), pn_fabric_connection_backup_interval=dict(required=False, type='str'), pn_connection_backup_interval=dict(required=False, type='str'), pn_connection_stats_log_enable=dict(required=False, type='bool'), pn_fabric_connection_max_memory=dict(required=False, type='str'), pn_fabric_connection_backup_enable=dict(required=False, type='bool'), pn_client_server_stats_log_disk_space=dict(required=False, type='str'), pn_connection_max_memory=dict(required=False, type='str'), pn_connection_stats_max_memory=dict(required=False, type='str'), pn_client_server_stats_log_interval=dict(required=False, type='str'), ), required_one_of=[[ 'pn_enable', 'pn_connection_backup_enable', 'pn_client_server_stats_max_memory', 'pn_connection_stats_log_disk_space', 'pn_client_server_stats_log_enable', 'pn_service_stat_max_memory', 'pn_connection_stats_log_interval', 'pn_connection_backup_interval', 'pn_connection_stats_log_enable', 'pn_fabric_connection_max_memory', 'pn_fabric_connection_backup_enable', 'pn_client_server_stats_log_disk_space', 'pn_connection_max_memory', 'pn_connection_stats_max_memory', 'pn_client_server_stats_log_interval' ]]) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] enable = module.params['pn_enable'] connection_backup_enable = module.params['pn_connection_backup_enable'] client_server_stats_max_memory = module.params[ 'pn_client_server_stats_max_memory'] connection_stats_log_disk_space = module.params[ 'pn_connection_stats_log_disk_space'] client_server_stats_log_enable = module.params[ 'pn_client_server_stats_log_enable'] service_stat_max_memory = module.params['pn_service_stat_max_memory'] connection_stats_log_interval = module.params[ 'pn_connection_stats_log_interval'] fabric_connection_backup_interval = module.params[ 'pn_fabric_connection_backup_interval'] connection_backup_interval = module.params['pn_connection_backup_interval'] connection_stats_log_enable = module.params[ 'pn_connection_stats_log_enable'] fabric_connection_max_memory = module.params[ 'pn_fabric_connection_max_memory'] fabric_connection_backup_enable = module.params[ 'pn_fabric_connection_backup_enable'] client_server_stats_log_disk_space = module.params[ 'pn_client_server_stats_log_disk_space'] connection_max_memory = module.params['pn_connection_max_memory'] connection_stats_max_memory = module.params[ 'pn_connection_stats_max_memory'] client_server_stats_log_interval = module.params[ 'pn_client_server_stats_log_interval'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) if command == 'connection-stats-settings-modify': cli += ' %s ' % command cli += booleanArgs(enable, 'enable', 'disable') cli += booleanArgs(connection_backup_enable, 'connection-backup-enable', 'connection-backup-disable') cli += booleanArgs(client_server_stats_log_enable, 'client-server-stats-log-enable', 'client-server-stats-log-disable') cli += booleanArgs(connection_stats_log_enable, 'connection-stats-log-enable', 'connection-stats-log-disable') cli += booleanArgs(fabric_connection_backup_enable, 'fabric-connection-backup-enable', 'fabric-connection-backup-disable') if client_server_stats_max_memory: cli += ' client-server-stats-max-memory ' + client_server_stats_max_memory if connection_stats_log_disk_space: cli += ' connection-stats-log-disk-space ' + connection_stats_log_disk_space if service_stat_max_memory: cli += ' service-stat-max-memory ' + service_stat_max_memory if connection_stats_log_interval: cli += ' connection-stats-log-interval ' + connection_stats_log_interval if fabric_connection_backup_interval: cli += ' fabric-connection-backup-interval ' + fabric_connection_backup_interval if connection_backup_interval: cli += ' connection-backup-interval ' + connection_backup_interval if fabric_connection_max_memory: cli += ' fabric-connection-max-memory ' + fabric_connection_max_memory if client_server_stats_log_disk_space: cli += ' client-server-stats-log-disk-space ' + client_server_stats_log_disk_space if connection_max_memory: cli += ' connection-max-memory ' + connection_max_memory if connection_stats_max_memory: cli += ' connection-stats-max-memory ' + connection_stats_max_memory if client_server_stats_log_interval: cli += ' client-server-stats-log-interval ' + client_server_stats_log_interval run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(present='vtep-create', absent='vtep-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=False, type='str'), pn_ip=dict(required=False, type='str'), pn_vrouter_name=dict(required=False, type='str'), pn_virtual_ip=dict(required=False, type='str'), pn_location=dict(required=False, type='str'), pn_switch_in_cluster=dict(required=False, type='bool', default='True')) module = AnsibleModule( argument_spec=argument_spec, required_if=( [ "state", "present", ["pn_name", "pn_ip", "pn_vrouter_name", "pn_location"] ], ["state", "absent", ["pn_name"]], ), ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] name = module.params['pn_name'] ip = module.params['pn_ip'] vrouter_name = module.params['pn_vrouter_name'] virtual_ip = module.params['pn_virtual_ip'] location = module.params['pn_location'] switch_in_cluster = module.params['pn_switch_in_cluster'] if switch_in_cluster and not virtual_ip and state == 'present': module.exit_json( failed=True, msg='virtual ip is required when switch is in cluster') 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 == 'vtep-delete': if NAME_EXISTS is False: module.exit_json(skipped=True, msg='vtep with name %s does not exist' % name) if command == 'vtep-create': if NAME_EXISTS is True: module.exit_json(skipped=True, msg='vtpe with name %s already exists' % name) cli += 'vrouter-name %s ' % vrouter_name cli += 'ip %s ' % ip cli += 'location %s ' % location if virtual_ip: cli += 'virtual-ip %s ' % virtual_ip 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(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='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(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(present='vrouter-ospf-add', absent='vrouter-ospf-remove') argument_spec = dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=False, type='str', choices=state_map.keys(), default='present'), pn_netmask=dict(required=False, type='str'), pn_ospf_area=dict(required=False, type='str'), pn_network=dict(required=True, type='str'), pn_vrouter_name=dict(required=True, type='str'), ) module = AnsibleModule( argument_spec=argument_spec, required_if=( [ "state", "present", [ 'pn_vrouter_name', 'pn_network', 'pn_netmask', 'pn_ospf_area' ] ], ["state", "absent", ['pn_vrouter_name', 'pn_network']], ), ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] netmask = module.params['pn_netmask'] ospf_area = module.params['pn_ospf_area'] 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) VROUTER_EXISTS, NETWORK_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-ospf-remove': if NETWORK_EXISTS is False: module.exit_json(skipped=True, msg='OSPF with network %s dose not exists' % network) cli += ' %s vrouter-name %s network %s' % (command, vrouter_name, network) if command == 'vrouter-ospf-add': if NETWORK_EXISTS is True: module.exit_json(skipped=True, msg='OSPF with network %s already exists' % network) if netmask: cli += ' netmask ' + netmask if ospf_area: cli += ' ospf-area ' + ospf_area run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict( present='user-create', absent='user-delete', update='user-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_initial_role=dict(required=False, type='str'), pn_password=dict(required=False, type='str', no_log=True), pn_name=dict(required=False, type='str'), ), required_if=( ["state", "present", ["pn_name", "pn_scope"]], ["state", "absent", ["pn_name"]], ["state", "update", ["pn_name", "pn_password"]] ), ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] scope = module.params['pn_scope'] initial_role = module.params['pn_initial_role'] password = module.params['pn_password'] 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 == 'user-modify': if USER_EXISTS is False: module.fail_json( failed=True, msg='User with name %s does not exist' % name ) if initial_role or scope: module.fail_json( failed=True, msg='Only password can be modified' ) if command == 'user-delete': if USER_EXISTS is False: module.exit_json( skipped=True, msg='user with name %s does not exist' % name ) if command == 'user-create': if USER_EXISTS is True: module.exit_json( skipped=True, msg='User with name %s already exists' % name ) if scope: cli += ' scope ' + scope if initial_role: cli += ' initial-role ' + initial_role if command != 'user-delete': if password: cli += ' password ' + password 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( 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-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(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='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( update='switch-setup-modify' ) module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=['update']), pn_force=dict(required=False, type='bool'), pn_dns_ip=dict(required=False, type='str'), pn_mgmt_netmask=dict(required=False, type='str'), pn_gateway_ip6=dict(required=False, type='str'), pn_in_band_ip6_assign=dict(required=False, type='str', choices=['none', 'autoconf']), pn_domain_name=dict(required=False, type='str'), pn_timezone=dict(required=False, type='str'), pn_in_band_netmask=dict(required=False, type='str'), pn_in_band_ip6=dict(required=False, type='str'), pn_in_band_netmask_ip6=dict(required=False, type='str'), pn_motd=dict(required=False, type='str'), pn_loopback_ip6=dict(required=False, type='str'), pn_mgmt_ip6_assignment=dict(required=False, type='str', choices=['none', 'autoconf']), pn_ntp_secondary_server=dict(required=False, type='str'), pn_in_band_ip=dict(required=False, type='str'), pn_eula_accepted=dict(required=False, type='str', choices=['true', 'false']), pn_mgmt_ip=dict(required=False, type='str'), pn_ntp_server=dict(required=False, type='str'), pn_mgmt_ip_assignment=dict(required=False, type='str', choices=['none', 'dhcp']), pn_date=dict(required=False, type='str'), pn_password=dict(required=False, type='str', no_log=True), pn_banner=dict(required=False, type='str'), pn_loopback_ip=dict(required=False, type='str'), pn_dns_secondary_ip=dict(required=False, type='str'), pn_switch_name=dict(required=False, type='str'), pn_eula_timestamp=dict(required=False, type='str'), pn_mgmt_netmask_ip6=dict(required=False, type='str'), pn_enable_host_ports=dict(required=False, type='bool'), pn_mgmt_ip6=dict(required=False, type='str'), pn_analytics_store=dict(required=False, type='str', choices=['default', 'optimized']), pn_gateway_ip=dict(required=False, type='str'), ), required_one_of=[['pn_force', 'pn_dns_ip', 'pn_mgmt_netmask', 'pn_gateway_ip6', 'pn_in_band_ip6_assign', 'pn_domain_name', 'pn_timezone', 'pn_in_band_netmask', 'pn_in_band_ip6', 'pn_in_band_netmask_ip6', 'pn_motd', 'pn_loopback_ip6', 'pn_mgmt_ip6_assignment', 'pn_ntp_secondary_server', 'pn_in_band_ip', 'pn_eula_accepted', 'pn_mgmt_ip', 'pn_ntp_server', 'pn_mgmt_ip_assignment', 'pn_date', 'pn_password', 'pn_banner', 'pn_loopback_ip', 'pn_dns_secondary_ip', 'pn_switch_name', 'pn_eula_timestamp', 'pn_mgmt_netmask_ip6', 'pn_enable_host_ports', 'pn_mgmt_ip6', 'pn_analytics_store', 'pn_gateway_ip']], required_together=[['pn_in_band_ip6', 'pn_in_band_netmask_ip6'], ['pn_in_band_ip', 'pn_in_band_netmask'], ['pn_mgmt_ip', 'pn_mgmt_netmask'], ['pn_mgmt_ip6', 'pn_mgmt_netmask_ip6']], ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] force = module.params['pn_force'] dns_ip = module.params['pn_dns_ip'] mgmt_netmask = module.params['pn_mgmt_netmask'] gateway_ip6 = module.params['pn_gateway_ip6'] in_band_ip6_assign = module.params['pn_in_band_ip6_assign'] domain_name = module.params['pn_domain_name'] timezone = module.params['pn_timezone'] in_band_netmask = module.params['pn_in_band_netmask'] in_band_ip6 = module.params['pn_in_band_ip6'] in_band_netmask_ip6 = module.params['pn_in_band_netmask_ip6'] motd = module.params['pn_motd'] loopback_ip6 = module.params['pn_loopback_ip6'] mgmt_ip6_assignment = module.params['pn_mgmt_ip6_assignment'] ntp_secondary_server = module.params['pn_ntp_secondary_server'] in_band_ip = module.params['pn_in_band_ip'] eula_accepted = module.params['pn_eula_accepted'] mgmt_ip = module.params['pn_mgmt_ip'] ntp_server = module.params['pn_ntp_server'] mgmt_ip_assignment = module.params['pn_mgmt_ip_assignment'] date = module.params['pn_date'] password = module.params['pn_password'] banner = module.params['pn_banner'] loopback_ip = module.params['pn_loopback_ip'] dns_secondary_ip = module.params['pn_dns_secondary_ip'] switch_name = module.params['pn_switch_name'] eula_timestamp = module.params['pn_eula_timestamp'] mgmt_netmask_ip6 = module.params['pn_mgmt_netmask_ip6'] enable_host_ports = module.params['pn_enable_host_ports'] mgmt_ip6 = module.params['pn_mgmt_ip6'] analytics_store = module.params['pn_analytics_store'] gateway_ip = module.params['pn_gateway_ip'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) if command == 'switch-setup-modify': cli += ' %s ' % command if dns_ip: cli += ' dns-ip ' + dns_ip if mgmt_netmask: cli += ' mgmt-netmask ' + mgmt_netmask if gateway_ip6: cli += ' gateway-ip6 ' + gateway_ip6 if in_band_ip6_assign: cli += ' in-band-ip6-assign ' + in_band_ip6_assign if domain_name: cli += ' domain-name ' + domain_name if timezone: cli += ' timezone ' + timezone if in_band_netmask: cli += ' in-band-netmask ' + in_band_netmask if in_band_ip6: cli += ' in-band-ip6 ' + in_band_ip6 if in_band_netmask_ip6: cli += ' in-band-netmask-ip6 ' + in_band_netmask_ip6 if motd: cli += ' motd ' + motd if loopback_ip6: cli += ' loopback-ip6 ' + loopback_ip6 if mgmt_ip6_assignment: cli += ' mgmt-ip6-assignment ' + mgmt_ip6_assignment if ntp_secondary_server: cli += ' ntp-secondary-server ' + ntp_secondary_server if in_band_ip: cli += ' in-band-ip ' + in_band_ip if eula_accepted: cli += ' eula-accepted ' + eula_accepted if mgmt_ip: cli += ' mgmt-ip ' + mgmt_ip if ntp_server: cli += ' ntp-server ' + ntp_server if mgmt_ip_assignment: cli += ' mgmt-ip-assignment ' + mgmt_ip_assignment if date: cli += ' date ' + date if password: cli += ' password ' + password if banner: cli += ' banner ' + banner if loopback_ip: cli += ' loopback-ip ' + loopback_ip if dns_secondary_ip: cli += ' dns-secondary-ip ' + dns_secondary_ip if switch_name: cli += ' switch-name ' + switch_name if eula_timestamp: cli += ' eula_timestamp ' + eula_timestamp if mgmt_netmask_ip6: cli += ' mgmt-netmask-ip6 ' + mgmt_netmask_ip6 if mgmt_ip6: cli += ' mgmt-ip6 ' + mgmt_ip6 if analytics_store: cli += ' analytics-store ' + analytics_store if gateway_ip: cli += ' gateway-ip ' + gateway_ip cli += booleanArgs(force, 'force', 'no-force') cli += booleanArgs(enable_host_ports, 'enable-host-ports', 'disable-host-ports') run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict( present='ipv6security-raguard-create', absent='ipv6security-raguard-delete', update='ipv6security-raguard-modify' ) argument_spec = dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=False, type='str', choices=state_map.keys(), default='present'), pn_device=dict(required=False, type='str', choices=['host', 'router']), pn_access_list=dict(required=False, type='str'), pn_prefix_list=dict(required=False, type='str'), pn_router_priority=dict(required=False, type='str', choices=['low', 'medium', 'high']), pn_name=dict(required=True, type='str'), ) module = AnsibleModule( argument_spec=argument_spec, required_if=( ["state", "present", ['pn_device']], ), ) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] device = module.params['pn_device'] access_list = module.params['pn_access_list'] prefix_list = module.params['pn_prefix_list'] router_priority = module.params['pn_router_priority'] name = module.params['pn_name'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) NAME_EXISTS = check_cli(module) if command == 'ipv6security-raguard-modify': if not device and not access_list and not prefix_list and not router_priority: module.fail_json( failed=True, msg='required one of device, access_list, prefix_list or router_priority' ) if command == 'ipv6security-raguard-create': if NAME_EXISTS is True: module.exit_json( skipped=True, msg='ipv6 security raguard with name %s already exists' % name ) if command != 'ipv6security-raguard-create': if NAME_EXISTS is False: module.exit_json( skipped=True, msg='ipv6 security raguard with name %s does not exist' % name ) cli += ' %s name %s ' % (command, name) if command != 'ipv6security-raguard-delete': if device == 'router': cli += ' device ' + device if access_list: check_list(module, access_list, 'access-list-show') cli += ' access-list ' + access_list if prefix_list: check_list(module, prefix_list, 'prefix-list-show') cli += ' prefix-list ' + prefix_list if router_priority: cli += ' router-priority ' + router_priority if device == 'host': cli += ' device ' + device run_cli(module, cli, state_map)
def main(): """ This section is for arguments parsing """ state_map = dict(present='snmp-trap-sink-create', absent='snmp-trap-sink-delete') module = AnsibleModule( argument_spec=dict( pn_cliswitch=dict(required=False, type='str'), state=dict(required=True, type='str', choices=state_map.keys()), pn_dest_host=dict(required=False, type='str'), pn_community=dict(required=False, type='str'), pn_dest_port=dict(required=False, type='str', default='162'), pn_type=dict(required=False, type='str', choices=[ 'TRAP_TYPE_V1_TRAP', 'TRAP_TYPE_V2C_TRAP', 'TRAP_TYPE_V2_INFORM' ], default='TRAP_TYPE_V2C_TRAP'), ), required_if=( ["state", "present", ["pn_community", "pn_dest_host"]], ["state", "absent", ["pn_community", "pn_dest_host"]], )) # Accessing the arguments cliswitch = module.params['pn_cliswitch'] state = module.params['state'] dest_host = module.params['pn_dest_host'] community = module.params['pn_community'] dest_port = module.params['pn_dest_port'] pn_type = module.params['pn_type'] command = state_map[state] # Building the CLI command string cli = pn_cli(module, cliswitch) VALUE_EXISTS = check_cli(module, cli) cli += ' %s ' % command if command == 'snmp-trap-sink-create': if VALUE_EXISTS is True: module.exit_json(skipped=True, msg='snmp trap sink already exists') if VALUE_EXISTS is None: module.fail_json( failed=True, msg='snmp community does not exists to create trap sink') if pn_type: cli += ' type ' + pn_type if dest_host: cli += ' dest-host ' + dest_host if community: cli += ' community ' + community if dest_port: cli += ' dest-port ' + dest_port if command == 'snmp-trap-sink-delete': if VALUE_EXISTS is None: module.fail_json( failed=True, msg='snmp community does not exists to delete trap sink') if VALUE_EXISTS is False: module.exit_json( skipped=True, msg= 'snmp-trap-sink with community %s does not exist with dest-host %s ' % (community, dest_host)) if community: cli += ' community ' + community if dest_host: cli += ' dest-host ' + dest_host if dest_port: cli += ' dest-port ' + dest_port run_cli(module, cli, state_map)