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
Esempio n. 2
0
def main():
    """ This section is for arguments parsing """

    state_map = dict(update='admin-session-timeout-modify')

    module = AnsibleModule(
        argument_spec=dict(
            pn_cliswitch=dict(required=False, type='str'),
            state=dict(required=True, type='str', choices=state_map.keys()),
            pn_timeout=dict(required=False, type='str'),
        ),
        required_together=[['state', 'pn_timeout']],
    )

    # Accessing the arguments
    cliswitch = module.params['pn_cliswitch']
    state = module.params['state']
    timeout = module.params['pn_timeout']

    command = state_map[state]

    # Building the CLI command string
    cli = pn_cli(module, cliswitch)
    if command == 'admin-session-timeout-modify':
        cli += ' %s ' % command
        if timeout:
            cli += ' timeout ' + timeout

    run_cli(module, cli, state_map)
def main():
    """ This section is for arguments parsing """

    state_map = dict(present='snmp-community-create',
                     absent='snmp-community-delete',
                     update='snmp-community-modify')

    module = AnsibleModule(
        argument_spec=dict(
            pn_cliswitch=dict(required=False, type='str'),
            state=dict(required=True, type='str', choices=state_map.keys()),
            pn_community_type=dict(required=False,
                                   type='str',
                                   choices=['read-only', 'read-write']),
            pn_community_string=dict(required=False, type='str'),
        ),
        required_if=(
            ["state", "present", ["pn_community_type", "pn_community_string"]],
            ["state", "absent", ["pn_community_string"]],
            ["state", "update", ["pn_community_type", "pn_community_string"]],
        ))

    # Accessing the arguments
    cliswitch = module.params['pn_cliswitch']
    state = module.params['state']
    community_type = module.params['pn_community_type']
    comm_str = module.params['pn_community_string']

    command = state_map[state]

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

    COMMUNITY_EXISTS = check_cli(module, cli)

    if command == 'snmp-community-modify':
        if COMMUNITY_EXISTS is False:
            module.fail_json(failed=True,
                             msg='snmp community name %s does not exist' %
                             comm_str)

    if command == 'snmp-community-delete':
        if COMMUNITY_EXISTS is False:
            module.exit_json(skipped=True,
                             msg='snmp community name %s does not exist' %
                             comm_str)

    if command == 'snmp-community-create':
        if COMMUNITY_EXISTS is True:
            module.exit_json(skipped=True,
                             msg='snmp community with name %s already exists' %
                             comm_str)

    cli += ' %s community-string %s ' % (command, comm_str)

    if command != 'snmp-community-delete' and community_type:
        cli += ' community-type ' + community_type

    run_cli(module, cli, state_map)
def main():
    """ This section is for arguments parsing """

    state_map = dict(present='vrouter-bgp-network-add',
                     absent='vrouter-bgp-network-remove')

    module = AnsibleModule(
        argument_spec=dict(
            pn_cliswitch=dict(required=False, type='str'),
            state=dict(required=True, type='str', choices=state_map.keys()),
            pn_netmask=dict(required=False, type='str'),
            pn_network=dict(required=False, type='str'),
            pn_vrouter_name=dict(required=False, type='str'),
        ),
        required_if=(
            [
                'state', 'present',
                ['pn_vrouter_name', 'pn_netmask', 'pn_network']
            ],
            ['state', 'absent', ['pn_vrouter_name', 'pn_network']],
        ),
    )

    # Accessing the arguments
    state = module.params['state']
    cliswitch = module.params['pn_cliswitch']
    netmask = module.params['pn_netmask']
    network = module.params['pn_network']
    vrouter_name = module.params['pn_vrouter_name']

    command = state_map[state]

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

    NETWORK_EXISTS, VROUTER_EXISTS = check_cli(module, cli)

    if VROUTER_EXISTS is None:
        module.fail_json(failed=True,
                         msg='vRouter %s does not exists' % vrouter_name)

    if command == 'vrouter-bgp-network-add':
        if NETWORK_EXISTS is True:
            module.exit_json(skipped=True,
                             msg='Network %s already added to bgp' % network)

    if command == 'vrouter-bgp-network-remove':
        if NETWORK_EXISTS is False:
            module.exit_json(skipped=True,
                             msg='Network %s does not exists' % network)

    cli += ' %s vrouter-name %s ' % (command, vrouter_name)

    if netmask:
        cli += ' netmask ' + netmask
    if network:
        cli += ' network ' + network

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

    global state_map
    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)
Esempio n. 8
0
def main():
    """ This section is for arguments parsing """

    state_map = dict(
        present='dscp-map-create',
        absent='dscp-map-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']
    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 == 'dscp-map-delete':
        if NAME_EXISTS is False:
            module.exit_json(
                skipped=True,
                msg='dscp map with name %s does not exist' % name
            )
    else:
        if command == 'dscp-map-create':
            if NAME_EXISTS is True:
                module.exit_json(
                    skipped=True,
                    msg='dscp map with name %s already exists' % name
                )

        if scope:
            cli += ' scope ' + scope

    run_cli(module, cli, state_map)
Esempio n. 9
0
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. 10
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)
Esempio n. 11
0
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. 12
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)
Esempio n. 13
0
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. 14
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)
def main():
    """ This section is for arguments parsing """

    state_map = dict(update='igmp-snooping-modify')

    module = AnsibleModule(argument_spec=dict(
        pn_cliswitch=dict(required=False, type='str'),
        state=dict(required=True, type='str', choices=state_map.keys()),
        pn_enable=dict(required=False, type='bool'),
        pn_query_interval=dict(required=False, type='str'),
        pn_igmpv2_vlans=dict(required=False, type='str'),
        pn_igmpv3_vlans=dict(required=False, type='str'),
        pn_enable_vlans=dict(required=False, type='str'),
        pn_vxlan=dict(required=False, type='bool'),
        pn_query_max_response_time=dict(required=False, type='str'),
        pn_scope=dict(required=False, type='str', choices=['local', 'fabric']),
        pn_no_snoop_linklocal_vlans=dict(required=False, type='str'),
        pn_snoop_linklocal_vlans=dict(required=False, type='str'),
    ),
                           required_one_of=[[
                               'pn_enable', 'pn_query_interval',
                               'pn_igmpv2_vlans', 'pn_igmpv3_vlans',
                               'pn_enable_vlans', 'pn_vxlan',
                               'pn_query_max_response_time', 'pn_scope',
                               'pn_no_snoop_linklocal_vlans',
                               'pn_snoop_linklocal_vlans'
                           ]])

    # Accessing the arguments
    cliswitch = module.params['pn_cliswitch']
    state = module.params['state']
    enable = module.params['pn_enable']
    query_interval = module.params['pn_query_interval']
    igmpv2_vlans = module.params['pn_igmpv2_vlans']
    igmpv3_vlans = module.params['pn_igmpv3_vlans']
    enable_vlans = module.params['pn_enable_vlans']
    vxlan = module.params['pn_vxlan']
    query_max_response_time = module.params['pn_query_max_response_time']
    scope = module.params['pn_scope']
    no_snoop_linklocal_vlans = module.params['pn_no_snoop_linklocal_vlans']
    snoop_linklocal_vlans = module.params['pn_snoop_linklocal_vlans']

    command = state_map[state]

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

    if command == 'igmp-snooping-modify':
        cli += ' %s ' % command

        cli += booleanArgs(enable, 'enable', 'disable')
        cli += booleanArgs(vxlan, 'vxlan', 'no-vxlan')

        if query_interval:
            cli += ' query-interval ' + query_interval
        if igmpv2_vlans:
            cli += ' igmpv2-vlans ' + igmpv2_vlans
        if igmpv3_vlans:
            cli += ' igmpv3-vlans ' + igmpv3_vlans
        if enable_vlans:
            cli += ' enable-vlans ' + enable_vlans
        if query_max_response_time:
            cli += ' query-max-response-time ' + query_max_response_time
        if scope:
            cli += ' scope ' + scope
        if no_snoop_linklocal_vlans:
            cli += ' no-snoop-linklocal-vlans ' + no_snoop_linklocal_vlans
        if snoop_linklocal_vlans:
            cli += ' snoop-linklocal-vlans ' + snoop_linklocal_vlans

    run_cli(module, cli, state_map)
def main():
    """ This section is for arguments parsing """

    state_map = dict(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)
Esempio n. 18
0
def main():
    """ This section is for arguments parsing """

    state_map = dict(update='port-config-modify')

    module = AnsibleModule(
        argument_spec=dict(
            pn_cliswitch=dict(required=False, type='str'),
            state=dict(required=True, type='str', choices=['update']),
            pn_intf=dict(required=False, type='str'),
            pn_crc_check_enable=dict(required=False, type='bool'),
            pn_dscp_map=dict(required=False, type='str'),
            pn_autoneg=dict(required=False, type='bool'),
            pn_speed=dict(required=False,
                          type='str',
                          choices=[
                              'disable', '10m', '100m', '1g', '2.5g', '10g',
                              '25g', '40g', '50g', '100g'
                          ]),
            pn_port=dict(required=False, type='str'),
            pn_vxlan_termination=dict(required=False, type='bool'),
            pn_pause=dict(required=False, type='bool'),
            pn_loopback=dict(required=False, type='bool'),
            pn_loop_vlans=dict(required=False, type='str'),
            pn_routing=dict(required=False, type='bool'),
            pn_edge_switch=dict(required=False, type='bool'),
            pn_enable=dict(required=False, type='bool'),
            pn_description=dict(required=False, type='str'),
            pn_host_enable=dict(required=False, type='bool'),
            pn_allowed_tpid=dict(required=False,
                                 type='str',
                                 choices=['vlan', 'q-in-q', 'q-in-q-old']),
            pn_mirror_only=dict(required=False, type='bool'),
            pn_reflect=dict(required=False, type='bool'),
            pn_jumbo=dict(required=False, type='bool'),
            pn_egress_rate_limit=dict(required=False, type='str'),
            pn_eth_mode=dict(
                required=False,
                type='str',
                choices=['1000base-x', 'sgmii', 'disabled', 'GMII']),
            pn_fabric_guard=dict(required=False, type='bool'),
            pn_local_switching=dict(required=False, type='bool'),
            pn_lacp_priority=dict(required=False, type='str'),
            pn_send_port=dict(required=False, type='str'),
            pn_port_mac_address=dict(required=False, type='str'),
            pn_defer_bringup=dict(required=False, type='bool'),
        ),
        required_if=(['state', 'update', ['pn_port']], ),
        required_one_of=[[
            'pn_intf', 'pn_crc_check_enable', 'pn_dscp_map', 'pn_speed',
            'pn_autoneg', 'pn_vxlan_termination', 'pn_pause', 'pn_fec',
            'pn_loopback', 'pn_loop_vlans', 'pn_routing', 'pn_edge_switch',
            'pn_enable', 'pn_description', 'pn_host_enable', 'pn_allowed_tpid',
            'pn_mirror_only', 'pn_reflect', 'pn_jumbo', 'pn_egress_rate_limit',
            'pn_eth_mode', 'pn_fabric_guard', 'pn_local_switching',
            'pn_lacp_priority', 'pn_send_port', 'pn_port_mac_address',
            'pn_defer_bringup'
        ]],
    )

    # Accessing the arguments
    cliswitch = module.params['pn_cliswitch']
    state = module.params['state']
    intf = module.params['pn_intf']
    crc_check_enable = module.params['pn_crc_check_enable']
    dscp_map = module.params['pn_dscp_map']
    autoneg = module.params['pn_autoneg']
    speed = module.params['pn_speed']
    port = module.params['pn_port']
    vxlan_termination = module.params['pn_vxlan_termination']
    pause = module.params['pn_pause']
    loopback = module.params['pn_loopback']
    loop_vlans = module.params['pn_loop_vlans']
    routing = module.params['pn_routing']
    edge_switch = module.params['pn_edge_switch']
    enable = module.params['pn_enable']
    description = module.params['pn_description']
    host_enable = module.params['pn_host_enable']
    allowed_tpid = module.params['pn_allowed_tpid']
    mirror_only = module.params['pn_mirror_only']
    reflect = module.params['pn_reflect']
    jumbo = module.params['pn_jumbo']
    egress_rate_limit = module.params['pn_egress_rate_limit']
    eth_mode = module.params['pn_eth_mode']
    fabric_guard = module.params['pn_fabric_guard']
    local_switching = module.params['pn_local_switching']
    lacp_priority = module.params['pn_lacp_priority']
    send_port = module.params['pn_send_port']
    port_mac_address = module.params['pn_port_mac_address']
    defer_bringup = module.params['pn_defer_bringup']

    command = state_map[state]

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

    if dscp_map:
        NAME_EXISTS = check_cli(module, cli)

    if command == 'port-config-modify':
        cli += ' %s ' % command
        if dscp_map:
            if NAME_EXISTS is False:
                module.fail_json(
                    failed=True,
                    msg='Create dscp map with name %s before updating' %
                    dscp_map)

            cli += ' dscp-map ' + dscp_map
        if intf:
            cli += ' intf ' + intf
        if speed:
            cli += ' speed ' + speed
        if port:
            cli += ' port ' + port
        if allowed_tpid:
            cli += ' allowed-tpid ' + allowed_tpid
        if egress_rate_limit:
            cli += ' egress-rate-limit ' + egress_rate_limit
        if eth_mode:
            cli += ' eth-mode ' + eth_mode
        if lacp_priority:
            cli += ' lacp-priority ' + lacp_priority
        if send_port:
            cli += ' send-port ' + send_port
        if port_mac_address:
            cli += ' port-mac-address ' + port_mac_address

        cli += booleanArgs(crc_check_enable, 'crc-check-enable',
                           'crc-check-disable')
        cli += booleanArgs(autoneg, 'autoneg', 'no-autoneg')
        cli += booleanArgs(vxlan_termination, 'vxlan-termination',
                           'no-vxlan-termination')
        cli += booleanArgs(pause, 'pause', 'no-pause')
        cli += booleanArgs(loopback, 'loopback', 'no-loopback')
        cli += booleanArgs(routing, 'routing', 'no-routing')
        cli += booleanArgs(edge_switch, 'edge-switch', 'no-edge-switch')
        cli += booleanArgs(enable, 'enable', 'disable')
        cli += booleanArgs(host_enable, 'host-enable', 'host-disable')
        cli += booleanArgs(mirror_only, 'mirror-only',
                           'no-mirror-receive-only')
        cli += booleanArgs(reflect, 'reflect', 'no-reflect')
        cli += booleanArgs(jumbo, 'jumbo', 'no-jumbo')
        cli += booleanArgs(fabric_guard, 'fabric-guard', 'no-fabric-guard')
        cli += booleanArgs(local_switching, 'local-switching',
                           'no-local-switching')
        cli += booleanArgs(defer_bringup, 'defer-bringup', 'no-defer-bringup')

    run_cli(module, cli, state_map)
def main():
    """ This section is for arguments parsing """

    state_map = dict(update='port-cos-rate-setting-modify')

    module = AnsibleModule(
        argument_spec=dict(
            pn_cliswitch=dict(required=False, type='str'),
            state=dict(required=True, type='str', choices=state_map.keys()),
            pn_cos1_rate=dict(required=False, type='str'),
            pn_cos5_rate=dict(required=False, type='str'),
            pn_cos2_rate=dict(required=False, type='str'),
            pn_cos0_rate=dict(required=False, type='str'),
            pn_cos6_rate=dict(required=False, type='str'),
            pn_cos3_rate=dict(required=False, type='str'),
            pn_cos4_rate=dict(required=False, type='str'),
            pn_cos7_rate=dict(required=False, type='str'),
            pn_port=dict(required=False,
                         type='str',
                         choices=['control-port', 'data-port', 'span-ports']),
        ),
        required_if=(['state', 'update', ['pn_port']], ),
        required_one_of=[[
            'pn_cos0_rate', 'pn_cos1_rate', 'pn_cos2_rate', 'pn_cos3_rate',
            'pn_cos4_rate', 'pn_cos5_rate', 'pn_cos6_rate', 'pn_cos7_rate'
        ]],
    )

    # Accessing the arguments
    cliswitch = module.params['pn_cliswitch']
    state = module.params['state']
    cos1_rate = module.params['pn_cos1_rate']
    cos5_rate = module.params['pn_cos5_rate']
    cos2_rate = module.params['pn_cos2_rate']
    cos0_rate = module.params['pn_cos0_rate']
    cos6_rate = module.params['pn_cos6_rate']
    cos3_rate = module.params['pn_cos3_rate']
    cos4_rate = module.params['pn_cos4_rate']
    cos7_rate = module.params['pn_cos7_rate']
    port = module.params['pn_port']

    command = state_map[state]

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

    if command == 'port-cos-rate-setting-modify':
        cli += ' %s ' % command
        if cos1_rate:
            cli += ' cos1-rate ' + cos1_rate
        if cos5_rate:
            cli += ' cos5-rate ' + cos5_rate
        if cos2_rate:
            cli += ' cos2-rate ' + cos2_rate
        if cos0_rate:
            cli += ' cos0-rate ' + cos0_rate
        if cos6_rate:
            cli += ' cos6-rate ' + cos6_rate
        if cos3_rate:
            cli += ' cos3-rate ' + cos3_rate
        if cos4_rate:
            cli += ' cos4-rate ' + cos4_rate
        if cos7_rate:
            cli += ' cos7-rate ' + cos7_rate
        if port:
            cli += ' port ' + port

    run_cli(module, cli, state_map)
Esempio n. 20
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)
Esempio n. 21
0
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)
Esempio n. 22
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)
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)
Esempio n. 24
0
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)
Esempio n. 25
0
def main():
    """ This section is for arguments parsing """

    state_map = dict(present='vrouter-interface-ip-add',
                     absent='vrouter-interface-ip-remove')

    module = AnsibleModule(
        argument_spec=dict(
            pn_cliswitch=dict(required=False, type='str'),
            state=dict(required=True, type='str', choices=state_map.keys()),
            pn_bd=dict(required=False, type='str'),
            pn_netmask=dict(required=False, type='str'),
            pn_vnet=dict(required=False, type='str'),
            pn_ip=dict(required=False, type='str'),
            pn_nic=dict(required=False, type='str'),
            pn_vrouter_name=dict(required=False, type='str'),
        ),
        required_if=([
            "state", "present",
            ["pn_vrouter_name", "pn_nic", "pn_ip", "pn_netmask"]
        ], ["state", "absent", ["pn_vrouter_name", "pn_nic", "pn_ip"]]),
    )

    # Accessing the arguments
    cliswitch = module.params['pn_cliswitch']
    state = module.params['state']
    bd = module.params['pn_bd']
    netmask = module.params['pn_netmask']
    vnet = module.params['pn_vnet']
    ip = module.params['pn_ip']
    nic = module.params['pn_nic']
    vrouter_name = module.params['pn_vrouter_name']

    command = state_map[state]

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

    VROUTER_EXISTS, INTERFACE_EXISTS, NIC_EXISTS = check_cli(module, cli)

    if VROUTER_EXISTS is False:
        module.fail_json(failed=True,
                         msg='vRouter %s does not exist' % vrouter_name)

    if NIC_EXISTS is False:
        module.fail_json(failed=True,
                         msg='vRouter with nic %s does not exist' % nic)

    cli += ' %s vrouter-name %s ' % (command, vrouter_name)

    if command == 'vrouter-interface-ip-add':
        if INTERFACE_EXISTS is True:
            module.exit_json(skipped=True,
                             msg='vRouter with interface ip %s exist' % ip)
        cli += ' nic %s ip %s ' % (nic, ip)

        if bd:
            cli += ' bd ' + bd
        if netmask:
            cli += ' netmask ' + netmask
        if vnet:
            cli += ' vnet ' + vnet

    if command == 'vrouter-interface-ip-remove':
        if INTERFACE_EXISTS is False:
            module.exit_json(
                skipped=True,
                msg='vRouter with interface ip %s does not exist' % ip)
        if nic:
            cli += ' nic %s ' % nic
        if ip:
            cli += ' ip %s ' % ip.split('/')[0]

    run_cli(module, cli, state_map)
def main():
    """ This section is for arguments parsing """

    state_map = dict(present='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)
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)
Esempio n. 28
0
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)
Esempio n. 29
0
def main():
    """ This section is for arguments parsing """

    global state_map
    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)
Esempio n. 30
0
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)