Example #1
0
    def remove_router_interface(self, context, router_id, interface_info):
        LOG.debug("Remove router interface in progress: "
                  "router_id=%(router_id)s "
                  "interface_info=%(interface_info)r",
                  {'router_id': router_id, 'interface_info': interface_info})

        subnet_id = interface_info.get('subnet_id')
        port_id = interface_info.get('port_id')
        if not subnet_id:
            if not port_id:
                raise sdnve_exc.BadInputException(msg=_('No port ID'))
            myport = super(SdnvePluginV2, self).get_port(context, port_id)
            LOG.debug("SdnvePluginV2.remove_router_interface port: %s",
                      myport)
            myfixed_ips = myport.get('fixed_ips')
            if not myfixed_ips:
                raise sdnve_exc.BadInputException(msg=_('No fixed IP'))
            subnet_id = myfixed_ips[0].get('subnet_id')
            if subnet_id:
                interface_info['subnet_id'] = subnet_id
                LOG.debug(
                    "SdnvePluginV2.remove_router_interface subnet_id: %s",
                    subnet_id)
        else:
            if not port_id:
                # The backend requires port id info in the request
                subnet = super(SdnvePluginV2, self).get_subnet(context,
                                                               subnet_id)
                df = {'device_id': [router_id],
                      'device_owner': [n_const.DEVICE_OWNER_ROUTER_INTF],
                      'network_id': [subnet['network_id']]}
                ports = self.get_ports(context, filters=df)
                if ports:
                    pid = ports[0]['id']
                    interface_info['port_id'] = pid
                    msg = ("SdnvePluginV2.remove_router_interface "
                           "subnet_id: %(sid)s  port_id: %(pid)s")
                    LOG.debug(msg, {'sid': subnet_id, 'pid': pid})

        (res, data) = self.sdnve_client.sdnve_update(
            'router', router_id + '/remove_router_interface', interface_info)

        if res not in constants.HTTP_ACCEPTABLE:
            raise sdnve_exc.SdnveException(
                msg=(_('Update router-remove-interface failed SDN-VE: %s') %
                     res))

        session = context.session
        with session.begin(subtransactions=True):
            try:
                info = super(SdnvePluginV2, self).remove_router_interface(
                    context, router_id, interface_info)
            except Exception:
                with excutils.save_and_reraise_exception():
                    self._add_router_interface_only(context,
                                                    router_id, interface_info)

        return info
Example #2
0
    def remove_router_interface(self, context, router_id, interface_info):
        LOG.debug(
            _("Remove router interface in progress: "
              "router_id=%(router_id)s "
              "interface_info=%(interface_info)r"), {
                  'router_id': router_id,
                  'interface_info': interface_info
              })

        subnet_id = interface_info.get('subnet_id')
        if not subnet_id:
            portid = interface_info.get('port_id')
            if not portid:
                raise sdnve_exc.BadInputException(msg=_('No port ID'))
            myport = super(SdnvePluginV2, self).get_port(context, portid)
            LOG.debug(_("SdnvePluginV2.remove_router_interface port: %s"),
                      myport)
            myfixed_ips = myport.get('fixed_ips')
            if not myfixed_ips:
                raise sdnve_exc.BadInputException(msg=_('No fixed IP'))
            subnet_id = myfixed_ips[0].get('subnet_id')
            if subnet_id:
                interface_info['subnet_id'] = subnet_id
                LOG.debug(
                    _("SdnvePluginV2.remove_router_interface subnet_id: %s"),
                    subnet_id)

        (res, data) = self.sdnve_client.sdnve_update(
            'router', router_id + '/remove_router_interface', interface_info)

        if res not in constants.HTTP_ACCEPTABLE:
            raise sdnve_exc.SdnveException(
                msg=(_('Update router-remove-interface failed SDN-VE: %s') %
                     res))

        session = context.session
        with session.begin(subtransactions=True):
            try:
                info = super(SdnvePluginV2, self).remove_router_interface(
                    context, router_id, interface_info)
            except Exception:
                with excutils.save_and_reraise_exception():
                    self._add_router_interface_only(context, router_id,
                                                    interface_info)

        return info