'Attach a port to policy and return any previous policy on port.'

def set_port_policy(self, port, policy):

    port_id = port['port_id']
    old_policy = self.get_port_policy(port)
    self.known_policies[policy.id] = policy
    self.port_policies[port_id] = policy.id
    self.qos_policy_ports[policy.id][port_id] = port
    if (old_policy and (old_policy.id != policy.id)):
        del self.qos_policy_ports[old_policy.id][port_id]
    return old_policy
