'Handle agent QoS extension for port.
This method applies a new policy to a port using the QoS driver.
Update events are handled in _handle_notification.'

@lockutils.synchronized('qos-port')
def handle_port(self, context, port):

    port_id = port['port_id']
    port_qos_policy_id = port.get('qos_policy_id')
    network_qos_policy_id = port.get('network_qos_policy_id')
    qos_policy_id = (port_qos_policy_id or network_qos_policy_id)
    if (qos_policy_id is None):
        self._process_reset_port(port)
        return
    if (not self.policy_map.has_policy_changed(port, qos_policy_id)):
        return
    qos_policy = self.resource_rpc.pull(context, resources.QOS_POLICY, qos_policy_id)
    if (qos_policy is None):
        LOG.info(_LI('QoS    policy    %(qos_policy_id)s    applied    to    port    %(port_id)s    is    not    available    on    server,    it    has    been    deleted.    Skipping.'), {'qos_policy_id': qos_policy_id, 'port_id': port_id})
        self._process_reset_port(port)
    else:
        old_qos_policy = self.policy_map.set_port_policy(port, qos_policy)
        if old_qos_policy:
            self.qos_driver.delete(port, old_qos_policy)
            self.qos_driver.update(port, qos_policy)
        else:
            self.qos_driver.create(port, qos_policy)
