Set lock_path correctly.
[openstack-build/neutron-build.git] / neutron / services / qos / notification_drivers / message_queue.py
1 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
2 #    not use this file except in compliance with the License. You may obtain
3 #    a copy of the License at
4 #
5 #         http://www.apache.org/licenses/LICENSE-2.0
6 #
7 #    Unless required by applicable law or agreed to in writing, software
8 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 #    License for the specific language governing permissions and limitations
11 #    under the License.
12
13 from oslo_log import log as logging
14
15 from neutron._i18n import _LW
16 from neutron.api.rpc.callbacks import events
17 from neutron.api.rpc.callbacks.producer import registry
18 from neutron.api.rpc.callbacks import resources
19 from neutron.api.rpc.handlers import resources_rpc
20 from neutron.objects.qos import policy as policy_object
21 from neutron.services.qos.notification_drivers import qos_base
22
23
24 LOG = logging.getLogger(__name__)
25
26
27 def _get_qos_policy_cb(resource, policy_id, **kwargs):
28     context = kwargs.get('context')
29     if context is None:
30         LOG.warning(_LW(
31             'Received %(resource)s %(policy_id)s without context'),
32             {'resource': resource, 'policy_id': policy_id}
33         )
34         return
35
36     policy = policy_object.QosPolicy.get_by_id(context, policy_id)
37     return policy
38
39
40 class RpcQosServiceNotificationDriver(
41     qos_base.QosServiceNotificationDriverBase):
42     """RPC message queue service notification driver for QoS."""
43
44     def __init__(self):
45         self.notification_api = resources_rpc.ResourcesPushRpcApi()
46         registry.provide(_get_qos_policy_cb, resources.QOS_POLICY)
47
48     def get_description(self):
49         return "Message queue updates"
50
51     def create_policy(self, context, policy):
52         #No need to update agents on create
53         pass
54
55     def update_policy(self, context, policy):
56         self.notification_api.push(context, policy, events.UPDATED)
57
58     def delete_policy(self, context, policy):
59         self.notification_api.push(context, policy, events.DELETED)