コード例 #1
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(
        aep=dict(type='str',
                 aliases=['aep_name'
                          ]),  # Not required for querying all objects
        domain=dict(type='str',
                    aliases=['domain_name', 'domain_profile'
                             ]),  # Not required for querying all objects
        domain_type=dict(type='str',
                         choices=['fc', 'l2dom', 'l3dom', 'phys', 'vmm'],
                         aliases=['type'
                                  ]),  # Not required for querying all objects
        state=dict(type='str',
                   default='present',
                   choices=['absent', 'present', 'query']),
        vm_provider=dict(type='str',
                         choices=[
                             'cloudfoundry', 'kubernetes', 'microsoft',
                             'openshift', 'openstack', 'redhat', 'vmware'
                         ]),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ['domain_type', 'vmm', ['vm_provider']],
            ['state', 'absent', ['aep', 'domain', 'domain_type']],
            ['state', 'present', ['aep', 'domain', 'domain_type']],
        ],
        required_together=[
            ['domain', 'domain_type'],
        ],
    )

    aep = module.params.get('aep')
    domain = module.params.get('domain')
    domain_type = module.params.get('domain_type')
    vm_provider = module.params.get('vm_provider')
    state = module.params.get('state')

    # Report when vm_provider is set when type is not virtual
    if domain_type != 'vmm' and vm_provider is not None:
        module.fail_json(msg="Domain type '{0}' cannot have a 'vm_provider'".
                         format(domain_type))

    # Compile the full domain for URL building
    if domain_type == 'fc':
        domain_mo = 'uni/fc-{0}'.format(domain)
    elif domain_type == 'l2dom':
        domain_mo = 'uni/l2dom-{0}'.format(domain)
    elif domain_type == 'l3dom':
        domain_mo = 'uni/l3dom-{0}'.format(domain)
    elif domain_type == 'phys':
        domain_mo = 'uni/phys-{0}'.format(domain)
    elif domain_type == 'vmm':
        domain_mo = 'uni/vmmp-{0}/dom-{1}'.format(
            VM_PROVIDER_MAPPING[vm_provider], domain)
    else:
        domain_mo = None

    aci = ACIModule(module)
    aci.construct_url(
        root_class=dict(
            aci_class='infraAttEntityP',
            aci_rn='infra/attentp-{0}'.format(aep),
            module_object=aep,
            target_filter={'name': aep},
        ),
        subclass_1=dict(
            aci_class='infraRsDomP',
            aci_rn='rsdomP-[{0}]'.format(domain_mo),
            module_object=domain_mo,
            target_filter={'tDn': domain_mo},
        ),
    )

    aci.get_existing()

    if state == 'present':
        aci.payload(
            aci_class='infraRsDomP',
            class_config=dict(tDn=domain_mo),
        )

        aci.get_diff(aci_class='infraRsDomP')

        aci.post_config()

    elif state == 'absent':
        aci.delete_config()

    aci.exit_json()
コード例 #2
0
def main():
    argument_spec = aci_argument_spec()

    argument_spec.update(aep=dict(type='str', aliases=['aep_name']),
                         tenant=dict(type='str', aliases=['tenant_name']),
                         ap=dict(type='str',
                                 aliases=['app_profile', 'app_profile_name']),
                         epg=dict(type='str', aliases=['epg_name']),
                         encap=dict(type='int',
                                    aliases=['vlan', 'vlan_id', 'encap_id']),
                         primary_encap=dict(type='int',
                                            aliases=[
                                                'primary_vlan',
                                                'primary_vlan_id',
                                                'primary_encap_id'
                                            ]),
                         interface_mode=dict(type='str',
                                             choices=[
                                                 '802.1p', 'access', 'native',
                                                 'regular', 'tagged', 'trunk',
                                                 'untagged'
                                             ],
                                             aliases=[
                                                 'mode_name', 'mode',
                                                 'interface_mode_name'
                                             ]),
                         state=dict(type='str',
                                    default='present',
                                    choices=['absent', 'present', 'query']))

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ['state', 'absent', ['aep', 'epg', 'ap', 'tenant']],
            [
                'state', 'present',
                ['interface_mode', 'encap', 'aep', 'epg', 'ap', 'tenant']
            ],
        ])

    aep = module.params.get('aep')
    tenant = module.params.get('tenant')
    ap = module.params.get('ap')
    epg = module.params.get('epg')
    encap = module.params.get('encap')
    primary_encap = module.params.get('primary_encap')
    interface_mode = module.params.get('interface_mode')
    state = module.params.get('state')

    if interface_mode is not None:
        interface_mode = INTERFACE_MODE_MAPPING[interface_mode]

    if encap is not None:
        encap = 'vlan-{0}'.format(encap)

    if primary_encap is not None:
        primary_encap = 'vlan-{0}'.format(primary_encap)

    epg_mo = None
    if tenant is not None and ap is not None and epg is not None:
        epg_mo = 'uni/tn-{0}/ap-{1}/epg-{2}'.format(tenant, ap, epg)

    aci = ACIModule(module)
    aci.construct_url(root_class=dict(aci_class='infraAttEntityP',
                                      aci_rn='infra/attentp-{0}'.format(aep),
                                      module_object=aep,
                                      target_filter={'name': aep}),
                      subclass_1=dict(aci_class='infraGeneric',
                                      aci_rn='gen-default',
                                      module_object='default',
                                      target_filter={'name': 'default'}),
                      child_classes=['infraRsFuncToEpg'])

    aci.get_existing()

    if state == 'present':
        child_configs = [
            dict(infraRsFuncToEpg=dict(
                attributes=dict(encap=encap,
                                primaryEncap=primary_encap,
                                mode=interface_mode,
                                tDn=epg_mo)))
        ]

        aci.payload(aci_class='infraGeneric',
                    class_config=dict(name='default'),
                    child_configs=child_configs)

        aci.get_diff(aci_class='infraGeneric')

        aci.post_config()

    elif state == 'absent':
        aci.delete_config()

    aci.exit_json()
コード例 #3
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(
        tenant=dict(type='str', aliases=['tenant_name'], required=True),
        l3out=dict(type='str', aliases=['l3out_name'], required=True),
        node_profile=dict(type='str',
                          aliases=['node_profile_name', 'logical_node'],
                          required=True),
        interface_profile=dict(
            type='str',
            aliases=['interface_profile_name', 'logical_interface'],
            required=True),
        state=dict(type='str',
                   default='present',
                   choices=['absent', 'present', 'query']),
        pod_id=dict(type='str', required=True),
        node_id=dict(type='str', required=True),
        path_ep=dict(type='str', required=True),
        peer_ip=dict(type='str', required=True),
        remote_asn=dict(type='int'),
        bgp_controls=dict(type='list',
                          elements='str',
                          choices=[
                              'send-com', 'send-ext-com', 'allow-self-as',
                              'as-override', 'dis-peer-as-check', 'nh-self'
                          ]),
        peer_controls=dict(type='list',
                           elements='str',
                           choices=['bfd', 'dis-conn-check']),
        address_type_controls=dict(type='list',
                                   elements='str',
                                   choices=['af-ucast', 'af-mcast']),
        private_asn_controls=dict(
            type='list',
            elements='str',
            choices=['remove-exclusive', 'remove-all', 'replace-as']),
        ttl=dict(type='int'),
        weight=dict(type='int'),
        admin_state=dict(type='str', choices=['enabled', 'disabled']),
        allow_self_as_count=dict(type='int'),
    )

    module = AnsibleModule(argument_spec=argument_spec,
                           supports_check_mode=True)

    tenant = module.params.get('tenant')
    l3out = module.params.get('l3out')
    node_profile = module.params.get('node_profile')
    interface_profile = module.params.get('interface_profile')
    state = module.params.get('state')
    pod_id = module.params.get('pod_id')
    node_id = module.params.get('node_id')
    path_ep = module.params.get('path_ep')
    peer_ip = module.params.get('peer_ip')
    remote_asn = module.params.get('remote_asn')
    bgp_controls = module.params.get('bgp_controls')
    peer_controls = module.params.get('peer_controls')
    address_type_controls = module.params.get('address_type_controls')
    private_asn_controls = module.params.get('private_asn_controls')
    ttl = module.params.get('ttl')
    weight = module.params.get('weight')
    admin_state = module.params.get('admin_state')
    allow_self_as_count = module.params.get('allow_self_as_count')

    aci = ACIModule(module)
    if '-' in node_id:
        path_type = 'protpaths'
    else:
        path_type = 'paths'

    path_dn = ('topology/pod-{0}/{1}-{2}/pathep-[{3}]'.format(
        pod_id, path_type, node_id, path_ep))

    aci.construct_url(
        root_class=dict(
            aci_class='fvTenant',
            aci_rn='tn-{0}'.format(tenant),
            module_object=tenant,
            target_filter={'name': tenant},
        ),
        subclass_1=dict(
            aci_class='l3extOut',
            aci_rn='out-{0}'.format(l3out),
            module_object=l3out,
            target_filter={'name': l3out},
        ),
        subclass_2=dict(
            aci_class='l3extLNodeP',
            aci_rn='lnodep-{0}'.format(node_profile),
            module_object=node_profile,
            target_filter={'name': node_profile},
        ),
        subclass_3=dict(
            aci_class='l3extLIfP',
            aci_rn='lifp-{0}'.format(interface_profile),
            module_object=interface_profile,
            target_filter={'name': interface_profile},
        ),
        subclass_4=dict(aci_class='l3extRsPathL3OutAtt',
                        aci_rn='/rspathL3OutAtt-[{0}]'.format(path_dn),
                        module_object=path_dn,
                        target_filter={'tDn': path_dn}),
        subclass_5=dict(aci_class='bgpPeerP',
                        aci_rn='/peerP-[{0}]'.format(peer_ip),
                        module_object=peer_ip,
                        target_filter={'addr': peer_ip}),
        child_classes=['bgpRsPeerPfxPol', 'bgpAsP', 'bgpLocalAsnP'])

    aci.get_existing()

    if state == 'present':
        ctrl, peerCtrl, addrTCtrl, privateASctrl = None, None, None, None
        if bgp_controls:
            ctrl = ','.join(bgp_controls)
        if peer_controls:
            peerCtrl = ','.join(peer_controls)
        if address_type_controls:
            addrTCtrl = ','.join(address_type_controls)
        if private_asn_controls:
            privateASctrl = ','.join(private_asn_controls)
        aci.payload(
            aci_class='bgpPeerP',
            class_config=dict(addr=peer_ip,
                              ctrl=ctrl,
                              peerCtrl=peerCtrl,
                              addrTCtrl=addrTCtrl,
                              privateASctrl=privateASctrl,
                              ttl=ttl,
                              weight=weight,
                              adminSt=admin_state,
                              allowedSelfAsCnt=allow_self_as_count),
            child_configs=[
                dict(bgpAsP=dict(attributes=dict(asn=remote_asn), ), ),
            ],
        )

        aci.get_diff(aci_class='bgpPeerP')

        aci.post_config()

    elif state == 'absent':
        aci.delete_config()

    aci.exit_json()
コード例 #4
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update({
        'description':
        dict(type='str', aliases=['descr']),
        'name':
        dict(type='str',
             aliases=['cloud_epg', 'cloud_epg_name', 'epg', 'epg_name']),
        'tenant':
        dict(type='str', ),
        'ap':
        dict(type='str', aliases=['app_profile', 'app_profile_name']),
        'state':
        dict(type='str',
             default='present',
             choices=['absent', 'present', 'query']),
        'vrf':
        dict(type='str', aliases=['context', 'vrf_name']),
    })

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ['state', 'absent', ['name', 'tenant', 'ap']],
            ['state', 'present', ['name', 'tenant', 'ap']],
        ],
    )

    description = module.params.get('description')
    name = module.params.get('name')
    tenant = module.params.get('tenant')
    ap = module.params.get('ap')
    state = module.params.get('state')
    child_configs = []
    relation_vrf = module.params.get('vrf')

    if relation_vrf:
        child_configs.append({
            'cloudRsCloudEPgCtx': {
                'attributes': {
                    'tnFvCtxName': relation_vrf
                }
            }
        })

    aci = ACIModule(module)
    aci.construct_url(root_class={
        'aci_class':
        'fvTenant',
        'aci_rn':
        'tn-{0}'.format(tenant),
        'target_filter':
        'eq(fvTenant.name, "{0}")'.format(tenant),
        'module_object':
        tenant
    },
                      subclass_1={
                          'aci_class': 'cloudApp',
                          'aci_rn': 'cloudapp-{0}'.format(ap),
                          'target_filter':
                          'eq(cloudApp.name, "{0}")'.format(ap),
                          'module_object': ap
                      },
                      subclass_2={
                          'aci_class': 'cloudEPg',
                          'aci_rn': 'cloudepg-{0}'.format(name),
                          'target_filter':
                          'eq(cloudEPg.name, "{0}")'.format(name),
                          'module_object': name
                      },
                      child_classes=['cloudRsCloudEPgCtx'])

    aci.get_existing()

    if state == 'present':
        aci.payload(aci_class='cloudEPg',
                    class_config={
                        'descr': description,
                        'name': name,
                    },
                    child_configs=child_configs)

        aci.get_diff(aci_class='cloudEPg')

        aci.post_config()

    elif state == 'absent':
        aci.delete_config()

    aci.exit_json()
コード例 #5
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(
        allow_useg=dict(type='str', choices=['encap', 'useg']),
        ap=dict(type='str',
                aliases=['app_profile', 'app_profile_name'
                         ]),  # Not required for querying all objects
        deploy_immediacy=dict(type='str', choices=['immediate', 'lazy']),
        domain=dict(type='str',
                    aliases=['domain_name', 'domain_profile'
                             ]),  # Not required for querying all objects
        domain_type=dict(type='str',
                         choices=['l2dom', 'phys', 'vmm'],
                         aliases=['type'
                                  ]),  # Not required for querying all objects
        encap=dict(type='int'),
        encap_mode=dict(type='str', choices=['auto', 'vlan', 'vxlan']),
        switching_mode=dict(type='str',
                            default='native',
                            choices=['AVE', 'native']),
        epg=dict(type='str',
                 aliases=['name', 'epg_name'
                          ]),  # Not required for querying all objects
        netflow=dict(type='bool'),
        primary_encap=dict(type='int'),
        resolution_immediacy=dict(
            type='str', choices=['immediate', 'lazy', 'pre-provision']),
        state=dict(type='str',
                   default='present',
                   choices=['absent', 'present', 'query']),
        tenant=dict(type='str',
                    aliases=['tenant_name'
                             ]),  # Not required for querying all objects
        vm_provider=dict(type='str',
                         choices=[
                             'cloudfoundry', 'kubernetes', 'microsoft',
                             'openshift', 'openstack', 'redhat', 'vmware'
                         ]),
        promiscuous=dict(type='str',
                         default='reject',
                         choices=['accept', 'reject']),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ['domain_type', 'vmm', ['vm_provider']],
            [
                'state', 'absent',
                ['ap', 'domain', 'domain_type', 'epg', 'tenant']
            ],
            [
                'state', 'present',
                ['ap', 'domain', 'domain_type', 'epg', 'tenant']
            ],
        ],
    )

    aci = ACIModule(module)

    allow_useg = module.params.get('allow_useg')
    ap = module.params.get('ap')
    deploy_immediacy = module.params.get('deploy_immediacy')
    domain = module.params.get('domain')
    domain_type = module.params.get('domain_type')
    vm_provider = module.params.get('vm_provider')
    promiscuous = module.params.get('promiscuous')
    encap = module.params.get('encap')
    if encap is not None:
        if encap in range(1, 4097):
            encap = 'vlan-{0}'.format(encap)
        else:
            module.fail_json(msg='Valid VLAN assignments are from 1 to 4096')
    encap_mode = module.params.get('encap_mode')
    switching_mode = module.params.get('switching_mode')
    epg = module.params.get('epg')
    netflow = aci.boolean(module.params.get('netflow'), 'enabled', 'disabled')
    primary_encap = module.params.get('primary_encap')
    if primary_encap is not None:
        if primary_encap in range(1, 4097):
            primary_encap = 'vlan-{0}'.format(primary_encap)
        else:
            module.fail_json(msg='Valid VLAN assignments are from 1 to 4096')
    resolution_immediacy = module.params.get('resolution_immediacy')
    state = module.params.get('state')
    tenant = module.params.get('tenant')

    if domain_type in ['l2dom', 'phys'] and vm_provider is not None:
        module.fail_json(msg="Domain type '%s' cannot have a 'vm_provider'" %
                         domain_type)

    # Compile the full domain for URL building
    if domain_type == 'vmm':
        epg_domain = 'uni/vmmp-{0}/dom-{1}'.format(
            VM_PROVIDER_MAPPING[vm_provider], domain)
    elif domain_type == 'l2dom':
        epg_domain = 'uni/l2dom-{0}'.format(domain)
    elif domain_type == 'phys':
        epg_domain = 'uni/phys-{0}'.format(domain)
    else:
        epg_domain = None

    child_configs = [
        dict(vmmSecP=dict(attributes=dict(allowPromiscuous=promiscuous, ), ), )
    ]

    aci.construct_url(
        root_class=dict(
            aci_class='fvTenant',
            aci_rn='tn-{0}'.format(tenant),
            module_object=tenant,
            target_filter={'name': tenant},
        ),
        subclass_1=dict(
            aci_class='fvAp',
            aci_rn='ap-{0}'.format(ap),
            module_object=ap,
            target_filter={'name': ap},
        ),
        subclass_2=dict(
            aci_class='fvAEPg',
            aci_rn='epg-{0}'.format(epg),
            module_object=epg,
            target_filter={'name': epg},
        ),
        subclass_3=dict(
            aci_class='fvRsDomAtt',
            aci_rn='rsdomAtt-[{0}]'.format(epg_domain),
            module_object=epg_domain,
            target_filter={'tDn': epg_domain},
        ),
        child_classes=['vmmSecP'],
    )

    aci.get_existing()

    if state == 'present':
        aci.payload(
            aci_class='fvRsDomAtt',
            class_config=dict(
                classPref=allow_useg,
                encap=encap,
                encapMode=encap_mode,
                switchingMode=switching_mode,
                instrImedcy=deploy_immediacy,
                netflowPref=netflow,
                primaryEncap=primary_encap,
                resImedcy=resolution_immediacy,
            ),
            child_configs=child_configs,
        )

        aci.get_diff(aci_class='fvRsDomAtt')

        aci.post_config()

    elif state == 'absent':
        aci.delete_config()

    aci.exit_json()
コード例 #6
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(
        arp_flooding=dict(type='bool'),
        bd=dict(type='str', aliases=['bd_name', 'name']),  # Not required for querying all objects
        bd_type=dict(type='str', choices=['ethernet', 'fc']),
        description=dict(type='str'),
        enable_multicast=dict(type='bool'),
        enable_routing=dict(type='bool'),
        endpoint_clear=dict(type='bool'),
        endpoint_move_detect=dict(type='str', choices=['default', 'garp']),
        endpoint_retention_action=dict(type='str', choices=['inherit', 'resolve']),
        endpoint_retention_policy=dict(type='str'),
        igmp_snoop_policy=dict(type='str'),
        ip_learning=dict(type='bool'),
        ipv6_nd_policy=dict(type='str'),
        l2_unknown_unicast=dict(type='str', choices=['proxy', 'flood']),
        l3_unknown_multicast=dict(type='str', choices=['flood', 'opt-flood']),
        limit_ip_learn=dict(type='bool'),
        mac_address=dict(type='str', aliases=['mac']),
        multi_dest=dict(type='str', choices=['bd-flood', 'drop', 'encap-flood']),
        state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
        tenant=dict(type='str', aliases=['tenant_name']),  # Not required for querying all objects
        vrf=dict(type='str', aliases=['vrf_name']),
        route_profile=dict(type='str'),
        route_profile_l3out=dict(type='str'),
        name_alias=dict(type='str'),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ['state', 'absent', ['bd', 'tenant']],
            ['state', 'present', ['bd', 'tenant']],
        ],
    )

    aci = ACIModule(module)

    arp_flooding = aci.boolean(module.params.get('arp_flooding'))
    bd = module.params.get('bd')
    bd_type = module.params.get('bd_type')
    if bd_type == 'ethernet':
        # ethernet type is represented as regular, but that is not clear to the users
        bd_type = 'regular'
    description = module.params.get('description')
    enable_multicast = aci.boolean(module.params.get('enable_multicast'))
    enable_routing = aci.boolean(module.params.get('enable_routing'))
    endpoint_clear = aci.boolean(module.params.get('endpoint_clear'))
    endpoint_move_detect = module.params.get('endpoint_move_detect')
    if endpoint_move_detect == 'default':
        # the ACI default setting is an empty string, but that is not a good input value
        endpoint_move_detect = ''
    endpoint_retention_action = module.params.get('endpoint_retention_action')
    endpoint_retention_policy = module.params.get('endpoint_retention_policy')
    igmp_snoop_policy = module.params.get('igmp_snoop_policy')
    ip_learning = aci.boolean(module.params.get('ip_learning'))
    ipv6_nd_policy = module.params.get('ipv6_nd_policy')
    l2_unknown_unicast = module.params.get('l2_unknown_unicast')
    l3_unknown_multicast = module.params.get('l3_unknown_multicast')
    limit_ip_learn = aci.boolean(module.params.get('limit_ip_learn'))
    mac_address = module.params.get('mac_address')
    multi_dest = module.params.get('multi_dest')
    state = module.params.get('state')
    tenant = module.params.get('tenant')
    vrf = module.params.get('vrf')
    route_profile = module.params.get('route_profile')
    route_profile_l3out = module.params.get('route_profile_l3out')
    name_alias = module.params.get('name_alias')

    aci.construct_url(
        root_class=dict(
            aci_class='fvTenant',
            aci_rn='tn-{0}'.format(tenant),
            module_object=tenant,
            target_filter={'name': tenant},
        ),
        subclass_1=dict(
            aci_class='fvBD',
            aci_rn='BD-{0}'.format(bd),
            module_object=bd,
            target_filter={'name': bd},
        ),
        child_classes=['fvRsCtx', 'fvRsIgmpsn', 'fvRsBDToNdP', 'fvRsBdToEpRet', 'fvRsBDToProfile'],
    )

    aci.get_existing()

    if state == 'present':
        aci.payload(
            aci_class='fvBD',
            class_config=dict(
                arpFlood=arp_flooding,
                descr=description,
                epClear=endpoint_clear,
                epMoveDetectMode=endpoint_move_detect,
                ipLearning=ip_learning,
                limitIpLearnToSubnets=limit_ip_learn,
                mac=mac_address,
                mcastAllow=enable_multicast,
                multiDstPktAct=multi_dest,
                name=bd,
                type=bd_type,
                unicastRoute=enable_routing,
                unkMacUcastAct=l2_unknown_unicast,
                unkMcastAct=l3_unknown_multicast,
                nameAlias=name_alias,
            ),
            child_configs=[
                {'fvRsCtx': {'attributes': {'tnFvCtxName': vrf}}},
                {'fvRsIgmpsn': {'attributes': {'tnIgmpSnoopPolName': igmp_snoop_policy}}},
                {'fvRsBDToNdP': {'attributes': {'tnNdIfPolName': ipv6_nd_policy}}},
                {'fvRsBdToEpRet': {'attributes': {'resolveAct': endpoint_retention_action, 'tnFvEpRetPolName': endpoint_retention_policy}}},
                {'fvRsBDToProfile': {'attributes': {'tnL3extOutName': route_profile_l3out, 'tnRtctrlProfileName': route_profile}}},
            ],
        )

        aci.get_diff(aci_class='fvBD')

        aci.post_config()

    elif state == 'absent':
        aci.delete_config()

    aci.exit_json()
コード例 #7
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(aci_annotation_spec())
    argument_spec.update(aci_owner_spec())
    argument_spec.update(
        tenant=dict(type="str",
                    aliases=["tenant_name"
                             ]),  # Not required for querying all objects
        destination_epg=dict(type="dict", options=destination_epg_spec()),
        destination_group=dict(type="str", aliases=[
            "name", "dst_group"
        ]),  # Not required for querying all objects
        description=dict(type="str", aliases=["descr"]),
        name_alias=dict(type="str"),
        source_ip=dict(type="str"),
        destination_ip=dict(type="str"),
        mtu=dict(type="int"),
        ttl=dict(type="int"),
        flow_id=dict(type="int"),
        version_enforced=dict(type="bool"),
        span_version=dict(type="str", choices=["version_1", "version_2"]),
        dscp=dict(type="str",
                  choices=[
                      "CS0", "CS1", "CS2", "CS3", "CS4", "CS5", "CS6", "CS7",
                      "EF", "VA", "AF11", "AF12", "AF13", "AF21", "AF22",
                      "AF23", "AF31", "AF32", "AF33", "AF41", "AF42", "AF43",
                      "unspecified"
                  ]),
        state=dict(type="str",
                   default="present",
                   choices=["absent", "present", "query"]),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ["state", "absent", ["destination_group", "tenant"]],
            [
                "state", "present",
                [
                    "destination_group", "destination_ip", "source_ip",
                    "destination_epg", "tenant"
                ]
            ],
        ],
    )

    aci = ACIModule(module)

    destination_epg = module.params.get("destination_epg")
    destination_group = module.params.get("destination_group")
    description = module.params.get("description")
    state = module.params.get("state")
    tenant = module.params.get("tenant")
    destination_ip = module.params.get("destination_ip")
    source_ip = module.params.get("source_ip")
    span_version = module.params.get("span_version")
    name_alias = module.params.get("name_alias")
    dscp = module.params.get("dscp")
    mtu = str(module.params.get("mtu"))
    ttl = str(module.params.get("ttl"))
    flow_id = str(module.params.get("flow_id"))
    version_enforced = module.params.get("version_enforced")

    aci.construct_url(
        root_class=dict(
            aci_class="fvTenant",
            aci_rn="tn-{0}".format(tenant),
            module_object=tenant,
            target_filter={"name": tenant},
        ),
        subclass_1=dict(
            aci_class="spanDestGrp",
            aci_rn="destgrp-{0}".format(destination_group),
            module_object=destination_group,
            target_filter={"name": destination_group},
        ),
        child_classes=["spanDest", "spanRsDestEpg"],
    )

    aci.get_existing()

    if state == "present":
        dest_tdn = "uni/tn-{0}/ap-{1}/epg-{2}".format(
            destination_epg["tenant"], destination_epg["ap"],
            destination_epg["epg"])

        if version_enforced is True:
            version_enforced = "yes"
        else:
            version_enforced = "no"

        if span_version == "version_1":
            span_version = "ver1"
        else:
            span_version = "ver2"

        child_configs = [
            dict(spanDest=dict(attributes=dict(name=destination_group),
                               children=[
                                   dict(spanRsDestEpg=dict(attributes=dict(
                                       ip=destination_ip,
                                       srcIpPrefix=source_ip,
                                       ver=span_version,
                                       verEnforced=version_enforced,
                                       ttl=ttl,
                                       mtu=mtu,
                                       flowId=flow_id,
                                       dscp=dscp,
                                       tDn=dest_tdn)))
                               ])),
        ]

        aci.payload(
            aci_class="spanDestGrp",
            class_config=dict(
                name=destination_group,
                descr=description,
                nameAlias=name_alias,
            ),
            child_configs=child_configs,
        )

        aci.get_diff(aci_class="spanDestGrp")

        aci.post_config()

    elif state == "absent":
        aci.delete_config()

    aci.exit_json()
コード例 #8
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(
        tenant=dict(type='str', aliases=['tenant_name']),
        l3out=dict(type='str', aliases=['l3out_name']),
        node_profile=dict(type='str',
                          aliases=['node_profile_name', 'logical_node']),
        interface_profile=dict(
            type='str',
            aliases=['name', 'interface_profile_name', 'logical_interface']),
        nd_policy=dict(type='str', default=''),
        egress_dpp_policy=dict(type='str', default=''),
        ingress_dpp_policy=dict(type='str', default=''),
        state=dict(type='str',
                   default='present',
                   choices=['absent', 'present', 'query']))

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[[
            'state', 'absent',
            ['tenant', 'l3out', 'node_profile', 'interface_profile']
        ],
                     [
                         'state', 'present',
                         [
                             'tenant', 'l3out', 'node_profile',
                             'interface_profile'
                         ]
                     ]])

    tenant = module.params.get('tenant')
    l3out = module.params.get('l3out')
    node_profile = module.params.get('node_profile')
    interface_profile = module.params.get('interface_profile')
    nd_policy = module.params.get('nd_policy')
    egress_dpp_policy = module.params.get('egress_dpp_policy')
    ingress_dpp_policy = module.params.get('ingress_dpp_policy')
    state = module.params.get('state')

    aci = ACIModule(module)

    aci.construct_url(root_class=dict(
        aci_class='fvTenant',
        aci_rn='tn-{0}'.format(tenant),
        module_object=tenant,
        target_filter={'name': tenant},
    ),
                      subclass_1=dict(
                          aci_class='l3extOut',
                          aci_rn='out-{0}'.format(l3out),
                          module_object=l3out,
                          target_filter={'name': l3out},
                      ),
                      subclass_2=dict(
                          aci_class='l3extLNodeP',
                          aci_rn='lnodep-{0}'.format(node_profile),
                          module_object=node_profile,
                          target_filter={'name': node_profile},
                      ),
                      subclass_3=dict(
                          aci_class='l3extLIfP',
                          aci_rn='lifp-[{0}]'.format(interface_profile),
                          module_object=interface_profile,
                          target_filter={'name': interface_profile},
                      ),
                      child_classes=[
                          'l3extRsNdIfPol', 'l3extRsIngressQosDppPol',
                          'l3extRsEgressQosDppPol'
                      ])

    aci.get_existing()

    if state == 'present':
        child_configs = [
            dict(l3extRsNdIfPol=dict(attributes=dict(
                tnNdIfPolName=nd_policy))),
            dict(l3extRsIngressQosDppPol=dict(attributes=dict(
                tnQosDppPolName=ingress_dpp_policy))),
            dict(l3extRsEgressQosDppPol=dict(attributes=dict(
                tnQosDppPolName=egress_dpp_policy)))
        ]
        aci.payload(aci_class='l3extLIfP',
                    class_config=dict(name=interface_profile),
                    child_configs=child_configs)

        aci.get_diff(aci_class='l3extLIfP')

        aci.post_config()

    elif state == 'absent':
        aci.delete_config()

    aci.exit_json()
コード例 #9
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(
        port_security=dict(
            type='str',
            aliases=['name']),  # Not required for querying all objects
        description=dict(type='str', aliases=['descr']),
        max_end_points=dict(type='int'),
        port_security_timeout=dict(type='int'),
        state=dict(type='str',
                   default='present',
                   choices=['absent', 'present', 'query']),
        name_alias=dict(type='str'),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ['state', 'absent', ['port_security']],
            ['state', 'present', ['port_security']],
        ],
    )

    port_security = module.params.get('port_security')
    description = module.params.get('description')
    max_end_points = module.params.get('max_end_points')
    port_security_timeout = module.params.get('port_security_timeout')
    name_alias = module.params.get('name_alias')
    if max_end_points is not None and max_end_points not in range(12001):
        module.fail_json(
            msg='The "max_end_points" must be between 0 and 12000')
    if port_security_timeout is not None and port_security_timeout not in range(
            60, 3601):
        module.fail_json(
            msg='The "port_security_timeout" must be between 60 and 3600')
    state = module.params.get('state')

    aci = ACIModule(module)
    aci.construct_url(root_class=dict(
        aci_class='l2PortSecurityPol',
        aci_rn='infra/portsecurityP-{0}'.format(port_security),
        module_object=port_security,
        target_filter={'name': port_security},
    ), )

    aci.get_existing()

    if state == 'present':
        aci.payload(
            aci_class='l2PortSecurityPol',
            class_config=dict(
                name=port_security,
                descr=description,
                maximum=max_end_points,
                nameAlias=name_alias,
            ),
        )

        aci.get_diff(aci_class='l2PortSecurityPol')

        aci.post_config()

    elif state == 'absent':
        aci.delete_config()

    aci.exit_json()
コード例 #10
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(aci_annotation_spec())
    argument_spec.update(
        name=dict(type="str", aliases=["syslog_group", "syslog_group_name"]),
        format=dict(type="str", choices=["aci", "nxos"]),
        admin_state=dict(type="str", choices=["enabled", "disabled"]),
        console_logging=dict(type="str", choices=["enabled", "disabled"]),
        console_log_severity=dict(type="str", choices=["alerts", "critical", "debugging", "emergencies", "error", "information", "notifications", "warnings"]),
        local_file_logging=dict(type="str", choices=["enabled", "disabled"]),
        local_file_log_severity=dict(
            type="str", choices=["alerts", "critical", "debugging", "emergencies", "error", "information", "notifications", "warnings"]
        ),
        include_ms=dict(type="bool"),
        include_time_zone=dict(type="bool"),
        state=dict(type="str", default="present", choices=["absent", "present", "query"]),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ["state", "absent", ["name"]],
            ["state", "present", ["name"]],
        ],
    )

    aci = ACIModule(module)

    name = module.params.get("name")
    format = module.params.get("format")
    admin_state = module.params.get("admin_state")
    console_logging = module.params.get("console_logging")
    console_log_severity = module.params.get("console_log_severity")
    local_file_logging = module.params.get("local_file_logging")
    local_file_log_severity = module.params.get("local_file_log_severity")
    include_ms = aci.boolean(module.params.get("include_ms"))
    include_time_zone = aci.boolean(module.params.get("include_time_zone"))
    state = module.params.get("state")

    aci.construct_url(
        root_class=dict(
            aci_class="syslogGroup",
            aci_rn="fabric/slgroup-{0}".format(name),
            module_object=name,
            target_filter={"name": name},
        ),
        child_classes=["syslogRemoteDest", "syslogProf", "syslogFile", "syslogConsole"],
    )

    aci.get_existing()

    if state == "present":
        class_config = dict(
            name=name,
            format=format,
            includeMilliSeconds=include_ms,
        )
        if include_time_zone is not None:
            class_config["includeTimeZone"] = include_time_zone
        aci.payload(
            aci_class="syslogGroup",
            class_config=class_config,
            child_configs=[
                dict(
                    syslogProf=dict(
                        attributes=dict(adminState=admin_state, name="syslog"),
                    ),
                ),
                dict(
                    syslogFile=dict(
                        attributes=dict(adminState=local_file_logging, format=format, severity=local_file_log_severity),
                    ),
                ),
                dict(
                    syslogConsole=dict(
                        attributes=dict(adminState=console_logging, format=format, severity=console_log_severity),
                    ),
                ),
            ],
        )

        aci.get_diff(aci_class="syslogGroup")

        aci.post_config()

    elif state == "absent":
        aci.delete_config()

    aci.exit_json()
コード例 #11
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(
        tenant=dict(type='str',
                    aliases=['tenant_name'
                             ]),  # Not required for querying all objects
        rtp=dict(type='str',
                 aliases=['name', 'rtp_name'
                          ]),  # Not required for querying all objects
        description=dict(type='str', aliases=['descr']),
        tag=dict(type='int'),
        state=dict(type='str',
                   default='present',
                   choices=['absent', 'present', 'query']),
        name_alias=dict(type='str'),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ['state', 'absent', ['rtp', 'tenant']],
            ['state', 'present', ['rtp', 'tenant']],
        ],
    )

    rtp = module.params.get('rtp')
    description = module.params.get('description')
    tag = module.params.get('tag')
    state = module.params.get('state')
    tenant = module.params.get('tenant')
    name_alias = module.params.get('name_alias')

    aci = ACIModule(module)
    aci.construct_url(
        root_class=dict(
            aci_class='fvTenant',
            aci_rn='tn-{0}'.format(tenant),
            module_object=tenant,
            target_filter={'name': tenant},
        ),
        subclass_1=dict(
            aci_class='l3extRouteTagPol',
            aci_rn='rttag-{0}'.format(rtp),
            module_object=rtp,
            target_filter={'name': rtp},
        ),
    )

    aci.get_existing()

    if state == 'present':
        aci.payload(
            aci_class='l3extRouteTagPol',
            class_config=dict(
                name=rtp,
                descr=description,
                tag=tag,
                nameAlias=name_alias,
            ),
        )

        aci.get_diff(aci_class='l3extRouteTagPol')

        aci.post_config()

    elif state == 'absent':
        aci.delete_config()

    aci.exit_json()
コード例 #12
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(
        contract=dict(type='str', aliases=['contract_name', 'name']),  # Not required for querying all objects
        tenant=dict(type='str', aliases=['tenant_name']),  # Not required for querying all objects
        description=dict(type='str', aliases=['descr']),
        scope=dict(type='str', choices=['application-profile', 'context', 'global', 'tenant']),
        priority=dict(type='str', choices=['level1', 'level2', 'level3', 'unspecified']),  # No default provided on purpose
        dscp=dict(type='str',
                  choices=['AF11', 'AF12', 'AF13', 'AF21', 'AF22', 'AF23', 'AF31', 'AF32', 'AF33', 'AF41', 'AF42', 'AF43',
                           'CS0', 'CS1', 'CS2', 'CS3', 'CS4', 'CS5', 'CS6', 'CS7', 'EF', 'VA', 'unspecified'],
                  aliases=['target']),  # No default provided on purpose
        state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
        name_alias=dict(type='str'),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ['state', 'absent', ['contract', 'tenant']],
            ['state', 'present', ['contract', 'tenant']],
        ],
    )

    contract = module.params.get('contract')
    description = module.params.get('description')
    scope = module.params.get('scope')
    priority = module.params.get('priority')
    dscp = module.params.get('dscp')
    state = module.params.get('state')
    tenant = module.params.get('tenant')
    name_alias = module.params.get('name_alias')

    aci = ACIModule(module)
    aci.construct_url(
        root_class=dict(
            aci_class='fvTenant',
            aci_rn='tn-{0}'.format(tenant),
            module_object=tenant,
            target_filter={'name': tenant},
        ),
        subclass_1=dict(
            aci_class='vzBrCP',
            aci_rn='brc-{0}'.format(contract),
            module_object=contract,
            target_filter={'name': contract},
        ),
    )

    aci.get_existing()

    if state == 'present':
        aci.payload(
            aci_class='vzBrCP',
            class_config=dict(
                name=contract,
                descr=description,
                scope=scope,
                prio=priority,
                targetDscp=dscp,
                nameAlias=name_alias,
            ),
        )

        aci.get_diff(aci_class='vzBrCP')

        aci.post_config()

    elif state == 'absent':
        aci.delete_config()

    aci.exit_json()
コード例 #13
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(
        name=dict(type='str',
                  aliases=['scheduler_name'
                           ]),  # Not required for querying all objects
        description=dict(type='str', aliases=['descr']),
        windowname=dict(type='str'),
        recurring=dict(type='bool'),
        concurCap=dict(
            type='int'),  # Number of devices it will run against concurrently
        maxTime=dict(
            type='str'
        ),  # The amount of minutes a process will be able to run (unlimited or dd:hh:mm:ss)
        date=dict(
            type='str'),  # The date the process will run YYYY-MM-DDTHH:MM:SS
        state=dict(type='str',
                   default='present',
                   choices=['absent', 'present', 'query']),
        hour=dict(type='int'),
        minute=dict(type='int'),
        day=dict(type='str',
                 default='every-day',
                 choices=[
                     'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday',
                     'Saturday', 'Sunday', 'every-day', 'even-day', 'odd-day'
                 ]),
        name_alias=dict(type='str'),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ['state', 'absent', ['name']],
            ['state', 'present', ['name']],
        ],
    )

    state = module.params.get('state')
    name = module.params.get('name')
    windowname = module.params.get('windowname')
    recurring = module.params.get('recurring')
    date = module.params.get('date')
    hour = module.params.get('hour')
    minute = module.params.get('minute')
    maxTime = module.params.get('maxTime')
    concurCap = module.params.get('concurCap')
    day = module.params.get('day')
    description = module.params.get('description')
    name_alias = module.params.get('name_alias')

    if recurring:
        child_configs = [
            dict(trigRecurrWindowP=dict(attributes=dict(
                name=windowname,
                hour=hour,
                minute=minute,
                procCa=maxTime,
                concurCap=concurCap,
                day=day,
            )))
        ]
    elif recurring is False:
        child_configs = [
            dict(trigAbsWindowP=dict(attributes=dict(
                name=windowname,
                procCap=maxTime,
                concurCap=concurCap,
                date=date,
            )))
        ]
    else:
        child_configs = []

    aci = ACIModule(module)
    aci.construct_url(root_class=dict(
        aci_class='trigSchedP',
        aci_rn='fabric/schedp-{0}'.format(name),
        target_filter={'name': name},
        module_object=name,
    ), )

    aci.get_existing()

    if state == 'present':
        aci.payload(
            aci_class='trigSchedP',
            class_config=dict(
                name=name,
                descr=description,
                nameAlias=name_alias,
            ),
            child_configs=child_configs,
        )

        aci.get_diff(aci_class='trigSchedP')

        aci.post_config()

    elif state == 'absent':
        aci.delete_config()

    aci.exit_json()
コード例 #14
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(aci_annotation_spec())
    argument_spec.update(aci_owner_spec())
    argument_spec.update(
        tenant=dict(type="str", required=True),
        cloud_context_profile=dict(type="str", required=True),
        state=dict(type="str",
                   default="query",
                   choices=["absent", "present", "query"]),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
    )

    tenant = module.params.get("tenant")
    cloud_context_profile = module.params.get("cloud_context_profile")
    state = module.params.get("state")
    child_configs = []

    aci = ACIModule(module)
    aci.construct_url(
        root_class=dict(
            aci_class="fvTenant",
            aci_rn="tn-{0}".format(tenant),
            target_filter='eq(fvTenant.name, "{0}")'.format(tenant),
            module_object=tenant),
        subclass_1=dict(
            aci_class="cloudCtxProfile",
            aci_rn="ctxprofile-{0}".format(cloud_context_profile),
            target_filter='eq(cloudCtxProfile.name, "{0}")'.format(
                cloud_context_profile),
            module_object=cloud_context_profile,
        ),
        subclass_2=dict(aci_class="cloudRouterP",
                        aci_rn="routerp-default",
                        target_filter='eq(cloudRouterP.name, "default")',
                        module_object="default"),
        child_classes=[
            "cloudRsToVpnGwPol", "cloudRsToHostRouterPol", "cloudIntNetworkP"
        ],
    )

    aci.get_existing()

    if state == "present":
        child_configs.append(
            dict(cloudIntNetworkP=dict(attributes=dict(name="default"))))
        aci.payload(aci_class="cloudRouterP",
                    class_config=dict(name="default"),
                    child_configs=child_configs)

        aci.get_diff(aci_class="cloudRouterP")
        aci.post_config()

    elif state == "absent":
        aci.delete_config()

    aci.exit_json()
コード例 #15
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(
        epg=dict(type='str', aliases=['epg_name', 'name']),  # Not required for querying all objects
        bd=dict(type='str', aliases=['bd_name', 'bridge_domain']),
        ap=dict(type='str', aliases=['app_profile', 'app_profile_name']),  # Not required for querying all objects
        tenant=dict(type='str', aliases=['tenant_name']),  # Not required for querying all objects
        description=dict(type='str', aliases=['descr']),
        priority=dict(type='str', choices=['level1', 'level2', 'level3', 'unspecified']),
        intra_epg_isolation=dict(choices=['enforced', 'unenforced']),
        fwd_control=dict(type='str', choices=['none', 'proxy-arp']),
        preferred_group=dict(type='bool'),
        state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
        name_alias=dict(type='str'),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ['state', 'absent', ['ap', 'epg', 'tenant']],
            ['state', 'present', ['ap', 'epg', 'tenant']],
        ],
    )

    aci = ACIModule(module)

    epg = module.params.get('epg')
    bd = module.params.get('bd')
    description = module.params.get('description')
    priority = module.params.get('priority')
    intra_epg_isolation = module.params.get('intra_epg_isolation')
    fwd_control = module.params.get('fwd_control')
    preferred_group = aci.boolean(module.params.get('preferred_group'), 'include', 'exclude')
    state = module.params.get('state')
    tenant = module.params.get('tenant')
    ap = module.params.get('ap')
    name_alias = module.params.get('name_alias')

    aci.construct_url(
        root_class=dict(
            aci_class='fvTenant',
            aci_rn='tn-{0}'.format(tenant),
            module_object=tenant,
            target_filter={'name': tenant},
        ),
        subclass_1=dict(
            aci_class='fvAp',
            aci_rn='ap-{0}'.format(ap),
            module_object=ap,
            target_filter={'name': ap},
        ),
        subclass_2=dict(
            aci_class='fvAEPg',
            aci_rn='epg-{0}'.format(epg),
            module_object=epg,
            target_filter={'name': epg},
        ),
        child_classes=['fvRsBd'],
    )

    aci.get_existing()

    if state == 'present':
        aci.payload(
            aci_class='fvAEPg',
            class_config=dict(
                name=epg,
                descr=description,
                prio=priority,
                pcEnfPref=intra_epg_isolation,
                fwdCtrl=fwd_control,
                prefGrMemb=preferred_group,
                nameAlias=name_alias,
            ),
            child_configs=[dict(
                fvRsBd=dict(
                    attributes=dict(
                        tnFvBDName=bd,
                    ),
                ),
            )],
        )

        aci.get_diff(aci_class='fvAEPg')

        aci.post_config()

    elif state == 'absent':
        aci.delete_config()

    aci.exit_json()
コード例 #16
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(aci_annotation_spec())
    argument_spec.update(aci_owner_spec())
    argument_spec.update(
        profile=dict(type="str", aliases=["spine_profile", "spine_switch_profile"]),
        name=dict(type="str", aliases=["association_name", "switch_association"]),
        policy_group=dict(type="str"),
        description=dict(type='str', aliases=['descr']),
        state=dict(type="str", default="present", choices=["absent", "present", "query"]),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ["state", "absent", ["profile", "name"]],
            ["state", "present", ["profile", "name"]],
        ],
    )

    aci = ACIModule(module)

    profile = module.params.get("profile")
    name = module.params.get("name")
    policy_group = module.params.get("policy_group")
    description = module.params.get('description')
    state = module.params.get("state")
    child_classes = ["fabricRsSpNodePGrp", "fabricNodeBlk"]

    aci.construct_url(
        root_class=dict(
            aci_class="fabricSpineP",
            aci_rn="fabric/spprof-{0}".format(profile),
            module_object=profile,
            target_filter={"name": profile},
        ),
        subclass_1=dict(
            aci_class="fabricSpineS",
            aci_rn="spines-{0}-typ-range".format(name),
            module_object=name,
            target_filter={"name": name},
        ),
        child_classes=child_classes,
    )

    aci.get_existing()

    if state == "present":
        child_configs = []
        if policy_group:
            tDn = "uni/fabric/funcprof/spnodepgrp-{0}".format(policy_group)
            child_configs.append(dict(fabricRsSpNodePGrp=dict(attributes=dict(tDn=tDn))))
        aci.payload(
            aci_class="fabricSpineS",
            class_config=dict(name=name, descr=description),
            child_configs=child_configs,
        )

        aci.get_diff(aci_class="fabricSpineS")

        aci.post_config()

    elif state == "absent":
        aci.delete_config()

    aci.exit_json()
コード例 #17
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(
        tenant=dict(type='str',
                    aliases=['tenant_name'
                             ]),  # Not required for querying all objects
        l3out=dict(type='str',
                   aliases=['l3out_name'
                            ]),  # Not required for querying all objects
        extepg=dict(type='str',
                    aliases=['extepg_name',
                             'name']),  # Not required for querying all objects
        network=dict(type='str', aliases=['address', 'ip']),
        description=dict(type='str', aliases=['descr']),
        subnet_name=dict(type='str', aliases=['name']),
        scope=dict(type='list',
                   choices=[
                       'export-rtctrl', 'import-security', 'shared-rtctrl',
                       'shared-security'
                   ]),
        state=dict(type='str',
                   default='present',
                   choices=['absent', 'present', 'query']),
        name_alias=dict(type='str'),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ['state', 'present', ['network']],
            ['state', 'absent', ['network']],
        ],
    )

    aci = ACIModule(module)

    tenant = module.params.get('tenant')
    l3out = module.params.get('l3out')
    extepg = module.params.get('extepg')
    network = module.params.get('network')
    description = module.params.get('description')
    subnet_name = module.params.get('subnet_name')
    scope = ','.join(sorted(module.params.get('scope')))
    state = module.params.get('state')
    name_alias = module.params.get('name_alias')

    aci.construct_url(
        root_class=dict(
            aci_class='fvTenant',
            aci_rn='tn-{0}'.format(tenant),
            module_object=tenant,
            target_filter={'name': tenant},
        ),
        subclass_1=dict(
            aci_class='l3extOut',
            aci_rn='out-{0}'.format(l3out),
            module_object=l3out,
            target_filter={'name': l3out},
        ),
        subclass_2=dict(
            aci_class='l3extInstP',
            aci_rn='instP-{0}'.format(extepg),
            module_object=extepg,
            target_filter={'name': extepg},
        ),
        subclass_3=dict(
            aci_class='l3extSubnet',
            aci_rn='extsubnet-[{0}]'.format(network),
            module_object=network,
            target_filter={'name': network},
        ),
    )

    aci.get_existing()

    if state == 'present':
        aci.payload(
            aci_class='l3extSubnet',
            class_config=dict(
                ip=network,
                descr=description,
                name=subnet_name,
                scope=scope,
                nameAlias=name_alias,
            ),
        )

        aci.get_diff(aci_class='l3extSubnet')

        aci.post_config()

    elif state == 'absent':
        aci.delete_config()

    aci.exit_json()
コード例 #18
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(aci_annotation_spec())
    argument_spec.update(aci_owner_spec())
    argument_spec.update(
        description=dict(
            type="str",
        ),
        name=dict(type="str", aliases=["cloud_context_profile"]),
        name_alias=dict(
            type="str",
        ),
        tenant=dict(
            type="str",
        ),
        state=dict(type="str", default="present", choices=["absent", "present", "query"]),
        primary_cidr=dict(
            type="str",
        ),
        # FIXME: didn't find the flow_log in UI
        # flow_log=dict(type='str'),
        vrf=dict(type="str"),
        region=dict(type="str"),
        cloud=dict(type="str", choices=["aws", "azure"]),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ["state", "absent", ["name", "tenant"]],
            ["state", "present", ["name", "tenant", "vrf", "region", "primary_cidr", "cloud"]],
        ],
    )

    description = module.params.get("description")
    name = module.params.get("name")
    name_alias = module.params.get("name_alias")
    tenant = module.params.get("tenant")
    state = module.params.get("state")
    primary_cidr = module.params.get("primary_cidr")
    child_configs = []

    vrf = module.params.get("vrf")
    region = module.params.get("region")
    cloud = module.params.get("cloud")

    aci = ACIModule(module)
    aci.construct_url(
        root_class=dict(aci_class="fvTenant", aci_rn="tn-{0}".format(tenant), target_filter='eq(fvTenant.name, "{0}")'.format(tenant), module_object=tenant),
        subclass_1=dict(
            aci_class="cloudCtxProfile", aci_rn="ctxprofile-{0}".format(name), target_filter='eq(cloudCtxProfile.name, "{0}")'.format(name), module_object=name
        ),
        child_classes=["cloudRsToCtx", "cloudRsCtxProfileToRegion", "cloudRouterP", "cloudCidr"],
    )

    aci.get_existing()

    if state == "present":
        child_configs.append(dict(cloudRsToCtx=dict(attributes=dict(tnFvCtxName=vrf))))
        child_configs.append(dict(cloudRsCtxProfileToRegion=dict(attributes=dict(tDn="uni/clouddomp/provp-{0}/region-{1}".format(cloud, region)))))
        child_configs.append(dict(cloudCidr=dict(attributes=dict(addr=primary_cidr, primary="yes"))))
        aci.payload(
            aci_class="cloudCtxProfile",
            class_config=dict(
                descr=description,
                name=name,
                name_alias=name_alias,
                type="regular",
            ),
            child_configs=child_configs,
        )

        aci.get_diff(aci_class="cloudCtxProfile")
        aci.post_config()

    elif state == "absent":
        aci.delete_config()

    aci.exit_json()
コード例 #19
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(aci_annotation_spec())
    argument_spec.update(
        allow_useg=dict(type="str", choices=["encap", "useg"]),
        ap=dict(type="str",
                aliases=["app_profile", "app_profile_name"
                         ]),  # Not required for querying all objects
        deploy_immediacy=dict(type="str", choices=["immediate", "lazy"]),
        domain=dict(type="str",
                    aliases=["domain_name", "domain_profile"
                             ]),  # Not required for querying all objects
        domain_type=dict(type="str",
                         choices=["l2dom", "phys", "vmm"],
                         aliases=["type"
                                  ]),  # Not required for querying all objects
        encap=dict(type="int"),
        encap_mode=dict(type="str", choices=["auto", "vlan", "vxlan"]),
        switching_mode=dict(type="str",
                            default="native",
                            choices=["AVE", "native"]),
        epg=dict(type="str",
                 aliases=["name", "epg_name"
                          ]),  # Not required for querying all objects
        enhanced_lag_policy=dict(type="str", aliases=["lag_policy"]),
        netflow=dict(type="bool"),
        primary_encap=dict(type="int"),
        resolution_immediacy=dict(
            type="str", choices=["immediate", "lazy", "pre-provision"]),
        state=dict(type="str",
                   default="present",
                   choices=["absent", "present", "query"]),
        tenant=dict(type="str",
                    aliases=["tenant_name"
                             ]),  # Not required for querying all objects
        vm_provider=dict(type="str",
                         choices=[
                             "cloudfoundry", "kubernetes", "microsoft",
                             "openshift", "openstack", "redhat", "vmware"
                         ]),
        promiscuous=dict(type="str",
                         default="reject",
                         choices=["accept", "reject"]),
        custom_epg_name=dict(type="str"),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ["domain_type", "vmm", ["vm_provider"]],
            [
                "state", "absent",
                ["ap", "domain", "domain_type", "epg", "tenant"]
            ],
            [
                "state", "present",
                ["ap", "domain", "domain_type", "epg", "tenant"]
            ],
        ],
    )

    aci = ACIModule(module)

    allow_useg = module.params.get("allow_useg")
    ap = module.params.get("ap")
    deploy_immediacy = module.params.get("deploy_immediacy")
    domain = module.params.get("domain")
    domain_type = module.params.get("domain_type")
    vm_provider = module.params.get("vm_provider")
    promiscuous = module.params.get("promiscuous")
    custom_epg_name = module.params.get("custom_epg_name")
    encap = module.params.get("encap")
    if encap is not None:
        if encap in range(1, 4097):
            encap = "vlan-{0}".format(encap)
        else:
            module.fail_json(msg="Valid VLAN assignments are from 1 to 4096")
    encap_mode = module.params.get("encap_mode")
    switching_mode = module.params.get("switching_mode")
    epg = module.params.get("epg")
    enhanced_lag_policy = module.params.get("enhanced_lag_policy")
    netflow = aci.boolean(module.params.get("netflow"), "enabled", "disabled")
    primary_encap = module.params.get("primary_encap")
    if primary_encap is not None:
        if primary_encap in range(1, 4097):
            primary_encap = "vlan-{0}".format(primary_encap)
        else:
            module.fail_json(msg="Valid VLAN assignments are from 1 to 4096")
    resolution_immediacy = module.params.get("resolution_immediacy")
    state = module.params.get("state")
    tenant = module.params.get("tenant")

    if domain_type in ["l2dom", "phys"] and vm_provider is not None:
        module.fail_json(msg="Domain type '%s' cannot have a 'vm_provider'" %
                         domain_type)

    child_classes = None
    child_configs = None

    # Compile the full domain for URL building
    if domain_type == "vmm":
        epg_domain = "uni/vmmp-{0}/dom-{1}".format(
            VM_PROVIDER_MAPPING[vm_provider], domain)
        child_configs = [
            dict(vmmSecP=dict(attributes=dict(allowPromiscuous=promiscuous)))
        ]
        child_classes = ["vmmSecP"]

        if enhanced_lag_policy is not None:
            lag_policy = epg_domain + "/vswitchpolcont/enlacplagp-{0}".format(
                enhanced_lag_policy)
            child_configs.append(
                dict(fvAEPgLagPolAtt=dict(
                    attributes=dict(annotation=""),
                    children=[
                        dict(fvRsVmmVSwitchEnhancedLagPol=dict(
                            attributes=dict(annotation="", tDn=lag_policy)))
                    ])))
            child_classes.append("fvAEPgLagPolAtt")

    elif domain_type == "l2dom":
        epg_domain = "uni/l2dom-{0}".format(domain)
    elif domain_type == "phys":
        epg_domain = "uni/phys-{0}".format(domain)
    else:
        epg_domain = None

    aci.construct_url(
        root_class=dict(
            aci_class="fvTenant",
            aci_rn="tn-{0}".format(tenant),
            module_object=tenant,
            target_filter={"name": tenant},
        ),
        subclass_1=dict(
            aci_class="fvAp",
            aci_rn="ap-{0}".format(ap),
            module_object=ap,
            target_filter={"name": ap},
        ),
        subclass_2=dict(
            aci_class="fvAEPg",
            aci_rn="epg-{0}".format(epg),
            module_object=epg,
            target_filter={"name": epg},
        ),
        subclass_3=dict(
            aci_class="fvRsDomAtt",
            aci_rn="rsdomAtt-[{0}]".format(epg_domain),
            module_object=epg_domain,
            target_filter={"tDn": epg_domain},
        ),
        child_classes=child_classes,
    )

    aci.get_existing()

    if state == "present":
        aci.payload(
            aci_class="fvRsDomAtt",
            class_config=dict(
                classPref=allow_useg,
                encap=encap,
                encapMode=encap_mode,
                switchingMode=switching_mode,
                instrImedcy=deploy_immediacy,
                netflowPref=netflow,
                primaryEncap=primary_encap,
                resImedcy=resolution_immediacy,
                customEpgName=custom_epg_name,
            ),
            child_configs=child_configs,
        )

        aci.get_diff(aci_class="fvRsDomAtt")

        aci.post_config()

    elif state == "absent":
        aci.delete_config()

    aci.exit_json()
コード例 #20
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(
        tenant=dict(type="str", aliases=["tenant_name"]),
        l3out=dict(type="str", aliases=["l3out_name"]),
        node_profile=dict(type="str",
                          aliases=["node_profile_name", "logical_node"]),
        interface_profile=dict(
            type="str",
            aliases=["interface_profile_name", "logical_interface"]),
        state=dict(type="str",
                   default="present",
                   choices=["absent", "present", "query"]),
        pod_id=dict(type="str"),
        node_id=dict(type="str"),
        path_ep=dict(type="str"),
        side=dict(type="str", choices=["A", "B"]),
        address=dict(type="str", aliases=["addr", "ip_address"]),
        ipv6_dad=dict(type="str", choices=["enabled", "disabled"]),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            [
                "state",
                "absent",
                [
                    "tenant",
                    "l3out",
                    "node_profile",
                    "interface_profile",
                    "pod_id",
                    "node_id",
                    "path_ep",
                ],
            ],
            [
                "state",
                "present",
                [
                    "tenant",
                    "l3out",
                    "node_profile",
                    "interface_profile",
                    "pod_id",
                    "node_id",
                    "path_ep",
                ],
            ],
        ],
    )

    tenant = module.params.get("tenant")
    l3out = module.params.get("l3out")
    node_profile = module.params.get("node_profile")
    interface_profile = module.params.get("interface_profile")
    pod_id = module.params.get("pod_id")
    node_id = module.params.get("node_id")
    path_ep = module.params.get("path_ep")
    side = module.params.get("side")
    address = module.params.get("address")
    ipv6_dad = module.params.get("ipv6_dad")
    state = module.params.get("state")

    aci = ACIModule(module)

    path_type = "paths"
    rn_prefix = ""

    if node_id:
        if "-" in node_id:
            path_type = "protpaths"
            rn_prefix = "mem-{0}/".format(side)

    path_dn = None
    if pod_id and node_id and path_ep:
        path_dn = "topology/pod-{0}/{1}-{2}/pathep-[{3}]".format(
            pod_id, path_type, node_id, path_ep)

    aci.construct_url(
        root_class=dict(
            aci_class="fvTenant",
            aci_rn="tn-{0}".format(tenant),
            module_object=tenant,
            target_filter={"name": tenant},
        ),
        subclass_1=dict(
            aci_class="l3extOut",
            aci_rn="out-{0}".format(l3out),
            module_object=l3out,
            target_filter={"name": l3out},
        ),
        subclass_2=dict(
            aci_class="l3extLNodeP",
            aci_rn="lnodep-{0}".format(node_profile),
            module_object=node_profile,
            target_filter={"name": node_profile},
        ),
        subclass_3=dict(
            aci_class="l3extLIfP",
            aci_rn="lifp-{0}".format(interface_profile),
            module_object=interface_profile,
            target_filter={"name": interface_profile},
        ),
        subclass_4=dict(
            aci_class="l3extRsPathL3OutAtt",
            aci_rn="rspathL3OutAtt-[{0}]".format(path_dn),
            module_object=path_dn,
            target_filter={"tDn": path_dn},
        ),
        subclass_5=dict(
            aci_class="l3extIp",
            aci_rn="{0}addr-[{1}]".format(rn_prefix, address),
            module_object=address,
            target_filter={"addr": address},
        ),
    )

    aci.get_existing()

    if state == "present":
        aci.payload(aci_class="l3extIp",
                    class_config=dict(addr=address, ipv6Dad=ipv6_dad))

        aci.get_diff(aci_class="l3extIp")
        aci.post_config()

    elif state == "absent":
        aci.delete_config()

    aci.exit_json()
コード例 #21
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(aci_annotation_spec())
    argument_spec.update(aci_owner_spec())
    argument_spec.update(
        arp_flooding=dict(type="bool"),
        bd=dict(type="str",
                aliases=["bd_name",
                         "name"]),  # Not required for querying all objects
        bd_type=dict(type="str", choices=["ethernet", "fc"]),
        description=dict(type="str"),
        enable_multicast=dict(type="bool"),
        enable_routing=dict(type="bool"),
        endpoint_clear=dict(type="bool"),
        endpoint_move_detect=dict(type="str", choices=["default", "garp"]),
        endpoint_retention_action=dict(type="str",
                                       choices=["inherit", "resolve"]),
        endpoint_retention_policy=dict(type="str"),
        igmp_snoop_policy=dict(type="str"),
        ip_learning=dict(type="bool"),
        ipv6_nd_policy=dict(type="str"),
        l2_unknown_unicast=dict(type="str", choices=["proxy", "flood"]),
        l3_unknown_multicast=dict(type="str", choices=["flood", "opt-flood"]),
        ipv6_l3_unknown_multicast=dict(type="str",
                                       choices=["flood", "opt-flood"]),
        limit_ip_learn=dict(type="bool"),
        mac_address=dict(type="str", aliases=["mac"]),
        multi_dest=dict(type="str",
                        choices=["bd-flood", "drop", "encap-flood"]),
        state=dict(type="str",
                   default="present",
                   choices=["absent", "present", "query"]),
        tenant=dict(type="str",
                    aliases=["tenant_name"
                             ]),  # Not required for querying all objects
        vrf=dict(type="str", aliases=["vrf_name"]),
        route_profile=dict(type="str"),
        route_profile_l3out=dict(type="str"),
        name_alias=dict(type="str"),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ["state", "absent", ["bd", "tenant"]],
            ["state", "present", ["bd", "tenant"]],
        ],
    )

    aci = ACIModule(module)

    arp_flooding = aci.boolean(module.params.get("arp_flooding"))
    bd = module.params.get("bd")
    bd_type = module.params.get("bd_type")
    if bd_type == "ethernet":
        # ethernet type is represented as regular, but that is not clear to the users
        bd_type = "regular"
    description = module.params.get("description")
    enable_multicast = aci.boolean(module.params.get("enable_multicast"))
    enable_routing = aci.boolean(module.params.get("enable_routing"))
    endpoint_clear = aci.boolean(module.params.get("endpoint_clear"))
    endpoint_move_detect = module.params.get("endpoint_move_detect")
    if endpoint_move_detect == "default":
        # the ACI default setting is an empty string, but that is not a good input value
        endpoint_move_detect = ""
    endpoint_retention_action = module.params.get("endpoint_retention_action")
    endpoint_retention_policy = module.params.get("endpoint_retention_policy")
    igmp_snoop_policy = module.params.get("igmp_snoop_policy")
    ip_learning = aci.boolean(module.params.get("ip_learning"))
    ipv6_nd_policy = module.params.get("ipv6_nd_policy")
    l2_unknown_unicast = module.params.get("l2_unknown_unicast")
    l3_unknown_multicast = module.params.get("l3_unknown_multicast")
    ipv6_l3_unknown_multicast = module.params.get("ipv6_l3_unknown_multicast")
    limit_ip_learn = aci.boolean(module.params.get("limit_ip_learn"))
    mac_address = module.params.get("mac_address")
    multi_dest = module.params.get("multi_dest")
    state = module.params.get("state")
    tenant = module.params.get("tenant")
    vrf = module.params.get("vrf")
    route_profile = module.params.get("route_profile")
    route_profile_l3out = module.params.get("route_profile_l3out")
    name_alias = module.params.get("name_alias")

    aci.construct_url(
        root_class=dict(
            aci_class="fvTenant",
            aci_rn="tn-{0}".format(tenant),
            module_object=tenant,
            target_filter={"name": tenant},
        ),
        subclass_1=dict(
            aci_class="fvBD",
            aci_rn="BD-{0}".format(bd),
            module_object=bd,
            target_filter={"name": bd},
        ),
        child_classes=[
            "fvRsCtx", "fvRsIgmpsn", "fvRsBDToNdP", "fvRsBdToEpRet",
            "fvRsBDToProfile"
        ],
    )

    aci.get_existing()

    if state == "present":
        class_config = dict(
            arpFlood=arp_flooding,
            descr=description,
            epClear=endpoint_clear,
            epMoveDetectMode=endpoint_move_detect,
            ipLearning=ip_learning,
            limitIpLearnToSubnets=limit_ip_learn,
            mac=mac_address,
            mcastAllow=enable_multicast,
            multiDstPktAct=multi_dest,
            name=bd,
            type=bd_type,
            unicastRoute=enable_routing,
            unkMacUcastAct=l2_unknown_unicast,
            unkMcastAct=l3_unknown_multicast,
            nameAlias=name_alias,
        )

        if ipv6_l3_unknown_multicast is not None:
            class_config["v6unkMcastAct"] = ipv6_l3_unknown_multicast

        aci.payload(
            aci_class="fvBD",
            class_config=class_config,
            child_configs=[
                {
                    "fvRsCtx": {
                        "attributes": {
                            "tnFvCtxName": vrf
                        }
                    }
                },
                {
                    "fvRsIgmpsn": {
                        "attributes": {
                            "tnIgmpSnoopPolName": igmp_snoop_policy
                        }
                    }
                },
                {
                    "fvRsBDToNdP": {
                        "attributes": {
                            "tnNdIfPolName": ipv6_nd_policy
                        }
                    }
                },
                {
                    "fvRsBdToEpRet": {
                        "attributes": {
                            "resolveAct": endpoint_retention_action,
                            "tnFvEpRetPolName": endpoint_retention_policy
                        }
                    }
                },
                {
                    "fvRsBDToProfile": {
                        "attributes": {
                            "tnL3extOutName": route_profile_l3out,
                            "tnRtctrlProfileName": route_profile
                        }
                    }
                },
            ],
        )

        aci.get_diff(aci_class="fvBD")

        aci.post_config()

    elif state == "absent":
        aci.delete_config()

    aci.exit_json()
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(
        leaf_profile=dict(type='str',
                          aliases=['leaf_profile_name'
                                   ]),  # Not required for querying all objects
        interface_selector=dict(type='str',
                                aliases=[
                                    'interface_profile_name',
                                    'interface_selector_name', 'name'
                                ]),  # Not required for querying all objects
        state=dict(type='str',
                   default='present',
                   choices=['absent', 'present', 'query']))

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[[
            'state', 'absent', ['leaf_profile', 'interface_selector']
        ], ['state', 'present', ['leaf_profile', 'interface_selector']]],
    )

    leaf_profile = module.params.get('leaf_profile')
    # WARNING: interface_selector accepts non existing interface_profile names and they appear on APIC gui with a state of "missing-target"
    interface_selector = module.params.get('interface_selector')
    state = module.params.get('state')

    # Defining the interface profile tDn for clarity
    interface_selector_tDn = 'uni/infra/accportprof-{0}'.format(
        interface_selector)

    aci = ACIModule(module)
    aci.construct_url(
        root_class=dict(
            aci_class='infraNodeP',
            aci_rn='infra/nprof-{0}'.format(leaf_profile),
            module_object=leaf_profile,
            target_filter={'name': leaf_profile},
        ),
        subclass_1=dict(
            aci_class='infraRsAccPortP',
            aci_rn='rsaccPortP-[{0}]'.format(interface_selector_tDn),
            module_object=interface_selector,
            target_filter={'name': interface_selector},
        ))

    aci.get_existing()

    if state == 'present':
        aci.payload(
            aci_class='infraRsAccPortP',
            class_config=dict(tDn=interface_selector_tDn),
        )

        aci.get_diff(aci_class='infraRsAccPortP')

        aci.post_config()

    elif state == 'absent':
        aci.delete_config()

    aci.exit_json()
コード例 #23
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(
        lldp_policy=dict(type='str',
                         aliases=['name'
                                  ]),  # Not required for querying all objects
        description=dict(type='str', aliases=['descr']),
        receive_state=dict(type='bool'),
        transmit_state=dict(type='bool'),
        state=dict(type='str',
                   default='present',
                   choices=['absent', 'present', 'query']),
        name_alias=dict(type='str'),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ['state', 'absent', ['lldp_policy']],
            ['state', 'present', ['lldp_policy']],
        ],
    )

    aci = ACIModule(module)

    lldp_policy = module.params.get('lldp_policy')
    description = module.params.get('description')
    receive_state = aci.boolean(module.params.get('receive_state'), 'enabled',
                                'disabled')
    transmit_state = aci.boolean(module.params.get('transmit_state'),
                                 'enabled', 'disabled')
    state = module.params.get('state')
    name_alias = module.params.get('name_alias')

    aci.construct_url(root_class=dict(
        aci_class='lldpIfPol',
        aci_rn='infra/lldpIfP-{0}'.format(lldp_policy),
        module_object=lldp_policy,
        target_filter={'name': lldp_policy},
    ), )

    aci.get_existing()

    if state == 'present':
        aci.payload(
            aci_class='lldpIfPol',
            class_config=dict(
                name=lldp_policy,
                descr=description,
                adminRxSt=receive_state,
                adminTxSt=transmit_state,
                nameAlias=name_alias,
            ),
        )

        aci.get_diff(aci_class='lldpIfPol')

        aci.post_config()

    elif state == 'absent':
        aci.delete_config()

    aci.exit_json()
コード例 #24
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(
        tenant=dict(type='str', aliases=['tenant_name']),
        l3out=dict(type='str', aliases=['l3out_name']),
        node_profile=dict(type='str', aliases=[
                          'node_profile_name', 'logical_node']),
        pod_id=dict(type='int'),
        node_id=dict(type='int'),
        router_id=dict(type='str'),
        router_id_as_loopback=dict(
            type='str', default='yes', choices=['yes', 'no']),
        state=dict(type='str', default='present',
                   choices=['absent', 'present', 'query'])
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ['state', 'absent', ['tenant', 'l3out',
                                 'node_profile', 'pod_id', 'node_id']],
            ['state', 'present', ['tenant', 'l3out',
                                  'node_profile', 'pod_id', 'node_id']]
        ]
    )

    tenant = module.params.get('tenant')
    l3out = module.params.get('l3out')
    node_profile = module.params.get('node_profile')
    pod_id = module.params.get('pod_id')
    node_id = module.params.get('node_id')
    router_id = module.params.get('router_id')
    router_id_as_loopback = module.params.get('router_id_as_loopback')
    state = module.params.get('state')

    tdn = None
    if pod_id is not None and node_id is not None:
        tdn = 'topology/pod-{0}/node-{1}'.format(pod_id, node_id)

    aci = ACIModule(module)

    aci.construct_url(
        root_class=dict(
            aci_class='fvTenant',
            aci_rn='tn-{0}'.format(tenant),
            module_object=tenant,
            target_filter={'name': tenant},
        ),
        subclass_1=dict(
            aci_class='l3extOut',
            aci_rn='out-{0}'.format(l3out),
            module_object=l3out,
            target_filter={'name': l3out},
        ),
        subclass_2=dict(
            aci_class='l3extLNodeP',
            aci_rn='lnodep-{0}'.format(node_profile),
            module_object=node_profile,
            target_filter={'name': node_profile},
        ),
        subclass_3=dict(
            aci_class='l3extRsNodeL3OutAtt',
            aci_rn='rsnodeL3OutAtt-[{0}]'.format(tdn),
            module_object=tdn,
            target_filter={'name': tdn},
        )
    )

    aci.get_existing()

    if state == 'present':
        aci.payload(
            aci_class='l3extRsNodeL3OutAtt',
            class_config=dict(
                rtrId=router_id,
                rtrIdLoopBack=router_id_as_loopback,
                tDn=tdn
            )
        )

        aci.get_diff(aci_class='l3extRsNodeL3OutAtt')

        aci.post_config()

    elif state == 'absent':
        aci.delete_config()

    aci.exit_json()
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(
        tenant=dict(type='str',
                    aliases=['tenant_name'
                             ]),  # Not required for querying all objects
        l3out=dict(type='str',
                   aliases=['l3out_name'
                            ]),  # Not required for querying all objects
        logical_node=dict(type='str'),  # Not required for querying all objects
        logical_interface=dict(type='str'),
        path_dn=dict(type='str'),
        side=dict(type='str'),
        description=dict(type='str', aliases=['descr']),
        state=dict(type='str',
                   default='present',
                   choices=['absent', 'present', 'query']),
        name_alias=dict(type='str'),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            [
                'state', 'present',
                [
                    'side', 'path_dn', 'logical_interface', 'logical_node',
                    'l3out', 'tenant'
                ]
            ],
            [
                'state', 'absent',
                [
                    'side', 'path_dn', 'logical_interface', 'logical_node',
                    'l3out', 'tenant'
                ]
            ],
        ],
    )

    aci = ACIModule(module)

    tenant = module.params.get('tenant')
    l3out = module.params.get('l3out')
    logical_node = module.params.get('logical_node')
    logical_interface = module.params.get('logical_interface')
    path_dn = module.params.get('path_dn')
    side = module.params.get('side')
    description = module.params.get('description')
    state = module.params.get('state')
    name_alias = module.params.get('name_alias')

    aci.construct_url(
        root_class=dict(
            aci_class='fvTenant',
            aci_rn='tn-{0}'.format(tenant),
            module_object=tenant,
            target_filter={'name': tenant},
        ),
        subclass_1=dict(
            aci_class='l3extOut',
            aci_rn='out-{0}'.format(l3out),
            module_object=l3out,
            target_filter={'name': l3out},
        ),
        subclass_2=dict(
            aci_class='l3extLNodeP',
            aci_rn='lnodep-{0}'.format(logical_node),
            module_object=logical_node,
            target_filter={'name': logical_node},
        ),
        subclass_3=dict(
            aci_class='l3extLIfP',
            aci_rn='lifp-{0}'.format(logical_interface),
            module_object=logical_interface,
            target_filter={'name': logical_interface},
        ),
        subclass_4=dict(
            aci_class='l3extRsPathL3OutAtt',
            aci_rn='rspathL3OutAtt-[{0}]'.format(path_dn),
            module_object=path_dn,
            target_filter={'name': path_dn},
        ),
        subclass_5=dict(
            aci_class='l3extMember',
            aci_rn='mem-{0}'.format(side),
            module_object=side,
            target_filter={'name': side},
        ),
    )

    aci.get_existing()

    if state == 'present':
        aci.payload(
            aci_class='l3extMember',
            class_config=dict(
                name=side,
                descr=description,
                nameAlias=name_alias,
            ),
        )

        aci.get_diff(aci_class='l3extMember')

        aci.post_config()

    elif state == 'absent':
        aci.delete_config()

    aci.exit_json()
コード例 #26
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(  # See comments in aci_static_binding_to_epg module.
        tenant=dict(type='str', aliases=['tenant_name']),
        l2out=dict(type='str', aliases=['l2out_name']),
        node_profile=dict(type='str',
                          default='default',
                          aliases=['node_profile_name', 'logical_node']),
        interface_profile=dict(
            type='str',
            aliases=['name', 'interface_profile_name', 'logical_interface']),
        state=dict(type='str',
                   default='present',
                   choices=['absent', 'present', 'query']))

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[[
            'state', 'absent',
            ['tenant', 'l2out', 'node_profile', 'interface_profile']
        ],
                     [
                         'state', 'present',
                         [
                             'tenant', 'l2out', 'node_profile',
                             'interface_profile'
                         ]
                     ]])

    tenant = module.params.get('tenant')
    l2out = module.params.get('l2out')
    node_profile = module.params.get('node_profile')
    interface_profile = module.params.get('interface_profile')
    state = module.params.get('state')

    aci = ACIModule(module)

    aci.construct_url(
        root_class=dict(
            aci_class='fvTenant',
            aci_rn='tn-{0}'.format(tenant),
            module_object=tenant,
            target_filter={'name': tenant},
        ),
        subclass_1=dict(
            aci_class='l2extOut',
            aci_rn='l2out-{0}'.format(l2out),
            module_object=l2out,
            target_filter={'name': l2out},
        ),
        subclass_2=dict(
            aci_class='l2extLNodeP',
            aci_rn='lnodep-{0}'.format(node_profile),
            module_object=node_profile,
            target_filter={'name': node_profile},
        ),
        subclass_3=dict(
            aci_class='l2extLIfP',
            aci_rn='lifp-{0}'.format(interface_profile),
            module_object=interface_profile,
            target_filter={'name': interface_profile},
        ),
    )

    aci.get_existing()

    if state == 'present':
        # child_configs = []
        aci.payload(
            aci_class='l2extLIfP',
            class_config=dict(name=interface_profile),
            # child_configs=child_configs
        )

        aci.get_diff(aci_class='l2extLIfP')

        aci.post_config()

    elif state == 'absent':
        aci.delete_config()

    aci.exit_json()
コード例 #27
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(
        source=dict(type='str',
                    aliases=['name', 'source_name'
                             ]),  # Not required for querying all objects
        polling_interval=dict(type='int'),
        url=dict(type='str'),
        url_username=dict(type='str'),
        url_password=dict(type='str', no_log=True),
        url_protocol=dict(type='str',
                          default='scp',
                          choices=['http', 'local', 'scp', 'usbkey'],
                          aliases=['url_proto']),
        state=dict(type='str',
                   default='present',
                   choices=['absent', 'present', 'query']),
        name_alias=dict(type='str'),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ['state', 'absent', ['source']],
            ['state', 'present', ['url_protocol', 'source', 'url']],
        ],
    )

    polling_interval = module.params.get('polling_interval')
    url_protocol = module.params.get('url_protocol')
    state = module.params.get('state')
    source = module.params.get('source')
    url = module.params.get('url')
    url_password = module.params.get('url_password')
    url_username = module.params.get('url_username')
    name_alias = module.params.get('name_alias')

    aci = ACIModule(module)
    aci.construct_url(root_class=dict(
        aci_class='firmwareOSource',
        aci_rn='fabric/fwrepop',
        module_object=source,
        target_filter={'name': source},
    ), )
    aci.get_existing()

    if state == 'present':
        aci.payload(
            aci_class='firmwareOSource',
            class_config=dict(
                name=source,
                url=url,
                password=url_password,
                pollingInterval=polling_interval,
                proto=url_protocol,
                user=url_username,
                nameAlias=name_alias,
            ),
        )

        aci.get_diff(aci_class='firmwareOSource')

        aci.post_config()

    elif state == 'absent':
        aci.delete_config()

    aci.exit_json()
コード例 #28
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(
        name=dict(type='str', aliases=['snmp_policy', 'snmp_policy_name']),
        admin_state=dict(type='str', choices=['enabled', 'disabled']),
        contact=dict(type='str'),
        description=dict(type='str'),
        location=dict(type='str'),
        state=dict(type='str', default='present',
                   choices=['absent', 'present', 'query'])
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ['state', 'absent', ['name']],
            ['state', 'present', ['name']],
        ]
    )

    aci = ACIModule(module)

    name = module.params.get('name')
    admin_state = module.params.get('admin_state')
    contact = module.params.get('contact')
    description = module.params.get('description')
    location = module.params.get('location')
    state = module.params.get('state')

    aci.construct_url(
        root_class=dict(
            aci_class='snmpPol',
            aci_rn='fabric/snmppol-{0}'.format(name),
            module_object=name,
            target_filter={'name': name},
        ),
        child_classes=['snmpCommunityP', 'snmpClientGrpP'],
    )

    aci.get_existing()

    if state == 'present':
        aci.payload(
            aci_class='snmpPol',
            class_config=dict(
                name=name,
                adminSt=admin_state,
                contact=contact,
                descr=description,
                loc=location
            ),
        )

        aci.get_diff(aci_class='snmpPol')

        aci.post_config()

    elif state == 'absent':
        aci.delete_config()

    aci.exit_json()
コード例 #29
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(aci_annotation_spec())
    argument_spec.update(aci_owner_spec())
    argument_spec.update(
        node_profile=dict(
            type="str", aliases=["name", "node_profile_name", "logical_node"]),
        tenant=dict(type="str", aliases=["tenant_name"]),
        l3out=dict(type="str", aliases=["l3out_name"]),
        description=dict(type="str", aliases=["descr"]),
        dscp=dict(
            type="str",
            choices=[
                "AF11",
                "AF12",
                "AF13",
                "AF21",
                "AF22",
                "AF23",
                "AF31",
                "AF32",
                "AF33",
                "AF41",
                "AF42",
                "AF43",
                "CS0",
                "CS1",
                "CS2",
                "CS3",
                "CS4",
                "CS5",
                "CS6",
                "CS7",
                "EF",
                "VA",
                "unspecified",
            ],
            aliases=["target_dscp"],
        ),
        state=dict(type="str",
                   default="present",
                   choices=["absent", "present", "query"]),
        name_alias=dict(type="str"),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ["state", "absent", ["tenant", "l3out", "node_profile"]],
            ["state", "present", ["tenant", "l3out", "node_profile"]],
        ],
    )

    node_profile = module.params.get("node_profile")
    tenant = module.params.get("tenant")
    l3out = module.params.get("l3out")
    description = module.params.get("description")
    dscp = module.params.get("dscp")
    state = module.params.get("state")
    name_alias = module.params.get("name_alias")

    aci = ACIModule(module)

    aci.construct_url(
        root_class=dict(
            aci_class="fvTenant",
            aci_rn="tn-{0}".format(tenant),
            module_object=tenant,
            target_filter={"name": tenant},
        ),
        subclass_1=dict(
            aci_class="l3extOut",
            aci_rn="out-{0}".format(l3out),
            module_object=l3out,
            target_filter={"name": l3out},
        ),
        subclass_2=dict(
            aci_class="l3extLNodeP",
            aci_rn="lnodep-{0}".format(node_profile),
            module_object=node_profile,
            target_filter={"name": node_profile},
        ),
    )

    aci.get_existing()

    if state == "present":
        aci.payload(
            aci_class="l3extLNodeP",
            class_config=dict(
                descr=description,
                name=node_profile,
                targetDscp=dscp,
                nameAlias=name_alias,
            ),
        )

        aci.get_diff(aci_class="l3extLNodeP")

        aci.post_config()

    elif state == "absent":
        aci.delete_config()

    aci.exit_json()
コード例 #30
0
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(
        relay_policy=dict(type='str', aliases=['relay_policy_name']),
        epg_type=dict(type='str',
                      required=True,
                      choices=['epg', 'l2_external', 'l3_external', 'dn']),
        anp=dict(type='str'),
        epg=dict(type='str', aliases=['app_epg']),
        l2out_name=dict(type='str'),
        l3out_name=dict(type='str'),
        external_epg=dict(type='str', aliases=['external_net']),
        dhcp_server_addr=dict(type='str'),
        state=dict(type='str',
                   default='present',
                   choices=['absent', 'present', 'query']),
        tenant=dict(type='str'),
        provider_tenant=dict(type='str'),
        dn=dict(type='str'),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ['state', 'absent', ['relay_policy', 'tenant']],
            ['state', 'present', ['relay_policy', 'tenant']],
            ['epg_type', 'epg', ['anp', 'epg']],
            ['epg_type', 'l2_external', ['l2out_name', 'external_epg']],
            ['epg_type', 'l3_external', ['l3out_name', 'external_epg']],
            ['epg_type', 'dn', ['dn']],
        ],
        mutually_exclusive=[
            ['anp', 'l2out_name'],
            ['anp', 'l3out_name'],
            ['anp', 'external_epg'],
            ['anp', 'dn'],
            ['epg', 'l2out_name'],
            ['epg', 'l3out_name'],
            ['epg', 'external_epg'],
            ['epg', 'dn'],
            ['l2out_name', 'l3out_name'],
            ['l2out_name', 'dn'],
            ['l3out_name', 'dn'],
            ['external_epg', 'dn'],
        ],
    )

    relay_policy = module.params.get('relay_policy')
    state = module.params.get('state')
    tenant = module.params.get('tenant')
    epg_type = module.params.get('epg_type')
    anp = module.params.get('anp')
    epg = module.params.get('epg')
    l2out_name = module.params.get('l2out_name')
    l3out_name = module.params.get('l3out_name')
    external_epg = module.params.get('external_epg')
    dhcp_server_addr = module.params.get('dhcp_server_addr')
    provider_tenant = module.params.get('provider_tenant')
    dn = module.params.get('dn')

    if provider_tenant is None:
        provider_tenant = tenant

    if epg_type == 'epg':
        tdn = 'uni/tn-{0}/ap-{1}/epg-{2}'.format(provider_tenant, anp, epg)
    elif epg_type == 'l2_external':
        tdn = ('uni/tn-{0}/l2out-{1}/instP-{2}'.format(provider_tenant,
                                                       l2out_name,
                                                       external_epg))
    elif epg_type == 'l3_external':
        tdn = ('uni/tn-{0}/out-{1}/instP-{2}'.format(provider_tenant,
                                                     l3out_name, external_epg))
    elif epg_type == 'dn':
        tdn = dn

    aci = ACIModule(module)
    aci.construct_url(
        root_class=dict(
            aci_class='fvTenant',
            aci_rn='tn-{0}'.format(tenant),
            module_object=tenant,
            target_filter={'name': tenant},
        ),
        subclass_1=dict(
            aci_class='dhcpRelayP',
            aci_rn='relayp-{0}'.format(relay_policy),
            module_object=relay_policy,
            target_filter={'name': relay_policy},
        ),
        subclass_2=dict(
            aci_class='dhcpRsProv',
            aci_rn='rsprov-[{0}]'.format(tdn),
            module_object=tdn,
            target_filter={'tDn': tdn},
        ),
    )

    aci.get_existing()

    if state == 'present':
        aci.payload(
            aci_class='dhcpRsProv',
            class_config=dict(addr=dhcp_server_addr, tDn=tdn),
        )

        aci.get_diff(aci_class='dhcpRsProv')

        aci.post_config()

    elif state == 'absent':
        aci.delete_config()

    aci.exit_json()