예제 #1
0
    def extend_router_dict(self, session, base_model, result):
        LOG.debug("APIC AIM MD extending dict for router: %s", result)

        tenant_id = result['tenant_id']
        tenant_aname = self.name_mapper.tenant(session, tenant_id)
        LOG.debug("Mapped tenant_id %(id)s to %(aname)s", {
            'id': tenant_id,
            'aname': tenant_aname
        })

        id = result['id']
        name = result['name']
        aname = self.name_mapper.router(session, id, name)
        LOG.debug("Mapped router_id %(id)s with name %(name)s to "
                  "%(aname)s", {
                      'id': id,
                      'name': name,
                      'aname': aname
                  })

        contract = aim_resource.Contract(tenant_name=tenant_aname, name=aname)

        subject = aim_resource.ContractSubject(tenant_name=tenant_aname,
                                               contract_name=aname,
                                               name=ROUTER_SUBJECT_NAME)

        aim_ctx = aim_context.AimContext(session)
        sync_state = cisco_apic.SYNC_SYNCED
        sync_state = self._merge_status(aim_ctx, sync_state, contract)
        sync_state = self._merge_status(aim_ctx, sync_state, subject)
        result[cisco_apic.DIST_NAMES] = {
            cisco_apic_l3.CONTRACT: contract.dn,
            cisco_apic_l3.CONTRACT_SUBJECT: subject.dn
        }
        result[cisco_apic.SYNC_STATE] = sync_state
예제 #2
0
    def delete_router(self, context, current):
        LOG.debug("APIC AIM MD deleting router: %s", current)

        session = context.session

        tenant_id = current['tenant_id']
        tenant_aname = self.name_mapper.tenant(session, tenant_id)
        LOG.debug("Mapped tenant_id %(id)s to %(aname)s", {
            'id': tenant_id,
            'aname': tenant_aname
        })

        id = current['id']
        name = current['name']
        aname = self.name_mapper.router(session, id, name)
        LOG.debug("Mapped router_id %(id)s with name %(name)s to "
                  "%(aname)s", {
                      'id': id,
                      'name': name,
                      'aname': aname
                  })

        aim_ctx = aim_context.AimContext(session)

        subject = aim_resource.ContractSubject(tenant_name=tenant_aname,
                                               contract_name=aname,
                                               name=ROUTER_SUBJECT_NAME)
        self.aim.delete(aim_ctx, subject)

        contract = aim_resource.Contract(tenant_name=tenant_aname, name=aname)
        self.aim.delete(aim_ctx, contract)

        self.name_mapper.delete_apic_name(session, id)
예제 #3
0
    def update_router(self, context, current, original):
        LOG.debug("APIC AIM MD updating router: %s", current)

        if current['name'] != original['name']:
            session = context.session

            tenant_id = current['tenant_id']
            tenant_aname = self.name_mapper.tenant(session, tenant_id)
            LOG.debug("Mapped tenant_id %(id)s to %(aname)s", {
                'id': tenant_id,
                'aname': tenant_aname
            })

            id = current['id']
            name = current['name']
            aname = self.name_mapper.router(session, id, name)
            LOG.debug(
                "Mapped router_id %(id)s with name %(name)s to "
                "%(aname)s", {
                    'id': id,
                    'name': name,
                    'aname': aname
                })
            dname = aim_utils.sanitize_display_name(name)

            aim_ctx = aim_context.AimContext(session)

            contract = aim_resource.Contract(tenant_name=tenant_aname,
                                             name=aname)
            contract = self.aim.update(aim_ctx, contract, display_name=dname)

            subject = aim_resource.ContractSubject(tenant_name=tenant_aname,
                                                   contract_name=aname,
                                                   name=ROUTER_SUBJECT_NAME)
            subject = self.aim.update(aim_ctx, subject, display_name=dname)
예제 #4
0
 def _get_flc_contract(self, session, flc, tenant):
     tenant_id = tenant
     flc_aid = self.name_mapper.flow_classifier(session, flc['id'])
     flc_aname = aim_utils.sanitize_display_name(flc['name'])
     return aim_resource.Contract(tenant_name=tenant_id,
                                  name=flc_aid,
                                  display_name=flc_aname)
 def _get_nat_contract(self, ctx, l3out):
     d_name = self._display_name(l3out)
     contract_name = self._scope_name_if_common(l3out.tenant_name,
                                                'EXT-%s' % l3out.name)
     return resource.Contract(tenant_name=l3out.tenant_name,
                              name=contract_name,
                              display_name=self._scope_name_if_common(
                                  l3out.tenant_name,
                                  aim_utils.sanitize_display_name('EXT-%s' %
                                                                  d_name)))
예제 #6
0
 def _get_contract(self, contract_name, tenant_name, should_exist=True):
     session = db_api.get_session()
     aim_ctx = aim_context.AimContext(session)
     contract = aim_resource.Contract(tenant_name=tenant_name,
                                      name=contract_name)
     contract = self.aim_mgr.get(aim_ctx, contract)
     if should_exist:
         self.assertIsNotNone(contract)
     else:
         self.assertIsNone(contract)
     return contract
 def _get_l3out_objects(self, l3out_name=None, l3out_display_name=None,
                        nat_vrf_name=None, vmm_domains=None,
                        phys_domains=None):
     name = 'EXT-%s' % (l3out_name or 'o1')
     d_name = 'EXT-%s' % (l3out_display_name or 'OUT')
     nat_vrf = a_res.VRF(tenant_name='t1', name=name, display_name=d_name)
     if vmm_domains is not None:
         vmm_doms = vmm_domains
     else:
         vmm_doms = self.vmm_domains
     if phys_domains is not None:
         phys_doms = phys_domains
     else:
         phys_doms = self.phys_domains
     return ([
         a_res.Filter(tenant_name='t1', name=name,
                      display_name=d_name),
         a_res.FilterEntry(tenant_name='t1', filter_name=name,
                           name='Any', display_name='Any'),
         a_res.Contract(tenant_name='t1', name=name,
                        display_name=d_name),
         a_res.ContractSubject(tenant_name='t1', contract_name=name,
                               name='Allow', display_name='Allow',
                               bi_filters=[name]),
         a_res.BridgeDomain(tenant_name='t1', name=name,
                            display_name=d_name,
                            vrf_name=nat_vrf_name or name,
                            limit_ip_learn_to_subnets=True,
                            l3out_names=[l3out_name or 'o1']),
         a_res.ApplicationProfile(tenant_name='t1', name='myapp',
                                  display_name='myapp'),
         a_res.EndpointGroup(tenant_name='t1', app_profile_name='myapp',
                             name=name, display_name=d_name,
                             bd_name=name,
                             provided_contract_names=[name],
                             consumed_contract_names=[name],
                             # NOTE(ivar): Need to keep both VMM
                             # representations since a GET on the EPG
                             # will also return the domain name list
                             # for backward compatibility
                             openstack_vmm_domain_names=[dom['name']
                                                         for dom in vmm_doms
                                                         if dom['type'] ==
                                                         'OpenStack'],
                             physical_domain_names=[dom['name']
                                                    for dom in phys_doms],
                             vmm_domains=vmm_doms,
                             physical_domains=phys_doms)] +
             ([nat_vrf] if nat_vrf_name is None else []))
예제 #8
0
    def create_router(self, context, current):
        LOG.debug("APIC AIM MD creating router: %s", current)

        session = context.session

        tenant_id = current['tenant_id']
        tenant_aname = self.name_mapper.tenant(session, tenant_id)
        LOG.debug("Mapped tenant_id %(id)s to %(aname)s", {
            'id': tenant_id,
            'aname': tenant_aname
        })

        id = current['id']
        name = current['name']
        aname = self.name_mapper.router(session, id, name)
        LOG.debug("Mapped router_id %(id)s with name %(name)s to "
                  "%(aname)s", {
                      'id': id,
                      'name': name,
                      'aname': aname
                  })
        dname = aim_utils.sanitize_display_name(name)

        aim_ctx = aim_context.AimContext(session)

        contract = aim_resource.Contract(tenant_name=tenant_aname,
                                         name=aname,
                                         display_name=dname)
        self.aim.create(aim_ctx, contract)

        subject = aim_resource.ContractSubject(tenant_name=tenant_aname,
                                               contract_name=aname,
                                               name=ROUTER_SUBJECT_NAME,
                                               display_name=dname,
                                               bi_filters=[ANY_FILTER_NAME])
        self.aim.create(aim_ctx, subject)

        # REVISIT(rkukura): Consider having L3 plugin extend router
        # dict again after calling this function.
        sync_state = cisco_apic.SYNC_SYNCED
        sync_state = self._merge_status(aim_ctx, sync_state, contract)
        sync_state = self._merge_status(aim_ctx, sync_state, subject)
        current[cisco_apic.DIST_NAMES] = {
            cisco_apic_l3.CONTRACT: contract.dn,
            cisco_apic_l3.CONTRACT_SUBJECT: subject.dn
        }
        current[cisco_apic.SYNC_STATE] = sync_state
    def test_subject_related_objects(self):
        self.mgr.create(self.ctx, aim_res.Tenant(name='common'))
        self.mgr.create(
            self.ctx, aim_res.Contract(tenant_name='common', name='c-name'))
        subj = aim_res.ContractSubject(
            **{'contract_name': 'c-name',
               'name': 's-name',
               'tenant_name': 'common', 'monitored': False})
        subj = self.mgr.create(self.ctx, subj)

        subj_flt = aim_res.ContractSubjOutFilter(
            **{'contract_name': 'c-name',
               'contract_subject_name': 's-name',
               'tenant_name': 'common',
               'monitored': False,
               'filter_name': 'pr_1'})
        subj_flt = self.mgr.create(self.ctx, subj_flt)

        subj_flt1 = aim_res.ContractSubjInFilter(
            **{'contract_name': 'c-name',
               'contract_subject_name': 's-name',
               'tenant_name': 'common',
               'monitored': False,
               'filter_name': 'pr_1'})
        subj_flt1 = self.mgr.create(self.ctx, subj_flt1)
        cfg_tree = self.tt_mgr.get(self.ctx, 'tn-common',
                                   tree=tree_manager.CONFIG_TREE)
        # verify pr_1 and its reverse are in the tree
        pr_1 = cfg_tree.find(
            ("fvTenant|common", "vzBrCP|c-name", "vzSubj|s-name",
             "vzOutTerm|outtmnl", "vzRsFiltAtt|pr_1"))
        rev_pr_1 = cfg_tree.find(
            ("fvTenant|common", "vzBrCP|c-name", "vzSubj|s-name",
             "vzInTerm|intmnl", "vzRsFiltAtt|pr_1"))
        self.assertIsNotNone(pr_1)
        self.assertIsNotNone(rev_pr_1)

        self.mgr.update(self.ctx, subj_flt1, action='deny')
        cfg_tree = self.tt_mgr.get(self.ctx, 'tn-common',
                                   tree=tree_manager.CONFIG_TREE)
        rev_pr_1 = cfg_tree.find(
            ("fvTenant|common", "vzBrCP|c-name", "vzSubj|s-name",
             "vzInTerm|intmnl", "vzRsFiltAtt|pr_1"))
        self.assertIsNotNone(rev_pr_1)
    def test_subject_related_objects(self):
        self.mgr.create(self.ctx, aim_res.Tenant(name='common'))
        self.mgr.create(self.ctx,
                        aim_res.Contract(tenant_name='common', name='c-name'))
        subj = aim_res.ContractSubject(
            **{
                'contract_name': 'c-name',
                'out_filters':
                ['pr_1', 'reverse-pr_1', 'pr_2', 'reverse-pr_2'],
                'name': 's-name',
                'tenant_name': 'common',
                'monitored': False,
                'bi_filters': [],
                'in_filters': ['pr_1', 'reverse-pr_1', 'pr_2', 'reverse-pr_2']
            })
        subj = self.mgr.create(self.ctx, subj)
        cfg_tree = self.tt_mgr.get(self.ctx,
                                   'tn-common',
                                   tree=tree_manager.CONFIG_TREE)
        # verify pr_1 and its reverse are in the tree
        pr_1 = cfg_tree.find(
            ("fvTenant|common", "vzBrCP|c-name", "vzSubj|s-name",
             "vzOutTerm|outtmnl", "vzRsFiltAtt|pr_1"))
        rev_pr_1 = cfg_tree.find(
            ("fvTenant|common", "vzBrCP|c-name", "vzSubj|s-name",
             "vzOutTerm|outtmnl", "vzRsFiltAtt|reverse-pr_1"))
        self.assertIsNotNone(pr_1)
        self.assertIsNotNone(rev_pr_1)

        self.mgr.update(self.ctx,
                        subj,
                        out_filters=['pr_2', 'reverse-pr_2'],
                        in_filters=['pr_2', 'reverse-pr_2'])
        cfg_tree = self.tt_mgr.get(self.ctx,
                                   'tn-common',
                                   tree=tree_manager.CONFIG_TREE)
        pr_1 = cfg_tree.find(
            ("fvTenant|common", "vzBrCP|c-name", "vzSubj|s-name",
             "vzOutTerm|outtmnl", "vzRsFiltAtt|pr_1"))
        rev_pr_1 = cfg_tree.find(
            ("fvTenant|common", "vzBrCP|c-name", "vzSubj|s-name",
             "vzOutTerm|outtmnl", "vzRsFiltAtt|reverse-pr_1"))
        self.assertIsNone(pr_1)
        self.assertIsNone(rev_pr_1)