コード例 #1
0
 def update(self, obj=None):
     changed = self.update_vnc_obj(obj)
     if 'bgpaas_session_attributes' in changed:
         session_attrib = self.bgpaas_session_attributes
         bgp_session = BgpSession()
         if session_attrib:
             bgp_session.attributes = [session_attrib]
         peering_attribs = BgpPeeringAttributes(session=[bgp_session])
         self.peering_attribs = BgpPeeringAttributes(session=[bgp_session])
     return changed
コード例 #2
0
def bgp_router_create(name, type, ip_address, asn=64512, **kwargs):
    '''
    Create specific Contrail control node

    CLI Example:

    .. code-block:: bash

        salt '*' contrail.bgp_router_create ntw03 control-node 10.10.10.103
        salt '*' contrail.bgp_router_create mx01 router 10.10.10.105
    '''
    ret = {}
    vnc_client = _auth(**kwargs)

    address_families = [
        'route-target', 'inet-vpn', 'e-vpn', 'erm-vpn', 'inet6-vpn'
    ]
    if type != 'control-node':
        address_families.remove('erm-vpn')

    bgp_addr_fams = AddressFamilies(address_families)
    bgp_sess_attrs = [BgpSessionAttributes(address_families=bgp_addr_fams)]
    bgp_sessions = [BgpSession(attributes=bgp_sess_attrs)]
    bgp_peering_attrs = BgpPeeringAttributes(session=bgp_sessions)
    rt_inst_obj = _get_rt_inst_obj(vnc_client)

    if type == 'control-node':
        vendor = 'contrail'
    elif type == 'router':
        vendor = 'mx'
    else:
        vendor = 'unknown'

    router_params = BgpRouterParams(router_type=type,
                                    vendor=vendor,
                                    autonomous_system=int(asn),
                                    identifier=_get_ip(ip_address),
                                    address=_get_ip(ip_address),
                                    port=179,
                                    address_families=bgp_addr_fams)

    bgp_router_objs = bgp_router_list(**kwargs)
    if name in bgp_router_objs:
        bgp_router_obj = vnc_client._object_read(
            'bgp-router', id=bgp_router_objs[name]['_uuid'])
        bgp_router_obj.set_bgp_router_parameters(router_params)
        if __opts__['test']:
            return "BGP router " + name + " will be updated"
        vnc_client.bgp_router_update(bgp_router_obj)
    else:
        bgp_router_obj = BgpRouter(name,
                                   rt_inst_obj,
                                   bgp_router_parameters=router_params)
        if __opts__['test']:
            return "BGP router " + name + " will be created"
        vnc_client.bgp_router_create(bgp_router_obj)
        return "Created"
    return {'OK': 'Config node %s already exists' % name}
コード例 #3
0
    def update_peering(self, rr_changed=False):
        if not ResourceBaseST.get_obj_type_map().get(
                'global_system_config').get_ibgp_auto_mesh():
            return
        if self.router_type in ('bgpaas-server', 'bgpaas-client'):
            return

        fabric = None
        if self.physical_router:
            phy_rtr = ResourceBaseST.get_obj_type_map().get(
                'physical_router').get(self.physical_router)
            fabric = phy_rtr.fabric

        global_asn = int(ResourceBaseST.get_obj_type_map().get(
            'global_system_config').get_autonomous_system())
        # if it's a fabric or sub cluster bgp router, ignore
        # global asn check that we do to determine e-bgp router
        if (self.sub_cluster is None and fabric is None
                and self.asn != global_asn):
            return
        try:
            obj = self.read_vnc_obj(fq_name=self.name)
        except NoIdError as e:
            self._logger.error("NoIdError while reading bgp router "
                               "%s: %s" % (self.name, str(e)))
            return

        cluster_rr_supported, control_rr_supported = \
            self._is_route_reflector_supported()
        peerings_set = [ref['to'] for ref in (obj.get_bgp_router_refs() or [])]

        new_peerings_list = []
        new_peerings_attrs = []
        for router in self._dict.values():
            if router.name == self.name:
                continue
            if router.sub_cluster != self.sub_cluster:
                continue
            if router.router_type in ('bgpaas-server', 'bgpaas-client'):
                continue

            if self._skip_bgp_router_peering_add(router, cluster_rr_supported,
                                                 control_rr_supported):
                continue

            router_fq_name = router.name.split(':')
            if router_fq_name in peerings_set and not rr_changed:
                continue
            router_obj = BgpRouter()
            router_obj.fq_name = router_fq_name
            af = AddressFamilies(family=[])
            bsa = BgpSessionAttributes(address_families=af)
            session = BgpSession(attributes=[bsa])
            attr = BgpPeeringAttributes(session=[session])
            new_peerings_list.append(router_fq_name)
            new_peerings_attrs.append(attr)
            obj.add_bgp_router(router_obj, attr)

        new_peerings_set = [
            ref['to'] for ref in (obj.get_bgp_router_refs() or [])
        ]
        if rr_changed:
            obj.set_bgp_router_list(new_peerings_list, new_peerings_attrs)
            try:
                self._vnc_lib.bgp_router_update(obj)
            except NoIdError as e:
                self._logger.error("NoIdError while updating bgp router "
                                   "%s: %s" % (self.name, str(e)))
        elif new_peerings_set != peerings_set:
            try:
                self._vnc_lib.bgp_router_update(obj)
            except NoIdError as e:
                self._logger.error("NoIdError while updating bgp router "
                                   "%s: %s" % (self.name, str(e)))