Ejemplo n.º 1
0
    def update_router(self, context, router_id, original_router, new_router):
        """Updates a router which is already created on Kaloom vFabric.
        """
        ori_router_name = utils._kaloom_router_name(self.prefix, router_id,
                                                    original_router['name'])
        new_router_name = utils._kaloom_router_name(self.prefix, router_id,
                                                    new_router['name'])
        try:
            LOG.info('Trying to rename vfabric router %s to %s',
                     ori_router_name, new_router_name)
            vfabric_router_id = self.vfabric.get_router_id_by_name(
                ori_router_name)
            if vfabric_router_id is None:
                msg = "non-existing vfabric router"
                raise ValueError(msg)

            router_info = {
                'router_node_id': vfabric_router_id,
                'router_name': new_router_name
            }
            self.vfabric.rename_router(router_info)
        except Exception as e:
            msg = (_('Failed to rename vFabric router %s to %s, err:%s') %
                   (ori_router_name, new_router_name, e))
            LOG.error(msg)
            raise kaloom_exc.KaloomServicePluginRpcError(msg=msg)
Ejemplo n.º 2
0
    def update_router_routes_info(self, context, router_id, original_router,
                                  new_routes_info):
        """ Updates a router's extra-routes as new_routes_info on Kaloom vFabric.
        """
        if original_router:
            router_name = utils._kaloom_router_name(self.prefix, router_id,
                                                    original_router['name'])
            try:
                LOG.info('Trying to update routes %s on vfabric router %s',
                         new_routes_info, router_name)
                vfabric_router_id = self.vfabric.get_router_id_by_name(
                    router_name)
                if vfabric_router_id is None:
                    msg = "non-existing vfabric router"
                    raise ValueError(msg)

                original_routes_info = original_router['routes']

                #Find diff
                new_set = set()
                for new_route in new_routes_info:
                    new_set.add(
                        (new_route["destination"], new_route["nexthop"]))

                original_set = set()
                for original_route in original_routes_info:
                    original_set.add((original_route["destination"],
                                      original_route["nexthop"]))

                setup = new_set - original_set
                delete = original_set - new_set

                for (destination, nexthop) in setup:
                    route_info = {
                        'router_node_id': vfabric_router_id,
                        'destination_prefix': destination,
                        'next_hop_address': nexthop
                    }
                    route_info['ip_version'] = netaddr.IPNetwork(
                        destination.split('/')[0]).version
                    self.vfabric.add_ip_static_route(route_info)

                for (destination, nexthop) in delete:
                    route_info = {
                        'router_node_id': vfabric_router_id,
                        'destination_prefix': destination
                    }
                    route_info['ip_version'] = netaddr.IPNetwork(
                        destination.split('/')[0]).version
                    self.vfabric.delete_ip_static_route(route_info)

            except Exception as e:
                msg = (
                    _('Failed to update routes %s on vfabric router %s, err:%s'
                      ) % (new_routes_info, router_name, e))
                LOG.error(msg)
                raise kaloom_exc.KaloomServicePluginRpcError(msg=msg)
Ejemplo n.º 3
0
    def delete_router(self, context, router_id, router):
        """Deletes a router from Kaloom vFabric."""
        if router:
            router_name = utils._kaloom_router_name(self.prefix, router_id,
                                                    router['name'])
            LOG.info('Trying to delete_router %s in vfabric', router_name)
            vfabric_router_id = self.vfabric.get_router_id_by_name(router_name)
            if vfabric_router_id is None:
                LOG.warning('No such vfabric router=%s to delete', router_name)
                return

            self.vfabric.delete_router(vfabric_router_id)
Ejemplo n.º 4
0
    def remove_router_interface(self, context, router_info):
        """Removes previously configured subnet interface from router on Kaloom vFabric.
        This deals with both IPv6 and IPv4 configurations. In case of no more subnet configuration remained, 
        removes interface connected to network. 
        """
        if router_info:
            router_name = utils._kaloom_router_name(self.prefix,
                                                    router_info['id'],
                                                    router_info['name'])
            l2_node_id = router_info['nw_name']
            try:
                LOG.info(
                    'Trying to remove subnet %s from vfabric router %s -- network %s',
                    router_info['subnet_id'], router_name, l2_node_id)
                router_inf_info = self.vfabric.get_router_interface_info(
                    router_name, l2_node_id)
                vfabric_router_id = router_inf_info['node_id']
                tp_interface_name = router_inf_info['interface']
                count_ip = len(router_inf_info['cidrs'])

                if vfabric_router_id is None:
                    LOG.warning(
                        'no router_interface to remove on non-existing vfabric router=%s',
                        router_name)
                    return

                if tp_interface_name is None:
                    LOG.warning('no router_interface to remove on router=%s',
                                router_name)
                    return

                router_inf_ip_addresses = [
                    cidr.split('/')[0] for cidr in router_inf_info['cidrs']
                ]
                #last IP subnet remained, detach router
                if count_ip == 0 or (count_ip == 1
                                     and router_info['ip_address']
                                     == router_inf_ip_addresses[0]):
                    self.vfabric.detach_router(vfabric_router_id, l2_node_id)
                elif router_info['ip_address'] in router_inf_ip_addresses:
                    #delete_ipaddress_from_interface
                    interface_info = {}
                    interface_info['router_node_id'] = vfabric_router_id
                    interface_info['interface_name'] = tp_interface_name
                    interface_info['ip_version'] = router_info['ip_version']
                    interface_info['ip_address'] = router_info['ip_address']
                    self.vfabric.delete_ipaddress_from_interface(
                        interface_info)
            except Exception as e:
                msg = (_('Failed to remove subnet %s from vfabric router '
                         '%s -- network %s, msg: %s') %
                       (router_info['subnet_id'], router_name, l2_node_id, e))
                raise kaloom_exc.KaloomServicePluginRpcError(msg=msg)
Ejemplo n.º 5
0
    def create_router(self, context, router):
        """Creates a router on Kaloom vFabric.
        """
        if router:
            router_name = utils._kaloom_router_name(self.prefix, router['id'],
                                                    router['name'])

            try:
                LOG.info('Trying to create_router %s in vfabric', router_name)
                self.vfabric.create_router(router_name)
            except Exception as e:
                msg = (
                    _('Failed to create router %s on Kaloom vFabric, err:%s') %
                    (router_name, e))
                LOG.error(msg)
                raise kaloom_exc.KaloomServicePluginRpcError(msg=msg)
Ejemplo n.º 6
0
 def router_l2node_link_exists(self, router_id, name, l2_node_id):
     """ check the link between router and l2_node exists or not. 
     """
     if router_id:
         router_name = utils._kaloom_router_name(self.prefix, router_id,
                                                 name)
         try:
             router_inf_info = self.vfabric.get_router_interface_info(
                 router_name, l2_node_id)
             vfabric_router_id = router_inf_info['node_id']
             tp_interface_name = router_inf_info['interface']
             if vfabric_router_id is not None and tp_interface_name is not None:
                 return True
             else:
                 return False
         except Exception as e:
             msg = (_(
                 'Failed to check router--l2_node %s--%s link existence on Kaloom vFabric, err:%s'
             ) % (router_name, l2_node_id, e))
             LOG.error(msg)
             raise kaloom_exc.KaloomServicePluginRpcError(msg=msg)
Ejemplo n.º 7
0
    def delete_router(self, context, router_id):
        """Delete an existing router from Kaloom vFabric as well as from the DB."""
        router = self.get_router(context, router_id)
        router_name = utils._kaloom_router_name(self.prefix, router_id, router['name'])
        # delete_router can't go in parallel with l3_sync (synchronize)
        # parallelism of router operations
        # shared (S) lock during transaction.
        db_session = db_api.get_writer_session()
        with db_session.begin(subtransactions=True):
            caller_msg = 'delete_router %s' % router_name
            kaloom_db.get_Lock(db_session, kconst.L3_LOCK_NAME, read=True, caller_msg = caller_msg)

            # Delete on neutron database
            super(KaloomL3ServicePlugin, self).delete_router(context, router_id)

            #delete router-id from the KaloomConcurrency table (no more future x/s lock)
            kaloom_db.delete_entry_for_Lock(router_id)

            # Delete router on the Kaloom vFabric, in case former does not raise exception
            try:
                self.driver.delete_router(context, router_id, router)
            except Exception as e:
                msg = "Failed to delete router %s on Kaloom vFabric, err:%s" % (router_name, e)
                LOG.warning(msg)
Ejemplo n.º 8
0
 def sync_routers(self, routers, vfabric_routers):
     try:
        #create routers if does not exist in vfabric
        for r in routers:
            vfabric_router = utils._kaloom_router_name(self.prefix, r['id'], r['name'])
            if vfabric_router in vfabric_routers.keys():
                #mark as non-stranding router
                vfabric_routers.pop(vfabric_router, None)
            else:
                try:
                    self.driver.create_router(self, r)
                except Exception as e:
                    LOG.error("sync_routers failed to create router=%s, msg:%s", vfabric_router, e)
        # remove stranded vfabric routers
        # possibility of stranded routers: router creation after netconf timeout; manually added routers in vFabric, failed deletion 
        for vfabric_router in vfabric_routers.keys():
            router_node_id = vfabric_routers[vfabric_router]
            try:
               LOG.info('Trying to delete_router %s in vfabric', vfabric_router)
               self.driver.vfabric.delete_router(router_node_id)
            except Exception as e:
               LOG.error("sync_routers failed to delete router=%s, msg:%s", vfabric_router, e)
     except Exception as e:
         LOG.error("sync_routers failed, msg:%s", e)
Ejemplo n.º 9
0
    def add_router_interface(self, context, router_info):
        """In case of no router interface present for the network of subnet, creates the interface.
        Adds a subnet configuration to the router interface on Kaloom vFabric.
        This deals with both IPv6 and IPv4 configurations. 
        """
        if router_info:
            router_name = utils._kaloom_router_name(self.prefix,
                                                    router_info['id'],
                                                    router_info['name'])
            l2_node_id = router_info['nw_name']
            try:
                attachFabricOperation = utils.Invoker()
                LOG.info(
                    'Trying to add subnet %s to vfabric router %s -- network %s',
                    router_info['subnet_id'], router_name, l2_node_id)
                router_inf_info = self.vfabric.get_router_interface_info(
                    router_name, l2_node_id)
                vfabric_router_id = router_inf_info['node_id']
                tp_interface_name = router_inf_info['interface']
                if vfabric_router_id is None:
                    msg = "non-existing vfabric router"
                    raise ValueError(msg)

                ## first subnet request ? absence of router--l2_node interface, first create interface.
                if tp_interface_name is None:
                    command = utils.Command(
                        utils.vfabric_operation_reversible(
                            self.vfabric, 'attach_router', 'detach_router'),
                        vfabric_router_id, l2_node_id)
                    tp_interface_name = attachFabricOperation.execute(command)

                #interface_info common to both add and delete.
                interface_info = {}
                interface_info['router_node_id'] = vfabric_router_id
                interface_info['interface_name'] = tp_interface_name
                interface_info['ip_version'] = router_info['ip_version']
                prefix_length = router_info['cidr'].split('/')[1]

                #plugin.remove_router_interface left stale data on vfabric? not cleaned yet? then delete (first) or reuse.
                #otherwise multiple IPs of same subnet would complain "That ipv4 address already exist for that router"
                given_ip_cidr = '%s/%s' % (router_info['ip_address'],
                                           prefix_length)
                deleted = self._delete_stale_ipaddress_from_interface(
                    interface_info, given_ip_cidr, router_inf_info['cidrs'])
                if not deleted:
                    #already exists exact ip/subnet in vfabric, which is not deleted to reuse.
                    return

                #add_ipaddress_to_interface
                interface_info['ip_address'] = router_info['ip_address']
                interface_info['prefix_length'] = prefix_length
                try:
                    self.vfabric.add_ipaddress_to_interface(interface_info)
                except Exception as _e:
                    msg = "add_ipaddress_to_interface failed: %s" % (_e)
                    raise ValueError(msg)
            except Exception as e:
                msg = (_('Failed to add subnet %s (IP %s) to vfabric router '
                         '%s -- network %s, err:%s') %
                       (router_info['subnet_id'], router_info['ip_address'],
                        router_name, l2_node_id, e))
                LOG.error(msg)
                attachFabricOperation.undo()
                raise kaloom_exc.KaloomServicePluginRpcError(msg=msg)