def detach_volume(vol_id, delete=False): EBSVol.configure_host_commands() # find the instance and device to which the volume is mapped instance, device = EBSVol._get_volume_attach_info(vol_id) conn = EBSVol._ec2() if instance is not None: # the volume is attached EBSVol.log_debug("Detaching %s from instance %s device %r", vol_id, instance, device) vol = EBSVol.get_volume(vol_id) t1 = time.time() conn.detach_volume(vol_id, instance, device) if not CompEC2._wait_for_status_extended(vol, 'available'): raise Exception("Volume could not be detached " + vol_id) tdiff = int(time.time() - t1) CompEC2.publish_stats("EBSDetachTime", "Count", tdiff) if delete: EBSVol.log_debug("Deleting %s", vol_id) conn.delete_volume(vol_id)
def _attach_free_volume(vol_id, dev_id): conn = EBSVol._ec2() instance_id = CompEC2.get_instance_id() device = os.path.join('/dev', dev_id) vol = EBSVol.get_volume(vol_id) EBSVol.log_info("Attaching volume %s at %s", vol_id, device) t1 = time.time() conn.attach_volume(vol_id, instance_id, device) if not CompEC2._wait_for_status(vol, 'in-use'): EBSVol.log_error("Could not attach volume %s", vol_id) raise Exception("Volume could not be attached. Volume id: " + vol_id) if not EBSVol._wait_for_device(device): EBSVol.log_error("Could not attach volume %s to device %s", vol_id, device) raise Exception("Volume could not be attached. Volume id: " + vol_id + ", device: " + device) tdiff = int(time.time() - t1) CompEC2.publish_stats("EBSAttachTime", "Count", tdiff) return device