Skip to content

Commit

Permalink
gcp: specify disk type
Browse files Browse the repository at this point in the history
  • Loading branch information
karmab committed Jun 13, 2024
1 parent 40c4b7b commit eccf5a5
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions kvirt/providers/gcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,16 @@ def create(self, name, virttype=None, profile='', flavor=None, plan='kvirt', cpu
body['networkInterfaces'].append(newnet)
body['disks'] = []
for index, disk in enumerate(disks):
disk_type = overrides.get('diskinterface') or overrides.get('disktype')
if isinstance(disk, int):
disksize = disk
elif isinstance(disk, str) and disk.isdigit():
disksize = int(disk)
elif isinstance(disk, dict):
disksize = disk.get('size', '10')
disk_type = disk.get('type') or disk.get('interface') or disk_type
if disk_type is not None:
disk_type = f'/compute/v1/projects/{project}/zones/{zone}/diskTypes/{disk_type}'
newdisk = {'boot': False, 'autoDelete': True}
if index == 0 and image is not None:
if image.startswith('rhcos'):
Expand All @@ -277,11 +281,15 @@ def create(self, name, virttype=None, profile='', flavor=None, plan='kvirt', cpu
pprint("Rounding primary disk to to 20Gb")
newdisk['initializeParams'] = {'sourceImage': src, 'diskSizeGb': disksize}
newdisk['boot'] = True
if disk_type is not None:
newdisk['initializeParams']['diskType'] = disk_type
else:
diskname = f"{name}-disk{index}"
diskpath = f'/compute/v1/projects/{project}/zones/{zone}/disks/{diskname}'
info = {'name': diskname, 'sizeGb': disksize}
conn.disks().insert(zone=zone, project=project, body=info).execute()
init = {'name': diskname, 'sizeGb': disksize}
if disk_type is not None:
init['type'] = disk_type
conn.disks().insert(zone=zone, project=project, body=init).execute()
timeout = 0
while True:
if timeout > 60:
Expand All @@ -303,7 +311,6 @@ def create(self, name, virttype=None, profile='', flavor=None, plan='kvirt', cpu
for entry in [field for field in metadata if field in METADATA_FIELDS]:
value = metadata[entry].replace('.', '-')
body['labels'][entry] = value

if not keys:
publickeyfile = get_ssh_pub_key()
if publickeyfile is not None:
Expand Down Expand Up @@ -987,6 +994,9 @@ def add_disk(self, name, size, pool=None, thin=True, image=None, shareable=False
numdisks = len(vm['disks']) + 1
diskname = f"{name}-disk{numdisks}"
body = {'sizeGb': size, 'name': diskname}
disk_type = overrides.get('diskinterface') or overrides.get('disktype')
if disk_type is not None:
body['diskType'] = disk_type
conn.disks().insert(zone=zone, project=project, body=body).execute()
timeout = 0
while True:
Expand Down

0 comments on commit eccf5a5

Please sign in to comment.