1 # Copyright 2015 IBM Corporation
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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
15 from neutron.agent.l3.item_allocator import ItemAllocator
18 class FipPriority(object):
19 def __init__(self, index):
23 return str(self.index)
26 return hash(self.__repr__())
28 def __eq__(self, other):
29 if isinstance(other, FipPriority):
30 return (self.index == other.index)
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.
42 def __init__(self, data_store_path, priority_rule_start,
44 """Create the necessary pool and create the item allocator
45 using ',' as the delimiter and FipRulePriorityAllocator as the
48 pool = set(FipPriority(str(s)) for s in range(priority_rule_start,
51 super(FipRulePriorityAllocator, self).__init__(data_store_path,