Commit 32d29b57 authored by Alain Takoudjou's avatar Alain Takoudjou

Avoid getting wrong storage path when creating kvm external disk

parent 242e94db
......@@ -36,11 +36,8 @@ external_disk_number = %(external-disk-number)s
external_disk_size = '%(external-disk-size)s'
disk_storage_dict = {}
disk_storage_list = """%(disk-storage-list)s""".split('\n')
for storage in disk_storage_list:
if storage:
key, val = storage.split(' ')
disk_storage_dict[key.strip()] = val.strip()
map_storage_list = ['data%%r' %% (i + 1) for i in range(0, len(disk_storage_dict))]
map_storage_list = []
etc_directory = '%(etc-directory)s'.strip()
def md5Checksum(file_path):
with open(file_path, 'rb') as fh:
......@@ -71,6 +68,22 @@ def getSocketStatus(host, port):
break
return s
def getMapStorageList(disk_storage_dict):
map_disk_file = os.path.join(etc_directory, '.data-disk-ids')
id_list = []
if os.path.exists(map_disk_file):
with open(map_disk_file, 'r') as mf:
# ID are writen in one line: data1 data3 data2 ...
content = mf.readline()
if content:
id_list = [id for id in content.split(' ') if disk_storage_dict.has_key(id)]
for key in disk_storage_dict:
if not key in id_list:
id_list.append(key)
with open(map_disk_file, 'w') as mf:
mf.write(' '.join(id_list))
return id_list
# Download existing hard drive if needed at first boot
if not os.path.exists(disk_path) and virtual_hard_drive_url != '':
print('Downloading virtual hard drive...')
......@@ -109,6 +122,13 @@ if not os.path.exists(disk_path):
# Check and create external disk
additional_disk_list = []
for storage in sorted(disk_storage_list):
if storage:
key, val = storage.split(' ')
disk_storage_dict[key.strip()] = val.strip()
map_storage_list = getMapStorageList(disk_storage_dict)
if disk_storage_dict:
if int(external_disk_number) > 0:
index = 0
......
......@@ -93,7 +93,7 @@ mode = 0644
recipe = hexagonit.recipe.download
url = ${:_profile_base_location_}/instance-kvm.cfg.jinja2
mode = 644
md5sum = 10af5beb60655add4de26f7ae60e32aa
md5sum = 5506e1df6ba32c6ead647636ebece79e
download-only = true
on-update = true
......
......@@ -103,6 +103,7 @@ qemu-path = {{ qemu_executable_location }}
qemu-img-path = {{ qemu_img_executable_location }}
6tunnel-path = {{ sixtunnel_executable_location }}
etc-directory = ${directory:etc}
disk-storage-list =
{% for key, path in storage_dict.items() -%}
{{ ' ' ~ key ~ ' ' ~ path }}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment