예제 #1
0
    def ensure_subnet_created(self, network_id, address_scope_name, gateway):
        tenant = self.get_tenant(network_id)

        scope_config = self._get_address_scope_config(address_scope_name)

        l3_outs = scope_config['l3_outs']

        bd = fv.BD(tenant, network_id)

        subnet = fv.Subnet(bd,
                           gateway,
                           scope=scope_config.get('scope', 'public'),
                           ctrl='querier')

        subnet_outs = []

        for l3_out in l3_outs.split(','):
            out = self._find_l3_out(network_id, l3_out)

            if out:
                LOG.info('Configure L3 out for subnet, {}'.format(out.name))
                subnet_outs.append(fv.RsBDSubnetToOut(subnet, out.name))
            else:
                LOG.error(
                    'Cannot configure L3 out for subnet, {} not found in ACI configuration'
                    .format(l3_out))

                # We don't need the out profiles for now
                # subnet_out_profile = RsBDSubnetToProfile(subnet,l3_out,tnL3extOutName=l3_out)

                # self.apic.commit(subnet_out_profile)

        self.apic.commit([subnet] + subnet_outs)
예제 #2
0
    def ensure_subnet_deleted(self, network_id, gateway):
        tenant = self.get_tenant(network_id)
        bd = fv.BD(tenant, network_id)

        subnet = fv.Subnet(bd, gateway)
        subnet.delete()

        self.apic.commit(subnet)
예제 #3
0
apicUsername = '******' + TacacsUser
apicPassword = TacacsPassword
loginSession = LoginSession(apicUrl, apicUsername, apicPassword)

# Create a session with the APIC and login
moDir = MoDirectory(loginSession)
moDir.login()

#Prompt User for Tenant to create BD in.
#UserTenant = raw_input('Create BD in which tenant? ')

# Start at the Tenant of MIT tree
TenantMo = moDir.lookupByDn((r'uni/tn-ExampleSdkTenant'))

# Create a new BD MO and connect it as a Child object to the Tenant MO
fvBDMo = fvModels.BD(TenantMo, name='myBD')

# Associate the VRF under the new BD
fvRsCtxMo = fvModels.RsCtx(fvBDMo, tnFvCtxName='myVRF')

# Add Subnet to BD
fvSubnetMo = fvModels.Subnet(fvBDMo, ip='10.20.30.1/24')

# Create a new configuration request to the APIC and pass in the new Tenant MO (including its children MOs)
# Commit the changes to the APIC
cfgRequest = ConfigRequest()
cfgRequest.addMo(fvBDMo)
moDir.commit(cfgRequest)

# Log Out once the request is complete
moDir.logout()
예제 #4
0
def create_overlay_policy(apic=None, policy=None):

    mo = aciPol.Uni('')

    for name, data in policy.items():
        # Create tenant behind the scenes
        tenantName = '{0}_Tenant'.format(name)
        fvTenant = aciFv.Tenant(mo, name=tenantName)

        # Create the required VRF as well
        vrfName = '{0}_VRF'.format(name)
        fvCtx = aciFv.Ctx(fvTenant, name=vrfName)

        # Create BD
        for vlan in data['vlans']:
            vlanName = 'VLAN_{0}'.format(vlan['id'])

            if vlan['optimized']:
                fvBD = aciFv.BD(fvTenant,
                                name=vlanName,
                                OptimizeWanBandwidth='no',
                                arpFlood='no',
                                epClear='no',
                                hostBasedRouting='yes',
                                intersiteBumTrafficAllow='no',
                                intersiteL2Stretch='no',
                                ipLearning='yes',
                                limitIpLearnToSubnets='yes',
                                llAddr='::',
                                mac='00:22:BD:F8:19:FF',
                                mcastAllow='no',
                                multiDstPktAct='encap-flood',
                                type='regular',
                                unicastRoute='yes',
                                unkMacUcastAct='proxy',
                                unkMcastAct='opt-flood',
                                v6unkMcastAct='flood',
                                vmac='not-applicable')
            else:
                fvBD = aciFv.BD(fvTenant,
                                name=vlanName,
                                OptimizeWanBandwidth='no',
                                arpFlood='yes',
                                epClear='no',
                                hostBasedRouting='no',
                                intersiteBumTrafficAllow='no',
                                intersiteL2Stretch='no',
                                ipLearning='yes',
                                limitIpLearnToSubnets='yes',
                                llAddr='::',
                                mac='00:22:BD:F8:19:FF',
                                mcastAllow='no',
                                multiDstPktAct='bd-flood',
                                type='regular',
                                unicastRoute='yes',
                                unkMacUcastAct='flood',
                                unkMcastAct='flood',
                                v6unkMcastAct='flood',
                                vmac='not-applicable')

            aciFv.Subnet(fvBD,
                         ip=vlan['subnet'],
                         preferred='no',
                         scope='private',
                         virtual='no')

            aciFv.RsCtx(fvBD, tnFvCtxName='{0}_VRF'.format(name))

            fvAp = aciFv.Ap(fvTenant, name='{0}_AppProf'.format(vlanName))
            aciFv.RsApMonPol(fvAp, tnMonEPGPolName='default')

            # REMAINING TASKS
            # Create EPGs
            # aciFv.EPg(fvAp, name, matchT, etc...)
            # Contracts

    return mo