def test_add_network_binding(self): with self.network() as network: TEST_NETWORK_ID = network['network']['id'] 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)
def update_port(self, context, id, port): session = context.session need_port_update_notify = False with session.begin(subtransactions=True): original_port = super(OVSNeutronPluginV2, self).get_port( context, id) updated_port = super(OVSNeutronPluginV2, self).update_port( context, id, port) if addr_pair.ADDRESS_PAIRS in port['port']: need_port_update_notify |= ( self.update_address_pairs_on_port(context, id, port, original_port, updated_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._update_extra_dhcp_opts_on_port( context, id, 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 changed_fixed_ips = "fixed_ips" in port["port"] with session.begin(subtransactions=True): original_port = super(OVSNeutronPluginV2, self).get_port(context, id) updated_port = super(OVSNeutronPluginV2, self).update_port(context, id, port) if self.is_address_pairs_attribute_updated(original_port, port): self._delete_allowed_address_pairs(context, id) self._process_create_allowed_address_pairs(context, updated_port, port["port"][addr_pair.ADDRESS_PAIRS]) need_port_update_notify = True elif changed_fixed_ips: self._check_fixed_ips_and_address_pairs_no_overlap(context, updated_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._update_extra_dhcp_opts_on_port(context, id, 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 test_add_network_binding(self): params = {'provider:network_type': 'vlan', 'provider:physical_network': PHYS_NET, 'provider:segmentation_id': 1234} params['arg_list'] = tuple(params.keys()) with self.network(**params) as network: TEST_NETWORK_ID = network['network']['id'] 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)
def delete_network(self, context, id): session = context.session with session.begin(subtransactions=True): binding = ovs_db_v2.get_network_binding(session, id) super(OVSNeutronPluginV2, self).delete_network(context, id) if binding.network_type in constants.TUNNEL_NETWORK_TYPES: ovs_db_v2.release_tunnel(session, binding.segmentation_id, self.tunnel_id_ranges) elif binding.network_type in [svc_constants.TYPE_VLAN, svc_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 _extend_network_dict_provider(self, context, network): binding = ovs_db_v2.get_network_binding(context.session, network['id']) network[provider.NETWORK_TYPE] = binding.network_type if binding.network_type in constants.TUNNEL_NETWORK_TYPES: 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 elif binding.network_type == constants.TYPE_LOCAL: network[provider.PHYSICAL_NETWORK] = None network[provider.SEGMENTATION_ID] = None
def update_port(self, context, id, port): session = context.session need_port_update_notify = False changed_fixed_ips = 'fixed_ips' in port['port'] with session.begin(subtransactions=True): original_port = super(OVSNeutronPluginV2, self).get_port( context, id) updated_port = super(OVSNeutronPluginV2, self).update_port( context, id, port) if addr_pair.ADDRESS_PAIRS in port['port']: need_port_update_notify |= ( self.update_address_pairs_on_port(context, id, port, original_port, updated_port)) elif changed_fixed_ips: self._check_fixed_ips_and_address_pairs_no_overlap( context, updated_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._update_extra_dhcp_opts_on_port( context, id, port, updated_port) secgrp_member_updated = self.is_security_group_member_updated( context, original_port, updated_port) need_port_update_notify |= secgrp_member_updated 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) if secgrp_member_updated: old_set = set(original_port.get(ext_sg.SECURITYGROUPS)) new_set = set(updated_port.get(ext_sg.SECURITYGROUPS)) self.notifier.security_groups_member_updated( context, old_set ^ new_set) return updated_port
def update_port(self, context, id, port): forward_ports = self._process_nat_update(context, port['port'], id) session = context.session need_port_update_notify = False changed_fixed_ips = 'fixed_ips' in port['port'] with session.begin(subtransactions=True): original_port = super(OVSNeutronPluginV2, self).get_port( context, id) updated_port = super(OVSNeutronPluginV2, self).update_port( context, id, port) if addr_pair.ADDRESS_PAIRS in port['port']: self._delete_allowed_address_pairs(context, id) self._process_create_allowed_address_pairs( context, updated_port, port['port'][addr_pair.ADDRESS_PAIRS]) need_port_update_notify = True elif changed_fixed_ips: self._check_fixed_ips_and_address_pairs_no_overlap( context, updated_port) if forward_ports: ovs_db_v2.clear_port_forwarding(session, updated_port['id']) ovs_db_v2.add_port_forwarding(session, updated_port['id'], forward_ports) self._extend_port_dict_nat(context, updated_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._update_extra_dhcp_opts_on_port( context, id, 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 retrieve_utif_info(self, context, neutron_port): plugin = manager.NeutronManager.get_plugin() session = context.session network_id = neutron_port["network_id"] network_binding = ovs_db_v2.get_network_binding(session, network_id) if not network_binding["segmentation_id"]: raise exc.UtifInfoError( err_msg=_("No segmentation_id found for the network, " "please be sure that tenant_network_type is vlan")) network = plugin._get_network(context, network_id) is_gw = neutron_port["device_owner"] == "network:router_gateway" result = h_info.UtifInfo(vlan=network_binding["segmentation_id"], network_name=network["name"], network_id=network["id"], is_gw=is_gw, owner_tenant=network["tenant_id"], port_id=neutron_port["id"], mac_address=neutron_port["mac_address"]) return result
def update_port(self, context, id, port): session = context.session need_port_update_notify = False changed_fixed_ips = 'fixed_ips' in port['port'] with session.begin(subtransactions=True): original_port = super(OVSNeutronPluginV2, self).get_port( context, id) updated_port = super(OVSNeutronPluginV2, self).update_port( context, id, port) if self.is_address_pairs_attribute_updated(original_port, port): self._delete_allowed_address_pairs(context, id) self._process_create_allowed_address_pairs( context, updated_port, port['port'][addr_pair.ADDRESS_PAIRS]) need_port_update_notify = True elif changed_fixed_ips: self._check_fixed_ips_and_address_pairs_no_overlap( context, updated_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._update_extra_dhcp_opts_on_port( context, id, 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(OVSNeutronPluginV2, self).get_port(context, id) updated_port = super(OVSNeutronPluginV2, self).update_port(context, id, port) if addr_pair.ADDRESS_PAIRS in port['port']: need_port_update_notify |= (self.update_address_pairs_on_port( context, id, port, original_port, updated_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._update_extra_dhcp_opts_on_port( context, id, port, updated_port) secgrp_member_updated = self.is_security_group_member_updated( context, original_port, updated_port) need_port_update_notify |= secgrp_member_updated 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) if secgrp_member_updated: old_set = set(original_port.get(ext_sg.SECURITYGROUPS)) new_set = set(updated_port.get(ext_sg.SECURITYGROUPS)) self.notifier.security_groups_member_updated( context, old_set ^ new_set) return updated_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 %(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
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
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
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