Пример #1
0
 def plug_interface(self, tenant_id, net_id, port_id, remote_interface_id):
     """
     Attaches a remote interface to the specified port on the
     specified Virtual Network.
     """
     port = self._get_port(tenant_id, net_id, port_id)
     # Validate attachment
     self._validate_attachment(tenant_id, net_id, port_id,
                               remote_interface_id)
     if port['interface_id']:
         raise exc.PortInUse(net_id=net_id, port_id=port_id,
                             att_id=port['interface_id'])
     db.port_set_attachment(port_id, net_id, remote_interface_id)
Пример #2
0
 def _add_interface_by_port(self, context, router_id, port_id, owner):
     with context.session.begin(subtransactions=True):
         port = self._core_plugin._get_port(context, port_id)
         if port['device_id']:
             raise n_exc.PortInUse(net_id=port['network_id'],
                                   port_id=port['id'],
                                   device_id=port['device_id'])
         fixed_ips = [ip for ip in port['fixed_ips']]
         if len(fixed_ips) != 1:
             msg = _('Router port must have exactly one fixed IP')
             raise n_exc.BadRequest(resource='router', msg=msg)
         subnet_id = fixed_ips[0]['subnet_id']
         subnet = self._core_plugin._get_subnet(context, subnet_id)
         self._check_for_dup_router_subnet(context, router_id,
                                           port['network_id'], subnet['id'],
                                           subnet['cidr'])
         port.update({'device_id': router_id, 'device_owner': owner})
         return port
Пример #3
0
    def add_router_interface(self, context, router_id, interface_info):
        if not interface_info:
            msg = _("Either subnet_id or port_id must be specified")
            raise q_exc.BadRequest(resource='router', msg=msg)

        if 'port_id' in interface_info:
            # make sure port update is committed
            with context.session.begin(subtransactions=True):
                if 'subnet_id' in interface_info:
                    msg = _("Cannot specify both subnet-id and port-id")
                    raise q_exc.BadRequest(resource='router', msg=msg)

                port = self._core_plugin._get_port(context,
                                                   interface_info['port_id'])
                if port['device_id']:
                    raise q_exc.PortInUse(net_id=port['network_id'],
                                          port_id=port['id'],
                                          device_id=port['device_id'])
                fixed_ips = [ip for ip in port['fixed_ips']]
                if len(fixed_ips) != 1:
                    msg = _('Router port must have exactly one fixed IP')
                    raise q_exc.BadRequest(resource='router', msg=msg)
                subnet_id = fixed_ips[0]['subnet_id']
                subnet = self._core_plugin._get_subnet(context, subnet_id)
                self._check_for_dup_router_subnet(context, router_id,
                                                  port['network_id'],
                                                  subnet['id'], subnet['cidr'])
                port.update({
                    'device_id': router_id,
                    'device_owner': DEVICE_OWNER_ROUTER_INTF
                })
        elif 'subnet_id' in interface_info:
            subnet_id = interface_info['subnet_id']
            subnet = self._core_plugin._get_subnet(context, subnet_id)
            # Ensure the subnet has a gateway
            if not subnet['gateway_ip']:
                msg = _('Subnet for router interface must have a gateway IP')
                raise q_exc.BadRequest(resource='router', msg=msg)
            self._check_for_dup_router_subnet(context, router_id,
                                              subnet['network_id'], subnet_id,
                                              subnet['cidr'])
            fixed_ip = {
                'ip_address': subnet['gateway_ip'],
                'subnet_id': subnet['id']
            }
            port = self._core_plugin.create_port(
                context, {
                    'port': {
                        'tenant_id': subnet['tenant_id'],
                        'network_id': subnet['network_id'],
                        'fixed_ips': [fixed_ip],
                        'mac_address': attributes.ATTR_NOT_SPECIFIED,
                        'admin_state_up': True,
                        'device_id': router_id,
                        'device_owner': DEVICE_OWNER_ROUTER_INTF,
                        'name': ''
                    }
                })

        self.l3_rpc_notifier.routers_updated(context, [router_id],
                                             'add_router_interface')
        info = {
            'id': router_id,
            'tenant_id': subnet['tenant_id'],
            'port_id': port['id'],
            'subnet_id': port['fixed_ips'][0]['subnet_id']
        }
        notifier_api.notify(context, notifier_api.publisher_id('network'),
                            'router.interface.create',
                            notifier_api.CONF.default_notification_level,
                            {'router.interface': info})
        return info