Skip to content

Commit

Permalink
Merge "Authorise IndexAllocator to reserve index outside the allocati…
Browse files Browse the repository at this point in the history
…on list" into R2.22-dev
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Sep 16, 2015
2 parents 70f3de3 + ce5d3b2 commit 8805dde
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/config/api-server/vnc_addr_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ def __init__(self, name, prefix, prefix_len,
exclude.append(service_node_address)
self._db_conn.subnet_create_allocator(name, alloc_int_list,
addr_from_start,
should_persist=should_persist)
should_persist,
network.first,
network.size)

# reserve excluded addresses
for addr in exclude:
Expand Down
10 changes: 6 additions & 4 deletions src/config/api-server/vnc_cfg_ifmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,14 +1169,15 @@ def __init__(self, instance_id, zk_server_ip, reset_config, db_prefix,
# end __init__

def create_subnet_allocator(self, subnet, subnet_alloc_list,
addr_from_start, should_persist):
addr_from_start, should_persist,
start_subnet, size):
# TODO handle subnet resizing change, ignore for now
if subnet not in self._subnet_allocators:
if addr_from_start is None:
addr_from_start = False
self._subnet_allocators[subnet] = IndexAllocator(
self._zk_client, self._subnet_path+'/'+subnet+'/',
size=0, start_idx=0, reverse=not addr_from_start,
size=size, start_idx=start_subnet, reverse=not addr_from_start,
alloc_list=subnet_alloc_list,
max_alloc=self._MAX_SUBNET_ADDR_ALLOC)
# end create_subnet_allocator
Expand Down Expand Up @@ -1718,10 +1719,11 @@ def subnet_free_req(self, subnet, addr):
# end subnet_free_req

def subnet_create_allocator(self, subnet, subnet_alloc_list,
addr_from_start, should_persist):
addr_from_start, should_persist,
start_subnet, size):
return self._zk_db.create_subnet_allocator(subnet,
subnet_alloc_list, addr_from_start,
should_persist)
should_persist, start_subnet, size)
# end subnet_create_allocator

def subnet_delete_allocator(self, subnet):
Expand Down
19 changes: 10 additions & 9 deletions src/config/common/zkclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class IndexAllocator(object):

def __init__(self, zookeeper_client, path, size=0, start_idx=0,
reverse=False,alloc_list=None, max_alloc=0):
self._size = size
self._start_idx = start_idx
if alloc_list is None:
self._alloc_list = [{'start':start_idx, 'end':start_idx+size}]
else:
Expand All @@ -31,7 +33,6 @@ def __init__(self, zookeeper_client, path, size=0, start_idx=0,

alloc_count = len(self._alloc_list)
total_size = 0
start_idx = self._alloc_list[0]['start']
size = 0

#check for overlap in alloc_list --TODO
Expand All @@ -44,10 +45,8 @@ def __init__(self, zookeeper_client, path, size=0, start_idx=0,
size += idx_end_addr - idx_start_addr + 1
size += self._alloc_list[alloc_count-1]['end'] - self._alloc_list[alloc_count-1]['start'] + 1

self._size = size
self._start_idx = start_idx
if max_alloc == 0:
self._max_alloc = self._size
self._max_alloc = size
else:
self._max_alloc = max_alloc

Expand Down Expand Up @@ -136,6 +135,7 @@ def reset_in_use(self, idx):
# end reset_in_use

def alloc(self, value=None):
# Allocates a index from the allocation list
if self._in_use.all():
idx = self._in_use.length()
if idx > self._max_alloc:
Expand All @@ -156,17 +156,18 @@ def alloc(self, value=None):
# end alloc

def reserve(self, idx, value=None):
bit_idx = self._get_bit_from_zk_index(idx)
if bit_idx < 0:
return None
# Reserves the requested index if available
if not self._start_idx <= idx < self._start_idx + self._size:
return None

try:
# Create a node at path and return its integer value
id_str = "%(#)010d" % {'#': idx}
self._zookeeper_client.create_node(self._path + id_str, value)
self._set_in_use(bit_idx)
self.set_in_use(idx)
return idx
except ResourceExistsError:
self._set_in_use(bit_idx)
self.set_in_use(idx)
existing_value = self.read(idx)
if (value == existing_value or
existing_value is None): # upgrade case
Expand Down

0 comments on commit 8805dde

Please sign in to comment.