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)
Esempio n. 3
0
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='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)
Esempio n. 6
0
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)
Esempio n. 7
0
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='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)
Esempio n. 9
0
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)
Esempio n. 11
0
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='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)
Esempio n. 13
0
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)
Esempio n. 15
0
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)
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)
Esempio n. 17
0
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='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='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-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(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='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='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)
Esempio n. 24
0
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='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='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)
Esempio n. 27
0
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='admin-service-modify')

    module = AnsibleModule(argument_spec=dict(
        pn_cliswitch=dict(required=False, type='str'),
        state=dict(required=True, type='str', choices=state_map.keys()),
        pn_web=dict(required=False, type='bool'),
        pn_web_ssl=dict(required=False, type='bool'),
        pn_snmp=dict(required=False, type='bool'),
        pn_web_port=dict(required=False, type='str'),
        pn_web_ssl_port=dict(required=False, type='str'),
        pn_nfs=dict(required=False, type='bool'),
        pn_ssh=dict(required=False, type='bool'),
        pn_web_log=dict(required=False, type='bool'),
        pn__if=dict(required=False, type='str', choices=['mgmt', 'data']),
        pn_icmp=dict(required=False, type='bool'),
        pn_net_api=dict(required=False, type='bool'),
    ),
                           required_if=([['state', 'update', ['pn__if']]]),
                           required_one_of=[[
                               'pn_web', 'pn_web_ssl', 'pn_snmp',
                               'pn_web_port', 'pn_web_ssl_port', 'pn_nfs',
                               'pn_ssh', 'pn_web_log', 'pn_icmp', 'pn_net_api'
                           ]])

    # Accessing the arguments
    cliswitch = module.params['pn_cliswitch']
    state = module.params['state']
    web = module.params['pn_web']
    web_ssl = module.params['pn_web_ssl']
    snmp = module.params['pn_snmp']
    web_port = module.params['pn_web_port']
    web_ssl_port = module.params['pn_web_ssl_port']
    nfs = module.params['pn_nfs']
    ssh = module.params['pn_ssh']
    web_log = module.params['pn_web_log']
    _if = module.params['pn__if']
    icmp = module.params['pn_icmp']
    net_api = module.params['pn_net_api']

    command = state_map[state]

    # Building the CLI command string
    cli = pn_cli(module, cliswitch)

    if command == 'admin-service-modify':
        cli += ' %s ' % command

        if _if:
            cli += ' if ' + _if
        if web_port:
            cli += ' web-port ' + web_port
        if web_ssl_port:
            cli += ' web-ssl-port ' + web_ssl_port

        cli += booleanArgs(web, 'web', 'no-web')
        cli += booleanArgs(web_ssl, 'web-ssl', 'no-web-ssl')
        cli += booleanArgs(snmp, 'snmp', 'no-snmp')
        cli += booleanArgs(nfs, 'nfs', 'no-nfs')
        cli += booleanArgs(ssh, 'ssh', 'no-ssh')
        cli += booleanArgs(icmp, 'icmp', 'no-icmp')
        cli += booleanArgs(net_api, 'net-api', 'no-net-api')
        cli += booleanArgs(web_log, 'web-log', 'no-web-log')

    run_cli(module, cli, state_map)
Esempio n. 29
0
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)
Esempio n. 30
0
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)