Пример #1
0
 def __init__(self, plugin, plugin_context, port, network,
              original_port=None):
     super(PortContext, self).__init__(plugin, plugin_context)
     self._port = port
     self._original_port = original_port
     self._network_context = NetworkContext(plugin, plugin_context,
                                            network)
     self._binding = db.ensure_port_binding(plugin_context.session,
                                            port['id'])
Пример #2
0
 def __init__(self, plugin, plugin_context, port, network,
              original_port=None):
     super(PortContext, self).__init__(plugin, plugin_context)
     self._port = port
     self._original_port = original_port
     self._network_context = NetworkContext(plugin, plugin_context,
                                            network)
     self._binding = db.ensure_port_binding(plugin_context.session,
                                            port['id'])
     if original_port:
         self._original_bound_segment_id = self._binding.segment
         self._original_bound_driver = self._binding.driver
     else:
         self._original_bound_segment_id = None
         self._original_bound_driver = None
Пример #3
0
 def __init__(self,
              plugin,
              plugin_context,
              port,
              network,
              original_port=None):
     super(PortContext, self).__init__(plugin, plugin_context)
     self._port = port
     self._original_port = original_port
     self._network_context = NetworkContext(plugin, plugin_context, network)
     self._binding = db.ensure_port_binding(plugin_context.session,
                                            port['id'])
     if original_port:
         self._original_bound_segment_id = self._binding.segment
         self._original_bound_driver = self._binding.driver
     else:
         self._original_bound_segment_id = None
         self._original_bound_driver = None
Пример #4
0
    def get_device_details(self, rpc_context, **kwargs):
        """Agent requests device details."""
        agent_id = kwargs.get('agent_id')
        device = kwargs.get('device')
        LOG.debug(
            _("Device %(device)s details requested by agent "
              "%(agent_id)s"), {
                  'device': device,
                  'agent_id': agent_id
              })
        port_id = self._device_to_port_id(device)

        session = db_api.get_session()
        with session.begin(subtransactions=True):
            port = db.get_port(session, port_id)
            if not port:
                LOG.warning(
                    _("Device %(device)s requested by agent "
                      "%(agent_id)s not found in database"), {
                          'device': device,
                          'agent_id': agent_id
                      })
                return {'device': device}

            segments = db.get_network_segments(session, port.network_id)
            if not segments:
                LOG.warning(
                    _("Device %(device)s requested by agent "
                      "%(agent_id)s has network %(network_id)s with "
                      "no segments"), {
                          'device': device,
                          'agent_id': agent_id,
                          'network_id': port.network_id
                      })
                return {'device': device}

            binding = db.ensure_port_binding(session, port.id)
            if not binding.segment:
                LOG.warning(
                    _("Device %(device)s requested by agent "
                      "%(agent_id)s on network %(network_id)s not "
                      "bound, vif_type: %(vif_type)s"), {
                          'device': device,
                          'agent_id': agent_id,
                          'network_id': port.network_id,
                          'vif_type': binding.vif_type
                      })
                return {'device': device}

            segment = self._find_segment(segments, binding.segment)
            if not segment:
                LOG.warning(
                    _("Device %(device)s requested by agent "
                      "%(agent_id)s on network %(network_id)s "
                      "invalid segment, vif_type: %(vif_type)s"), {
                          'device': device,
                          'agent_id': agent_id,
                          'network_id': port.network_id,
                          'vif_type': binding.vif_type
                      })
                return {'device': device}

            new_status = (q_const.PORT_STATUS_BUILD
                          if port.admin_state_up else q_const.PORT_STATUS_DOWN)
            if port.status != new_status:
                plugin = manager.NeutronManager.get_plugin()
                plugin.update_port_status(rpc_context, port_id, new_status)
                port.status = new_status
            entry = {
                'device': device,
                'network_id': port.network_id,
                'port_id': port.id,
                'admin_state_up': port.admin_state_up,
                'network_type': segment[api.NETWORK_TYPE],
                'segmentation_id': segment[api.SEGMENTATION_ID],
                'physical_network': segment[api.PHYSICAL_NETWORK]
            }
            LOG.debug(_("Returning: %s"), entry)
            return entry
Пример #5
0
    def get_device_details(self, rpc_context, **kwargs):
        """Agent requests device details."""
        agent_id = kwargs.get('agent_id')
        device = kwargs.get('device')
        LOG.debug(_("Device %(device)s details requested by agent "
                    "%(agent_id)s"),
                  {'device': device, 'agent_id': agent_id})
        port_id = self._device_to_port_id(device)

        session = db_api.get_session()
        with session.begin(subtransactions=True):
            port = db.get_port(session, port_id)
            if not port:
                LOG.warning(_("Device %(device)s requested by agent "
                              "%(agent_id)s not found in database"),
                            {'device': device, 'agent_id': agent_id})
                return {'device': device}

            segments = db.get_network_segments(session, port.network_id)
            if not segments:
                LOG.warning(_("Device %(device)s requested by agent "
                              "%(agent_id)s has network %(network_id)s with "
                              "no segments"),
                            {'device': device,
                             'agent_id': agent_id,
                             'network_id': port.network_id})
                return {'device': device}

            binding = db.ensure_port_binding(session, port.id)
            if not binding.segment:
                LOG.warning(_("Device %(device)s requested by agent "
                              "%(agent_id)s on network %(network_id)s not "
                              "bound, vif_type: %(vif_type)s"),
                            {'device': device,
                             'agent_id': agent_id,
                             'network_id': port.network_id,
                             'vif_type': binding.vif_type})
                return {'device': device}

            segment = self._find_segment(segments, binding.segment)
            if not segment:
                LOG.warning(_("Device %(device)s requested by agent "
                              "%(agent_id)s on network %(network_id)s "
                              "invalid segment, vif_type: %(vif_type)s"),
                            {'device': device,
                             'agent_id': agent_id,
                             'network_id': port.network_id,
                             'vif_type': binding.vif_type})
                return {'device': device}

            new_status = (q_const.PORT_STATUS_BUILD if port.admin_state_up
                          else q_const.PORT_STATUS_DOWN)
            if port.status != new_status:
                port.status = new_status
            entry = {'device': device,
                     'network_id': port.network_id,
                     'port_id': port.id,
                     'admin_state_up': port.admin_state_up,
                     'network_type': segment[api.NETWORK_TYPE],
                     'segmentation_id': segment[api.SEGMENTATION_ID],
                     'physical_network': segment[api.PHYSICAL_NETWORK]}
            LOG.debug(_("Returning: %s"), entry)
            return entry
Пример #6
0
    def get_device_details(self, rpc_context, **kwargs):
        """Agent requests device details."""
        agent_id = kwargs.get('agent_id')
        device = kwargs.get('device')
        LOG.debug(_("Device %(device)s details requested by agent "
                    "%(agent_id)s"),
                  {'device': device, 'agent_id': agent_id})
        port_id = self._device_to_port_id(device)

        session = db_api.get_session()
        with session.begin(subtransactions=True):
            port = db.get_port(session, port_id)
            if not port:
                LOG.warning(_("Device %(device)s requested by agent "
                              "%(agent_id)s not found in database"),
                            {'device': device, 'agent_id': agent_id})
                return {'device': device}

            segments = db.get_network_segments(session, port.network_id)
            if not segments:
                LOG.warning(_("Device %(device)s requested by agent "
                              "%(agent_id)s has network %(network_id)s with "
                              "no segments"),
                            {'device': device,
                             'agent_id': agent_id,
                             'network_id': port.network_id})
                return {'device': device}

            binding = db.ensure_port_binding(session, port.id)
            # Fake segment for virl LXC/Other ports, remain unbound officially
            binding_segment = binding.segment
            if (port.device_id or '').startswith('virl-'):
                binding_segment = binding_segment or segments[0][api.ID]
            if not binding_segment:
                LOG.warning(_("Device %(device)s requested by agent "
                              "%(agent_id)s on network %(network_id)s not "
                              "bound, vif_type: %(vif_type)s"),
                            {'device': device,
                             'agent_id': agent_id,
                             'network_id': port.network_id,
                             'vif_type': binding.vif_type})
                return {'device': device}

            segment = self._find_segment(segments, binding_segment)
            if not segment:
                LOG.warning(_("Device %(device)s requested by agent "
                              "%(agent_id)s on network %(network_id)s "
                              "invalid segment, vif_type: %(vif_type)s"),
                            {'device': device,
                             'agent_id': agent_id,
                             'network_id': port.network_id,
                             'vif_type': binding.vif_type})
                return {'device': device}

            new_status = (q_const.PORT_STATUS_BUILD if port.admin_state_up
                          else q_const.PORT_STATUS_DOWN)
            if port.status != new_status:
                plugin = manager.NeutronManager.get_plugin()
                plugin.update_port_status(rpc_context,
                                          port_id,
                                          new_status)
                port.status = new_status
            entry = {'device': device,
                     'network_id': port.network_id,
                     'port_id': port.id,
                     'device_id': port.device_id,
                     'device_owner': port.device_owner,
                     'mac_address': port.mac_address,
                     'admin_state_up': port.admin_state_up,
                     'network_type': segment[api.NETWORK_TYPE],
                     'segmentation_id': segment[api.SEGMENTATION_ID],
                     'physical_network': segment[api.PHYSICAL_NETWORK]}
            LOG.debug(_("Returning: %s"), entry)
            return entry