Skip to content

Commit

Permalink
Merge pull request #740 from grycap/devel
Browse files Browse the repository at this point in the history
Fix #739
  • Loading branch information
micafer authored Dec 19, 2018
2 parents df424a2 + eb54505 commit 3d16455
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions IM/connectors/EC2.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,27 +810,33 @@ def attach_volumes(self, instance, vm):
- instance(:py:class:`boto.ec2.instance`): object to connect to EC2 instance.
- vm(:py:class:`IM.VirtualMachine`): VM information.
"""
try:
if instance.state == 'running' and "volumes" not in vm.__dict__.keys():
# Flag to set that this VM has created (or is creating) the
# volumes
vm.volumes = True
conn = instance.connection
cont = 1
while (vm.info.systems[0].getValue("disk." + str(cont) + ".size") and
vm.info.systems[0].getValue("disk." + str(cont) + ".device")):
disk_size = vm.info.systems[0].getFeature("disk." + str(cont) + ".size").getValue('G')
disk_device = vm.info.systems[0].getValue("disk." + str(cont) + ".device")
disk_type = vm.info.systems[0].getValue("disk." + str(cont) + ".type")
self.log_info("Creating a %d GB volume for the disk %d" % (int(disk_size), cont))
if instance.state == 'running' and "volumes" not in vm.__dict__.keys():
# Flag to set that this VM has created (or is creating) the
# volumes
vm.volumes = True
conn = instance.connection
cont = 1
while (vm.info.systems[0].getValue("disk." + str(cont) + ".size") and
vm.info.systems[0].getValue("disk." + str(cont) + ".device")):
disk_size = vm.info.systems[0].getFeature("disk." + str(cont) + ".size").getValue('G')
disk_device = vm.info.systems[0].getValue("disk." + str(cont) + ".device")
disk_type = vm.info.systems[0].getValue("disk." + str(cont) + ".type")
self.log_info("Creating a %d GB volume for the disk %d" % (int(disk_size), cont))
volume = None
try:
volume = self.create_volume(conn, int(disk_size), instance.placement, disk_type)
if volume:
self.log_info("Attach the volume ID " + str(volume.id))
conn.attach_volume(volume.id, instance.id, "/dev/" + disk_device)
cont += 1
except Exception:
self.log_exception(
"Error creating or attaching the volume to the instance")
except:
self.log_exception("Error creating or attaching the volume to the instance")
if volume:
self.log_info("Removing the volume " + volume.id)
try:
conn.delete_volume(volume.id)
except:
self.log_exception("Error deleting the volume")
cont += 1

def delete_volumes(self, conn, volumes, instance_id, timeout=240):
"""
Expand Down

0 comments on commit 3d16455

Please sign in to comment.