From d95cc4bd16c7ff5aa34f3ba7ab6a87229de6d4fc Mon Sep 17 00:00:00 2001 From: micafer Date: Thu, 17 Oct 2019 16:56:43 +0200 Subject: [PATCH 1/2] Minor changes --- IM/connectors/EC2.py | 48 ++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/IM/connectors/EC2.py b/IM/connectors/EC2.py index 7a2e7dbbf..085d9d12a 100644 --- a/IM/connectors/EC2.py +++ b/IM/connectors/EC2.py @@ -668,26 +668,26 @@ def launch(self, inf, radl, requested_radl, num_vm, auth_data): i = 0 while i < num_vm: + try: + err_msg = "Launching in region %s with image: %s" % (region_name, ami) + err_msg += " in VPC: %s-%s " % (vpc, subnet) - vm = VirtualMachine(inf, None, self.cloud, radl, requested_radl, self) - vm.destroy = True - inf.add_vm(vm) - user_data = self.get_cloud_init_data(radl, vm, public_key, user) + vm = VirtualMachine(inf, None, self.cloud, radl, requested_radl, self) + vm.destroy = True + inf.add_vm(vm) + user_data = self.get_cloud_init_data(radl, vm, public_key, user) - bdm = boto.ec2.blockdevicemapping.BlockDeviceMapping(conn) - # Force to use magnetic volumes in root device - bdm[block_device_name] = boto.ec2.blockdevicemapping.BlockDeviceType(volume_type="standard", - delete_on_termination=True) + bdm = boto.ec2.blockdevicemapping.BlockDeviceMapping(conn) + # Force to use magnetic volumes in root device + bdm[block_device_name] = boto.ec2.blockdevicemapping.BlockDeviceType(volume_type="standard", + delete_on_termination=True) - volumes = self.get_volumes(conn, vm) - for device, (size, snapshot_id, disk_type) in volumes.items(): - bdm[device] = boto.ec2.blockdevicemapping.BlockDeviceType(snapshot_id=snapshot_id, - volume_type=disk_type, - size=size, delete_on_termination=True) + volumes = self.get_volumes(conn, vm) + for device, (size, snapshot_id, disk_type) in volumes.items(): + bdm[device] = boto.ec2.blockdevicemapping.BlockDeviceType(snapshot_id=snapshot_id, + volume_type=disk_type, + size=size, delete_on_termination=True) - err_msg = "Launching in region %s with image: %s" % (region_name, ami) - err_msg += " in VPC: %s-%s " % (vpc, subnet) - try: if spot: self.log_info("Launching a spot instance") err_msg += " a spot instance " @@ -835,14 +835,22 @@ def get_volumes(conn, vm): disk_device = "sd%s" % disk_device[-1] disk_size = None + snapshot_id = None if disk_url: - _, snapshot_id = EC2CloudConnector.getAMIData(disk_url) - snapshot = conn.get_all_snapshots([snapshot_id])[0] - disk_url = snapshot.id + _, elem_id = EC2CloudConnector.getAMIData(disk_url) + if elem_id.startswith('snap-'): + snapshot_id = conn.get_all_snapshots([elem_id])[0].id + else: + raise Exception("Incorrect snapshot ID: %s" % elem_id) else: disk_size = vm.info.systems[0].getFeature("disk." + str(cont) + ".size").getValue('G') - res["/dev/" + disk_device] = (disk_size, disk_url, disk_type) + # Set standard as default type + if not disk_type: + disk_type = "standard" + vm.info.systems[0].setValue("disk." + str(cont) + ".type", disk_type) + + res["/dev/" + disk_device] = (disk_size, snapshot_id, disk_type) cont += 1 return res From 424a73eb44319c2d1a2002a673a0de41f44ce785 Mon Sep 17 00:00:00 2001 From: micafer Date: Fri, 18 Oct 2019 08:26:58 +0200 Subject: [PATCH 2/2] Implements #929 --- IM/connectors/EC2.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/IM/connectors/EC2.py b/IM/connectors/EC2.py index 085d9d12a..836407634 100644 --- a/IM/connectors/EC2.py +++ b/IM/connectors/EC2.py @@ -841,7 +841,11 @@ def get_volumes(conn, vm): if elem_id.startswith('snap-'): snapshot_id = conn.get_all_snapshots([elem_id])[0].id else: - raise Exception("Incorrect snapshot ID: %s" % elem_id) + snapshot = conn.get_all_snapshots(filters={'tag:Name': elem_id}) + if snapshot: + snapshot_id = snapshot[0].id + else: + raise Exception("No snapshot found with name: %s" % elem_id) else: disk_size = vm.info.systems[0].getFeature("disk." + str(cont) + ".size").getValue('G')