Set lock_path correctly.
[openstack-build/neutron-build.git] / neutron / agent / l3 / fip_rule_priority_allocator.py
1 # Copyright 2015 IBM Corporation
2 #
3 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
4 #    not use this file except in compliance with the License. You may obtain
5 #    a copy of the License at
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
9 #    Unless required by applicable law or agreed to in writing, software
10 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 #    License for the specific language governing permissions and limitations
13 #    under the License.
14
15 from neutron.agent.l3.item_allocator import ItemAllocator
16
17
18 class FipPriority(object):
19     def __init__(self, index):
20         self.index = index
21
22     def __repr__(self):
23         return str(self.index)
24
25     def __hash__(self):
26         return hash(self.__repr__())
27
28     def __eq__(self, other):
29         if isinstance(other, FipPriority):
30             return (self.index == other.index)
31         else:
32             return False
33
34
35 class FipRulePriorityAllocator(ItemAllocator):
36     """Manages allocation of floating ips rule priorities.
37         IP rule priorities assigned to DVR floating IPs need
38         to be preserved over L3 agent restarts.
39         This class provides an allocator which saves the prirorities
40         to a datastore which will survive L3 agent restarts.
41     """
42     def __init__(self, data_store_path, priority_rule_start,
43                  priority_rule_end):
44         """Create the necessary pool and create the item allocator
45             using ',' as the delimiter and FipRulePriorityAllocator as the
46             class type
47         """
48         pool = set(FipPriority(str(s)) for s in range(priority_rule_start,
49                                                       priority_rule_end))
50
51         super(FipRulePriorityAllocator, self).__init__(data_store_path,
52                                                        FipPriority,
53                                                        pool)