Exemple #1
0
 def test_add_network_binding(self):
     self.assertIsNone(ovs_db_v2.get_network_binding(self.session,
                                                     TEST_NETWORK_ID))
     ovs_db_v2.add_network_binding(self.session, TEST_NETWORK_ID, 'vlan',
                                   PHYS_NET, 1234)
     binding = ovs_db_v2.get_network_binding(self.session, TEST_NETWORK_ID)
     self.assertIsNotNone(binding)
     self.assertEqual(binding.network_id, TEST_NETWORK_ID)
     self.assertEqual(binding.network_type, 'vlan')
     self.assertEqual(binding.physical_network, PHYS_NET)
     self.assertEqual(binding.segmentation_id, 1234)
Exemple #2
0
 def test_add_network_binding(self):
     self.assertIsNone(ovs_db_v2.get_network_binding(self.session,
                                                     TEST_NETWORK_ID))
     ovs_db_v2.add_network_binding(self.session, TEST_NETWORK_ID, 'vlan',
                                   PHYS_NET, 1234)
     binding = ovs_db_v2.get_network_binding(self.session, TEST_NETWORK_ID)
     self.assertIsNotNone(binding)
     self.assertEqual(binding.network_id, TEST_NETWORK_ID)
     self.assertEqual(binding.network_type, 'vlan')
     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 = ovs_db_v2.get_port(device)
     if port:
         binding = ovs_db_v2.get_network_binding(None, port['network_id'])
         entry = {
             'device': device,
             'network_id': port['network_id'],
             'port_id': port['id'],
             'admin_state_up': port['admin_state_up'],
             'network_type': binding.network_type,
             'segmentation_id': binding.segmentation_id,
             'physical_network': binding.physical_network
         }
         new_status = (q_const.PORT_STATUS_ACTIVE if port['admin_state_up']
                       else q_const.PORT_STATUS_DOWN)
         if port['status'] != new_status:
             ovs_db_v2.set_port_status(port['id'], new_status)
     else:
         entry = {'device': device}
         LOG.debug(_("%s can not be found in database"), device)
     return entry
Exemple #4
0
    def update_port(self, context, id, port):
        session = context.session
        need_port_update_notify = False
        with session.begin(subtransactions=True):
            original_port = super(OVSQuantumPluginV2,
                                  self).get_port(context, id)
            updated_port = super(OVSQuantumPluginV2,
                                 self).update_port(context, id, port)
            need_port_update_notify = self.update_security_group_on_port(
                context, id, port, original_port, updated_port)
            self._process_portbindings_create_and_update(
                context, port['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 = ovs_db_v2.get_network_binding(None,
                                                    updated_port['network_id'])
            self.notifier.port_update(context, updated_port,
                                      binding.network_type,
                                      binding.segmentation_id,
                                      binding.physical_network)
        return updated_port
    def update_port(self, context, id, port):
        session = context.session

        need_port_update_notify = False
        with session.begin(subtransactions=True):
            original_port = super(OVSQuantumPluginV2, self).get_port(
                context, id)
            updated_port = super(OVSQuantumPluginV2, self).update_port(
                context, id, port)
            need_port_update_notify = self.update_security_group_on_port(
                context, 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 = ovs_db_v2.get_network_binding(None,
                                                    updated_port['network_id'])
            self.notifier.port_update(context, updated_port,
                                      binding.network_type,
                                      binding.segmentation_id,
                                      binding.physical_network)

        return self._extend_port_dict_binding(context, updated_port)
Exemple #6
0
 def update_port(self, context, id, port):
     original_port = super(OVSQuantumPluginV2, self).get_port(context, id)
     port = super(OVSQuantumPluginV2, self).update_port(context, id, port)
     if original_port["admin_state_up"] != port["admin_state_up"]:
         binding = ovs_db_v2.get_network_binding(None, port["network_id"])
         self.notifier.port_update(
             context, port, binding.network_type, binding.segmentation_id, binding.physical_network
         )
     return self._extend_port_dict_binding(context, port)
 def update_port(self, context, id, port):
     original_port = super(OVSQuantumPluginV2, self).get_port(context, id)
     port = super(OVSQuantumPluginV2, self).update_port(context, id, port)
     if original_port['admin_state_up'] != port['admin_state_up']:
         binding = ovs_db_v2.get_network_binding(None, port['network_id'])
         self.notifier.port_update(context, port, binding.network_type,
                                   binding.segmentation_id,
                                   binding.physical_network)
     return port
 def update_port(self, context, id, port):
     original_port = super(OVSQuantumPluginV2, self).get_port(context,
                                                              id)
     port = super(OVSQuantumPluginV2, self).update_port(context, id, port)
     if original_port['admin_state_up'] != port['admin_state_up']:
         binding = ovs_db_v2.get_network_binding(None,
                                                 port['network_id'])
         self.notifier.port_update(self.rpc_context, port,
                                   binding.network_type,
                                   binding.segmentation_id,
                                   binding.physical_network)
     return port
Exemple #9
0
 def delete_network(self, context, id):
     session = context.session
     with session.begin(subtransactions=True):
         binding = ovs_db_v2.get_network_binding(session, id)
         super(OVSQuantumPluginV2, self).delete_network(context, id)
         if binding.network_type == constants.TYPE_GRE:
             ovs_db_v2.release_tunnel(session, binding.segmentation_id, self.tunnel_id_ranges)
         elif binding.network_type in [constants.TYPE_VLAN, constants.TYPE_FLAT]:
             ovs_db_v2.release_vlan(
                 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, id)
Exemple #10
0
 def update_port(self, context, id, port):
     if self.agent_rpc:
         original_port = super(OVSQuantumPluginV2, self).get_port(context,
                                                                  id)
     port = super(OVSQuantumPluginV2, self).update_port(context, id, port)
     if self.agent_rpc:
         if original_port['admin_state_up'] != port['admin_state_up']:
             binding = ovs_db_v2.get_network_binding(None,
                                                     port['network_id'])
             # REVISIT(rkukura): Either all binding data or no
             # binding data needed.
             self.notifier.port_update(self.rpc_context, port,
                                       binding.segmentation_id)
     return port
 def _extend_network_dict_provider(self, context, network):
     if self._check_provider_view_auth(context, network):
         binding = ovs_db_v2.get_network_binding(context.session,
                                                 network['id'])
         network[provider.NETWORK_TYPE] = binding.network_type
         if binding.network_type == constants.TYPE_GRE:
             network[provider.PHYSICAL_NETWORK] = None
             network[provider.SEGMENTATION_ID] = binding.segmentation_id
         elif binding.network_type == constants.TYPE_FLAT:
             network[provider.PHYSICAL_NETWORK] = binding.physical_network
             network[provider.SEGMENTATION_ID] = None
         elif binding.network_type == constants.TYPE_VLAN:
             network[provider.PHYSICAL_NETWORK] = binding.physical_network
             network[provider.SEGMENTATION_ID] = binding.segmentation_id
 def _extend_network_dict_provider(self, context, network):
     if self._check_provider_view_auth(context, network):
         binding = ovs_db_v2.get_network_binding(context.session,
                                                 network['id'])
         network[provider.NETWORK_TYPE] = binding.network_type
         if binding.network_type == constants.TYPE_GRE:
             network[provider.PHYSICAL_NETWORK] = None
             network[provider.SEGMENTATION_ID] = binding.segmentation_id
         elif binding.network_type == constants.TYPE_FLAT:
             network[provider.PHYSICAL_NETWORK] = binding.physical_network
             network[provider.SEGMENTATION_ID] = None
         elif binding.network_type == constants.TYPE_VLAN:
             network[provider.PHYSICAL_NETWORK] = binding.physical_network
             network[provider.SEGMENTATION_ID] = binding.segmentation_id
Exemple #13
0
 def delete_network(self, context, id):
     session = context.session
     with session.begin(subtransactions=True):
         binding = ovs_db_v2.get_network_binding(session, id)
         super(OVSQuantumPluginV2, self).delete_network(context, id)
         if binding.network_type == constants.TYPE_GRE:
             ovs_db_v2.release_tunnel(session, binding.segmentation_id,
                                      self.tunnel_id_ranges)
         elif binding.network_type in [constants.TYPE_VLAN,
                                       constants.TYPE_FLAT]:
             ovs_db_v2.release_vlan(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, id)
 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 = ovs_db_v2.get_port(device)
     if port:
         binding = ovs_db_v2.get_network_binding(None, port['network_id'])
         entry = {'device': device,
                  'network_id': port['network_id'],
                  'port_id': port['id'],
                  'admin_state_up': port['admin_state_up'],
                  'network_type': binding.network_type,
                  'segmentation_id': binding.segmentation_id,
                  'physical_network': binding.physical_network}
         # Set the port status to UP
         ovs_db_v2.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 #15
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 = ovs_db_v2.get_port(device)
     if port:
         binding = ovs_db_v2.get_network_binding(None, port['network_id'])
         entry = {'device': device,
                  'network_id': port['network_id'],
                  'port_id': port['id'],
                  'admin_state_up': port['admin_state_up'],
                  'network_type': binding.network_type,
                  'segmentation_id': binding.segmentation_id,
                  'physical_network': binding.physical_network}
         # Set the port status to UP
         ovs_db_v2.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
 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"),
               locals())
     port = ovs_db_v2.get_port(device)
     if port:
         binding = ovs_db_v2.get_network_binding(None, port['network_id'])
         entry = {'device': device,
                  'network_id': port['network_id'],
                  'port_id': port['id'],
                  'admin_state_up': port['admin_state_up'],
                  'network_type': binding.network_type,
                  'segmentation_id': binding.segmentation_id,
                  'physical_network': binding.physical_network}
         new_status = (q_const.PORT_STATUS_ACTIVE if port['admin_state_up']
                       else q_const.PORT_STATUS_DOWN)
         if port['status'] != new_status:
             ovs_db_v2.set_port_status(port['id'], new_status)
     else:
         entry = {'device': device}
         LOG.debug(_("%s can not be found in database"), device)
     return entry
Exemple #17
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"), locals())
     port = ovs_db_v2.get_port(device)
     if port:
         binding = ovs_db_v2.get_network_binding(None, port["network_id"])
         entry = {
             "device": device,
             "network_id": port["network_id"],
             "port_id": port["id"],
             "admin_state_up": port["admin_state_up"],
             "network_type": binding.network_type,
             "segmentation_id": binding.segmentation_id,
             "physical_network": binding.physical_network,
         }
         new_status = q_const.PORT_STATUS_ACTIVE if port["admin_state_up"] else q_const.PORT_STATUS_DOWN
         if port["status"] != new_status:
             ovs_db_v2.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_segmentation_id(self, network_id):
     binding_seg_id = odb.get_network_binding(None, network_id)
     return binding_seg_id.segmentation_id
Exemple #19
0
 def _get_segmentation_id(self, network_id):
     binding_seg_id = odb.get_network_binding(None, network_id)
     if not binding_seg_id:
         raise cexc.NetworkSegmentIDNotFound(net_id=network_id)
     return binding_seg_id.segmentation_id
Exemple #20
0
 def _get_segmentation_id(self, network_id):
     binding_seg_id = odb.get_network_binding(None, network_id)
     return binding_seg_id.segmentation_id