def test__is_network_device_port(self): self.assertFalse(utils.is_network_device_port(self.port)) port = self._create_fake_port() port['device_owner'] = constants.DEVICE_OWNER_DHCP self.assertTrue(utils.is_network_device_port(port)) port['device_owner'] = 'neutron:LOADBALANCERV2' self.assertTrue(utils.is_network_device_port(port))
def update_network(self, txn, network, original_network, reset=False, qos_rules=None): updated_port_ids = set([]) if not reset and not original_network: # If there is no information about the previous QoS policy, do not # make any change. return updated_port_ids qos_policy_id = network.get('qos_policy_id') if not reset: original_qos_policy_id = original_network.get('qos_policy_id') if qos_policy_id == original_qos_policy_id: return updated_port_ids # No QoS policy change # NOTE(ralonsoh): we don't use the transaction context because some # ports can belong to other projects. admin_context = n_context.get_admin_context() for port in qos_binding.QosPolicyPortBinding.get_ports_by_network_id( admin_context, network['id']): if utils.is_network_device_port(port): continue self._update_port_qos_rules(txn, port['id'], network['id'], qos_policy_id, qos_rules) updated_port_ids.add(port['id']) return updated_port_ids
def _update_network_ports(self, context, network_id, options): # Retrieve all ports for this network ports = self._plugin.get_ports(context, filters={'network_id': [network_id]}) for port in ports: # Don't apply qos rules if port has a policy port_policy_id = port.get('qos_policy_id') if port_policy_id: continue # Don't apply qos rules to network devices if utils.is_network_device_port(port): continue # Call into OVN client to update port self._driver.update_port(port, qos_options=options)
def update_network(self, txn, network, original_network, reset=False, qos_rules=None): updated_port_ids = set([]) updated_fip_ids = set([]) updated_router_ids = set([]) if not reset and not original_network: # If there is no information about the previous QoS policy, do not # make any change. return updated_port_ids, updated_fip_ids, updated_router_ids qos_policy_id = network.get('qos_policy_id') if not reset: original_qos_policy_id = original_network.get('qos_policy_id') if qos_policy_id == original_qos_policy_id: # No QoS policy change return updated_port_ids, updated_fip_ids, updated_router_ids # NOTE(ralonsoh): we don't use the transaction context because some # ports can belong to other projects. admin_context = n_context.get_admin_context() for port in qos_binding.QosPolicyPortBinding.get_ports_by_network_id( admin_context, network['id']): if (utils.is_network_device_port(port) or utils.is_port_external(port)): continue self._update_port_qos_rules(txn, port['id'], network['id'], qos_policy_id, qos_rules) updated_port_ids.add(port['id']) fips = qos_binding.QosPolicyFloatingIPBinding.get_fips_by_network_id( admin_context, network['id']) fip_ids = [fip.id for fip in fips] for floatingip in self._plugin_l3.get_floatingips( admin_context, filters={'id': fip_ids}): self.update_floatingip(txn, floatingip) updated_fip_ids.add(floatingip['id']) for router in (qos_binding.QosPolicyRouterGatewayIPBinding. get_routers_by_network_id(admin_context, network['id'])): router_dict = self._plugin_l3._make_router_dict(router) self.update_router(txn, router_dict) updated_router_ids.add(router.id) return updated_port_ids, updated_fip_ids, updated_router_ids
def port_effective_qos_policy_id(port): """Return port effective QoS policy If the port does not have any QoS policy reference or is a network device, then return None. """ policy_id = n_utils.effective_qos_policy_id(port) if not policy_id or utils.is_network_device_port(port): return None, None if port.get('qos_policy_id'): return port['qos_policy_id'], 'port' else: return port['qos_network_policy_id'], 'network'
def get_qos_options(self, port): # Is qos service enabled if 'qos_policy_id' not in port: return {} # Don't apply qos rules to network devices if utils.is_network_device_port(port): return {} # Determine if port or network policy should be used context = n_context.get_admin_context() port_policy_id = port.get('qos_policy_id') network_policy_id = None if not port_policy_id: network_policy = qos_policy.QosPolicy.get_network_policy( context, port['network_id']) network_policy_id = network_policy.id if network_policy else None # Generate qos options for the selected policy policy_id = port_policy_id or network_policy_id return self._generate_port_options(context, policy_id)