Exemple #1
0
 def test_add_network_binding(self):
     with self.network() as network:
         TEST_NETWORK_ID = network["network"]["id"]
         self.assertIsNone(mlnx_db.get_network_binding(self.session, TEST_NETWORK_ID))
         mlnx_db.add_network_binding(self.session, TEST_NETWORK_ID, NET_TYPE, PHYS_NET, 1234)
         binding = mlnx_db.get_network_binding(self.session, TEST_NETWORK_ID)
         self.assertIsNotNone(binding)
         self.assertEqual(binding.network_id, TEST_NETWORK_ID)
         self.assertEqual(binding.network_type, NET_TYPE)
         self.assertEqual(binding.physical_network, PHYS_NET)
         self.assertEqual(binding.segmentation_id, 1234)
Exemple #2
0
 def test_add_network_binding(self):
     with self.network() as network:
         TEST_NETWORK_ID = network['network']['id']
         self.assertIsNone(
             mlnx_db.get_network_binding(self.session, TEST_NETWORK_ID))
         mlnx_db.add_network_binding(self.session, TEST_NETWORK_ID,
                                     NET_TYPE, PHYS_NET, 1234)
         binding = mlnx_db.get_network_binding(self.session,
                                               TEST_NETWORK_ID)
         self.assertIsNotNone(binding)
         self.assertEqual(binding.network_id, TEST_NETWORK_ID)
         self.assertEqual(binding.network_type, NET_TYPE)
         self.assertEqual(binding.physical_network, PHYS_NET)
         self.assertEqual(binding.segmentation_id, 1234)
Exemple #3
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 from %(agent_id)s"), {
         'device': device,
         'agent_id': agent_id
     })
     port = self.get_port_from_device(device)
     if port:
         binding = db.get_network_binding(db_api.get_session(),
                                          port['network_id'])
         entry = {
             'device': device,
             'physical_network': binding.physical_network,
             'network_type': binding.network_type,
             'segmentation_id': binding.segmentation_id,
             'network_id': port['network_id'],
             'port_mac': port['mac_address'],
             'port_id': port['id'],
             'admin_state_up': port['admin_state_up']
         }
         if cfg.CONF.AGENT.rpc_support_old_agents:
             entry['vlan_id'] = binding.segmentation_id
         new_status = (q_const.PORT_STATUS_ACTIVE if port['admin_state_up']
                       else q_const.PORT_STATUS_DOWN)
         if port['status'] != new_status:
             db.set_port_status(port['id'], new_status)
     else:
         entry = {'device': device}
         LOG.debug(_("%s can not be found in database"), device)
     return entry
 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 from %(agent_id)s",
               {'device': device, 'agent_id': agent_id})
     plugin = manager.NeutronManager.get_plugin()
     port = plugin.get_port_from_device(device)
     if port:
         binding = db.get_network_binding(db_api.get_session(),
                                          port['network_id'])
         entry = {'device': device,
                  'physical_network': binding.physical_network,
                  'network_type': binding.network_type,
                  'segmentation_id': binding.segmentation_id,
                  'network_id': port['network_id'],
                  'port_mac': port['mac_address'],
                  'port_id': port['id'],
                  'admin_state_up': port['admin_state_up']}
         if cfg.CONF.AGENT.rpc_support_old_agents:
             entry['vlan_id'] = binding.segmentation_id
         new_status = (q_const.PORT_STATUS_ACTIVE if port['admin_state_up']
                       else q_const.PORT_STATUS_DOWN)
         if port['status'] != new_status:
             db.set_port_status(port['id'], new_status)
     else:
         entry = {'device': device}
         LOG.debug("%s can not be found in database", device)
     return entry
Exemple #5
0
    def _process_port_binding_create(self, context, attrs):
        binding_profile = attrs.get(portbindings.PROFILE)
        binding_profile_set = attributes.is_attr_set(binding_profile)

        net_binding = db.get_network_binding(context.session,
                                             attrs.get('network_id'))
        net_type = net_binding.network_type

        if not binding_profile_set:
            return self.vnic_type
        if constants.VNIC_TYPE in binding_profile:
            vnic_type = binding_profile[constants.VNIC_TYPE]
            if vnic_type in (constants.VIF_TYPE_DIRECT,
                             constants.VIF_TYPE_HOSTDEV):
                if self._check_port_binding_for_net_type(vnic_type,
                                                         net_type):
                    self.base_binding_dict[portbindings.VIF_TYPE] = vnic_type
                    return vnic_type
                else:
                    msg = (_("Unsupported vnic type %(vnic_type)s "
                             "for network type %(net_type)s") %
                           {'vnic_type': vnic_type, 'net_type': net_type})
            else:
                msg = _("Invalid vnic_type on port_create")
        else:
            msg = _("vnic_type is not defined in port profile")
        raise q_exc.InvalidInput(error_message=msg)
Exemple #6
0
    def _process_port_binding_create(self, context, attrs):
        binding_profile = attrs.get(portbindings.PROFILE)
        binding_profile_set = attributes.is_attr_set(binding_profile)

        net_binding = db.get_network_binding(context.session,
                                             attrs.get('network_id'))
        phy_net = net_binding.physical_network

        if not binding_profile_set:
            return self.vnic_type
        if constants.VNIC_TYPE in binding_profile:
            vnic_type = binding_profile[constants.VNIC_TYPE]
            phy_net_type = self.phys_network_type_maps[phy_net]
            if vnic_type in (constants.VIF_TYPE_DIRECT,
                             constants.VIF_TYPE_HOSTDEV):
                if self._check_port_binding_for_net_type(
                        vnic_type, phy_net_type):
                    self.base_binding_dict[portbindings.VIF_TYPE] = vnic_type
                    return vnic_type
                else:
                    msg = (_("Unsupported vnic type %(vnic_type)s "
                             "for physical network type %(net_type)s") % {
                                 'vnic_type': vnic_type,
                                 'net_type': phy_net_type
                             })
            else:
                msg = _("Invalid vnic_type on port_create")
        else:
            msg = _("vnic_type is not defined in port profile")
        raise n_exc.InvalidInput(error_message=msg)
 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 from %(agent_id)s"), {"device": device, "agent_id": agent_id})
     port = self.get_port_from_device(device)
     if port:
         binding = db.get_network_binding(db_api.get_session(), port["network_id"])
         entry = {
             "device": device,
             "physical_network": binding.physical_network,
             "network_type": binding.network_type,
             "segmentation_id": binding.segmentation_id,
             "network_id": port["network_id"],
             "port_mac": port["mac_address"],
             "port_id": port["id"],
             "admin_state_up": port["admin_state_up"],
         }
         if cfg.CONF.AGENT.rpc_support_old_agents:
             entry["vlan_id"] = binding.segmentation_id
         new_status = q_const.PORT_STATUS_ACTIVE if port["admin_state_up"] else q_const.PORT_STATUS_DOWN
         if port["status"] != new_status:
             db.set_port_status(port["id"], new_status)
     else:
         entry = {"device": device}
         LOG.debug("%s can not be found in database", device)
     return entry
Exemple #8
0
    def update_port(self, context, port_id, port):
        original_port = self.get_port(context, port_id)
        session = context.session
        need_port_update_notify = False

        with session.begin(subtransactions=True):
            updated_port = super(MellanoxEswitchPlugin,
                                 self).update_port(context, port_id, port)
            self._process_portbindings_create_and_update(
                context, port['port'], updated_port)
            need_port_update_notify = self.update_security_group_on_port(
                context, port_id, port, original_port, updated_port)

        need_port_update_notify |= self.is_security_group_member_updated(
            context, original_port, updated_port)

        if original_port['admin_state_up'] != updated_port['admin_state_up']:
            need_port_update_notify = True

        if need_port_update_notify:
            binding = db.get_network_binding(context.session,
                                             updated_port['network_id'])
            self.notifier.port_update(context, updated_port,
                                      binding.physical_network,
                                      binding.network_type,
                                      binding.segmentation_id)
        return self._extend_port_dict_binding(context, updated_port)
Exemple #9
0
    def update_port(self, context, port_id, port):
        original_port = self.get_port(context, port_id)
        session = context.session
        need_port_update_notify = False

        with session.begin(subtransactions=True):
            updated_port = super(MellanoxEswitchPlugin, self).update_port(
                context, port_id, port)
            self._process_portbindings_create_and_update(context,
                                                         port['port'],
                                                         updated_port)
            need_port_update_notify = self.update_security_group_on_port(
                context, port_id, port, original_port, updated_port)

        need_port_update_notify |= self.is_security_group_member_updated(
            context, original_port, updated_port)

        if original_port['admin_state_up'] != updated_port['admin_state_up']:
            need_port_update_notify = True

        if need_port_update_notify:
            binding = db.get_network_binding(context.session,
                                             updated_port['network_id'])
            self.notifier.port_update(context, updated_port,
                                      binding.physical_network,
                                      binding.network_type,
                                      binding.segmentation_id)
        return self._extend_port_dict_binding(context, updated_port)
Exemple #10
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 %s details requested from %s", device, agent_id)
     port = self.get_port_from_device(device)
     if port:
         binding = db.get_network_binding(db_api.get_session(),
                                          port['network_id'])
         entry = {
             'device': device,
             'physical_network': binding.physical_network,
             'network_type': binding.network_type,
             'vlan_id': binding.segmentation_id,
             'network_id': port['network_id'],
             'port_mac': port['mac_address'],
             'port_id': port['id'],
             'admin_state_up': port['admin_state_up']
         }
         # Set the port status to UP
         db.set_port_status(port['id'], q_const.PORT_STATUS_ACTIVE)
     else:
         entry = {'device': device}
         LOG.debug("%s can not be found in database", device)
     return entry
Exemple #11
0
 def _extend_port_dict_binding(self, context, port):
     port_binding = db.get_port_profile_binding(context.session, port['id'])
     if port_binding:
         port[portbindings.VIF_TYPE] = port_binding.vnic_type
     binding = db.get_network_binding(context.session, port['network_id'])
     fabric = binding.physical_network
     port[portbindings.PROFILE] = {'physical_network': fabric}
     return port
Exemple #12
0
 def _extend_port_dict_binding(self, context, port):
     port_binding = db.get_port_profile_binding(context.session,
                                                port['id'])
     if port_binding:
         port[portbindings.VIF_TYPE] = port_binding.vnic_type
     binding = db.get_network_binding(context.session,
                                      port['network_id'])
     fabric = binding.physical_network
     port[portbindings.PROFILE] = {'physical_network': fabric}
     return port
Exemple #13
0
 def _extend_port_dict_binding(self, context, port):
     port_binding = db.get_port_profile_binding(context.session, port['id'])
     if port_binding:
         port[portbindings.VIF_TYPE] = port_binding.vnic_type
     port[portbindings.CAPABILITIES] = {
         portbindings.CAP_PORT_FILTER:
         'security-group' in self.supported_extension_aliases
     }
     binding = db.get_network_binding(context.session, port['network_id'])
     fabric = binding.physical_network
     port[portbindings.PROFILE] = {'physical_network': fabric}
     return port
Exemple #14
0
 def _extend_network_dict_provider(self, context, network):
     binding = db.get_network_binding(context.session, network['id'])
     network[provider.NETWORK_TYPE] = binding.network_type
     if binding.network_type == constants.TYPE_FLAT:
         network[provider.PHYSICAL_NETWORK] = binding.physical_network
         network[provider.SEGMENTATION_ID] = None
     elif binding.network_type == constants.TYPE_LOCAL:
         network[provider.PHYSICAL_NETWORK] = None
         network[provider.SEGMENTATION_ID] = None
     else:
         network[provider.PHYSICAL_NETWORK] = binding.physical_network
         network[provider.SEGMENTATION_ID] = binding.segmentation_id
Exemple #15
0
 def _extend_network_dict_provider(self, context, network):
     binding = db.get_network_binding(context.session, network['id'])
     network[provider.NETWORK_TYPE] = binding.network_type
     if binding.network_type == svc_constants.TYPE_FLAT:
         network[provider.PHYSICAL_NETWORK] = binding.physical_network
         network[provider.SEGMENTATION_ID] = None
     elif binding.network_type == svc_constants.TYPE_LOCAL:
         network[provider.PHYSICAL_NETWORK] = None
         network[provider.SEGMENTATION_ID] = None
     else:
         network[provider.PHYSICAL_NETWORK] = binding.physical_network
         network[provider.SEGMENTATION_ID] = binding.segmentation_id
Exemple #16
0
 def delete_network(self, context, net_id):
     LOG.debug(_("delete network"))
     session = context.session
     with session.begin(subtransactions=True):
         binding = db.get_network_binding(session, net_id)
         super(MellanoxEswitchPlugin, self).delete_network(context, net_id)
         if binding.segmentation_id != constants.LOCAL_VLAN_ID:
             db.release_network(session, binding.physical_network,
                                binding.segmentation_id,
                                self.network_vlan_ranges)
         # the network_binding record is deleted via cascade from
         # the network record, so explicit removal is not necessary
     self.notifier.network_delete(context, net_id)
 def _extend_port_dict_binding(self, context, port):
     port_binding = db.get_port_profile_binding(context.session,
                                                port['id'])
     if port_binding:
         port[portbindings.VIF_TYPE] = port_binding.vnic_type
     port[portbindings.CAPABILITIES] = {
         portbindings.CAP_PORT_FILTER:
         'security-group' in self.supported_extension_aliases}
     binding = db.get_network_binding(context.session,
                                      port['network_id'])
     fabric = binding.physical_network
     port[portbindings.PROFILE] = {'physical_network': fabric}
     return port
Exemple #18
0
 def update_port(self, context, port_id, port):
     original_port = super(MellanoxEswitchPlugin,
                           self).get_port(context, port_id)
     session = context.session
     with session.begin(subtransactions=True):
         port = super(MellanoxEswitchPlugin,
                      self).update_port(context, port_id, port)
     if original_port['admin_state_up'] != port['admin_state_up']:
         binding = db.get_network_binding(context.session,
                                          port['network_id'])
         self.notifier.port_update(context, port, binding.physical_network,
                                   binding.network_type,
                                   binding.segmentation_id)
     return self._extend_port_dict_binding(context, port)
Exemple #19
0
 def delete_network(self, context, net_id):
     LOG.debug(_("Delete network"))
     session = context.session
     with session.begin(subtransactions=True):
         binding = db.get_network_binding(session, net_id)
         super(MellanoxEswitchPlugin, self).delete_network(context,
                                                           net_id)
         if binding.segmentation_id != constants.LOCAL_VLAN_ID:
             db.release_network(session, binding.physical_network,
                                binding.segmentation_id,
                                self.network_vlan_ranges)
         # the network_binding record is deleted via cascade from
         # the network record, so explicit removal is not necessary
     self.notifier.network_delete(context, net_id)
 def update_port(self, context, port_id, port):
     original_port = super(MellanoxEswitchPlugin, self).get_port(context,
                                                                 port_id)
     session = context.session
     with session.begin(subtransactions=True):
         port = super(MellanoxEswitchPlugin, self).update_port(context,
                                                               port_id,
                                                               port)
     if original_port['admin_state_up'] != port['admin_state_up']:
         binding = db.get_network_binding(context.session,
                                          port['network_id'])
         self.notifier.port_update(context, port,
                                   binding.physical_network,
                                   binding.network_type,
                                   binding.segmentation_id)
     return self._extend_port_dict_binding(context, port)
 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 %s details requested from %s", device, agent_id)
     port = self.get_port_from_device(device)
     if port:
         binding = db.get_network_binding(db_api.get_session(),
                                          port['network_id'])
         entry = {'device': device,
                  'physical_network': binding.physical_network,
                  'network_type': binding.network_type,
                  'vlan_id': binding.segmentation_id,
                  'network_id': port['network_id'],
                  'port_mac': port['mac_address'],
                  'port_id': port['id'],
                  'admin_state_up': port['admin_state_up']}
         # Set the port status to UP
         db.set_port_status(port['id'], q_const.PORT_STATUS_ACTIVE)
     else:
         entry = {'device': device}
         LOG.debug("%s can not be found in database", device)
     return entry