Пример #1
0
def main():
    helper = get_connection(
        template=True,
        template_stack=True,
        with_state=True,
        with_classic_provider_spec=True,
        argument_spec=setup_args(),
    )

    module = AnsibleModule(
        argument_spec=helper.argument_spec,
        supports_check_mode=True,
        required_one_of=helper.required_one_of,
    )

    parent = helper.get_pandevice_parent(module)

    vr = VirtualRouter(module.params['vr_name'])
    parent.add(vr)
    try:
        vr.refresh()
    except PanDeviceError as e:
        module.fail_json(msg='Failed refresh: {0}'.format(e))

    spec = {
        'name': module.params['name'],
        'priority': module.params['priority'],
        'action': module.params['action'],
        'filter_type': module.params['filter_type'],
        'filter_interface': module.params['filter_interface'],
        'filter_destination': module.params['filter_destination'],
        'filter_nexthop': module.params['filter_nexthop'],
        'ospf_filter_pathtype': module.params['ospf_filter_pathtype'],
        'ospf_filter_area': module.params['ospf_filter_area'],
        'ospf_filter_tag': module.params['ospf_filter_tag'],
        'bgp_filter_community': module.params['bgp_filter_community'],
        'bgp_filter_extended_community': module.params['bgp_filter_extended_community'],
    }

    if module.params['type'] == 'ipv4':
        obj = RedistributionProfile(**spec)
    else:
        obj = RedistributionProfileIPv6(**spec)

    listing = vr.findall(obj.__class__)
    vr.add(obj)

    changed = helper.apply_state(obj, listing, module)
    if changed and module.params['commit']:
        helper.commit(module)

    module.exit_json(changed=changed, msg='done')
Пример #2
0
def configure_network(device):
    eth1 = EthernetInterface(name='ethernet1/1',
                             mode='layer3',
                             ip=('192.168.55.20/24', ))
    eth2 = EthernetInterface(name='ethernet1/2',
                             mode='layer3',
                             ip=('192.168.45.20/24', ))
    eth3 = EthernetInterface(name='ethernet1/3',
                             mode='layer3',
                             ip=('192.168.35.20/24', ))

    device.add(eth1)
    device.add(eth2)
    device.add(eth3)

    eth1.create()
    eth2.create()
    eth3.create()

    untrust = Zone(name='untrust', mode='layer3', interface=['ethernet1/1'])
    web = Zone(name='web', mode='layer3', interface=['ethernet1/2'])
    db = Zone(name='db', mode='layer3', interface=['ethernet1/3'])

    device.add(untrust)
    device.add(web)
    device.add(db)

    untrust.create()
    web.create()
    db.create()

    vr_default = VirtualRouter(
        name='default',
        interface=['ethernet1/1', 'ethernet1/2', 'ethernet1/3'])
    device.add(vr_default)
    vr_default.create()

    default_route = StaticRoute(name='default',
                                destination='0.0.0.0/0',
                                nexthop='192.168.55.2')
    vr_default.add(default_route)
    default_route.create()