Skip to content

Commit

Permalink
Check media before adding new/existing volume
Browse files Browse the repository at this point in the history
  • Loading branch information
catborise committed Feb 14, 2019
1 parent ebf251f commit 2dc83f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions instances/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ def check_user_quota(instance, cpu, memory, disk_size):
return msg

def get_new_disk_dev(media, disks, bus):
existing_disk_devs = []
existing_media_devs = []
if bus == "virtio":
dev_base = "vd"
elif bus == "ide":
Expand All @@ -203,9 +205,14 @@ def get_new_disk_dev(media, disks, bus):
dev_base = "fd"
else:
dev_base = "sd"
existing_disk_devs = [disk['dev'] for disk in disks]

if disks:
existing_disk_devs = [disk['dev'] for disk in disks]

# cd-rom bus could be virtio/sata, because of that we should check it also
existing_media_devs = [disk['dev'] for disk in media]
if media:
existing_media_devs = [m['dev'] for m in media]

for l in string.lowercase:
dev = dev_base + l
if dev not in existing_disk_devs and dev not in existing_media_devs:
Expand Down Expand Up @@ -465,7 +472,7 @@ def migrate_instance(new_compute, instance, live=False, unsafe=False, xml_del=Fa
meta_prealloc = request.POST.get('meta_prealloc', False)
bus = request.POST.get('bus', default_bus)
cache = request.POST.get('cache', default_cache)
target = get_new_disk_dev(None, disks, bus)
target = get_new_disk_dev(media, disks, bus)

path = connCreate.create_volume(storage, name, size, format, meta_prealloc, default_owner)
conn.attach_disk(path, target, subdriver=format, cache=cache, targetbus=bus)
Expand All @@ -487,7 +494,7 @@ def migrate_instance(new_compute, instance, live=False, unsafe=False, xml_del=Fa

format = connCreate.get_volume_type(name)
path = connCreate.get_target_path()
target = get_new_disk_dev(None, disks, bus)
target = get_new_disk_dev(media, disks, bus)
source = path + "/" + name;

conn.attach_disk(source, target, subdriver=format, cache=cache, targetbus=bus)
Expand Down
2 changes: 1 addition & 1 deletion storages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def get_volumes(request, compute_id, pool):
compute.type,
pool)
conn.refresh()
except libvirtError as liberr:
except libvirtError:
pass
data['vols'] = sorted(conn.get_volumes())
return HttpResponse(json.dumps(data))

0 comments on commit 2dc83f3

Please sign in to comment.