Esempio n. 1
0
 def delete_mo(self):
     vmm_domp = self.check_if_mo_exist('uni/vmmp-' + self.vmm_provider +
                                       '/dom-',
                                       self.vmm_domain,
                                       DomP,
                                       description='VMM Domain')
     CtrlrP(vmm_domp, self.vcenter_controller).delete()
Esempio n. 2
0
def create_vcenter_controller(modir, vm_provider, vmm_domain_name,
                              controller_name, host_or_ip, data_center,
                              **args):
    vmm_domp = modir.lookupByDn('uni/vmmp-' + vm_provider + '/dom-' +
                                vmm_domain_name)
    args = args['args_from_CLI'] if 'args_from_CLI' in args.keys() else args
    if isinstance(vmm_domp, DomP):
        vmm_ctrlrp = CtrlrP(vmm_domp,
                            controller_name,
                            hostOrIp=host_or_ip,
                            rootContName=data_center,
                            statsMode=get_value(args, 'statsMode', 'disabled'))

        # define associated credential
        if 'associated_credential' in args.keys():
            vmm_usraccp_path = 'uni/vmmp-' + vm_provider + '/dom-' + vmm_domain_name + '/usracc-' + args[
                'associated_credential']
            vmm_usraccp = modir.lookupByDn(vmm_usraccp_path)
            if isinstance(vmm_usraccp, UsrAccP):
                vmm_rtctrlrp = RsAcc(vmm_ctrlrp, tDn=vmm_usraccp_path)
            else:
                print args['associated_credential'], 'has not been defined.'
                return
    else:
        print 'There is no VMM Domain', vmm_domain_name, 'in', vm_provider
        return

    print toXMLStr(vmm_domp, prettyPrint=True)
    commit_change(modir, vmm_domp)
Esempio n. 3
0
def delete_vcenter_controller(modir, vm_provider, vmm_domain_name,
                              controller_name):
    vmm_domp = modir.lookupByDn('uni/vmmp-' + vm_provider + '/dom-' +
                                vmm_domain_name)
    if isinstance(vmm_domp, DomP):
        CtrlrP(vmm_domp, controller_name).delete()
    else:
        print 'There is no VMM Domain', vmm_domain_name, 'in', vm_provider
        return

    print toXMLStr(vmm_domp, prettyPrint=True)
    commit_change(modir, vmm_domp)
Esempio n. 4
0
def create_vcenter_controller(vmm_domp, controller, host_or_ip, data_center,
                              **args):
    """Create vCenter Controller. The VMM controller profile, which specifies how to connect to a single VM management controller that is part of containing policy enforcement domain. For example, the VMM controller profile could be a policy to connect a VMware vCenter that is part a VMM domain. """
    args = args['optional_args'] if 'optional_args' in args.keys() else args
    vmm_ctrlrp = CtrlrP(vmm_domp,
                        controller,
                        hostOrIp=host_or_ip,
                        rootContName=data_center,
                        statsMode=get_value(args, 'stats_mode',
                                            DEFAULT_STATS_MODE))

    if is_valid_key(args, 'management_epg'):
        vmm_rsmgmtepg = RsMgmtEPg(vmm_ctrlrp,
                                  tDn='uni/tn-mgmt/out-vmm/instP-' +
                                  args['management_epg'])

    return vmm_ctrlrp
Esempio n. 5
0
def main(host, port, user, password):

    # CONNECT TO APIC
    print('Initializing connection to APIC...')
    apicUrl = 'http://%s:%d' % (host, port)
    moDir = MoDirectory(LoginSession(apicUrl, user, password))
    moDir.login()

    # Get the top level Policy Universe Directory
    uniMo = moDir.lookupByDn('uni')
    uniInfraMo = moDir.lookupByDn('uni/infra')

    # Create Vlan Namespace
    nsInfo = VMM_DOMAIN_INFO['namespace']
    print("Creating namespace %s.." % (nsInfo['name']))
    fvnsVlanInstPMo = VlanInstP(uniInfraMo, nsInfo['name'], 'dynamic')
    #fvnsArgs = {'from': nsInfo['from'], 'to': nsInfo['to']}
    EncapBlk(fvnsVlanInstPMo, nsInfo['from'], nsInfo['to'], name=nsInfo['name'])
    
    nsCfg = ConfigRequest()
    nsCfg.addMo(fvnsVlanInstPMo)
    moDir.commit(nsCfg)

    # Create VMM Domain
    print('Creating VMM domain...')

    vmmpVMwareProvPMo = moDir.lookupByDn('uni/vmmp-VMware')
    vmmDomPMo = DomP(vmmpVMwareProvPMo, VMM_DOMAIN_INFO['name'])
    
    vmmUsrMo = []
    for usrp in VMM_DOMAIN_INFO['usrs']:
        usrMo = UsrAccP(vmmDomPMo, usrp['name'], usr=usrp['usr'],
                        pwd=usrp['pwd'])
        vmmUsrMo.append(usrMo)

    # Create Controllers under domain
    for ctrlr in VMM_DOMAIN_INFO['ctrlrs']:
        vmmCtrlrMo = CtrlrP(vmmDomPMo, ctrlr['name'], scope=ctrlr['scope'],
                            hostOrIp=ctrlr['ip'])
        # Associate Ctrlr to UserP
        RsAcc(vmmCtrlrMo, tDn=vmmUsrMo[0].dn)
    
    # Associate Domain to Namespace
    RsVlanNs(vmmDomPMo, tDn=fvnsVlanInstPMo.dn)
   
    vmmCfg = ConfigRequest()
    vmmCfg.addMo(vmmDomPMo)
    moDir.commit(vmmCfg)
    print("VMM Domain Creation Completed.")

    print("Starting Tenant Creation..")
    for tenant in TENANT_INFO:
        print("Creating tenant %s.." % (tenant['name']))
        fvTenantMo = Tenant(uniMo, tenant['name'])
        
        # Create Private Network
        Ctx(fvTenantMo, tenant['pvn'])
        
        # Create Bridge Domain
        fvBDMo = BD(fvTenantMo, name=tenant['bd'])
        
        # Create association to private network
        RsCtx(fvBDMo, tnFvCtxName=tenant['pvn'])
        
        # Create Application Profile
        for app in tenant['ap']:
            print('Creating Application Profile: %s' % app['name'])
            fvApMo = Ap(fvTenantMo, app['name'])
            
            # Create EPGs 
            for epg in app['epgs']:
                
                print("Creating EPG: %s..." % (epg['name'])) 
                fvAEPgMo = AEPg(fvApMo, epg['name'])
                
                # Associate EPG to Bridge Domain 
                RsBd(fvAEPgMo, tnFvBDName=tenant['bd'])
                # Associate EPG to VMM Domain
                RsDomAtt(fvAEPgMo, vmmDomPMo.dn)

        # Commit each tenant seperately
        tenantCfg = ConfigRequest()
        tenantCfg.addMo(fvTenantMo)
        moDir.commit(tenantCfg)
    print('All done!')