def snapshot_volume(vol_id=None, dev_id=None, tag=None, description=None, wait_till_complete=True): EBSVol.configure_host_commands() if dev_id is not None: vol_id = EBSVol.get_volume_id_from_device(dev_id) if vol_id is None: EBSVol.log_warn("No volume to snapshot. vol_id: %r, dev_id %r", vol_id, dev_id) return vol = EBSVol.get_volume(vol_id) EBSVol.log_info("Creating snapshot for volume: %s", vol_id) snap = vol.create_snapshot(description) if wait_till_complete and (not CompEC2._wait_for_status_extended(snap, 'completed')): raise Exception("Could not create snapshot for volume " + vol_id) EBSVol.log_info("Created snapshot %s for volume %s", snap.id, vol_id) if tag is not None: EBSVol._ec2().create_tags([snap.id], {'Name': tag}) return snap.id
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 snapshot_volume(vol_id=None, dev_id=None, tag=None, description=None, wait_till_complete=True): EBSVol.configure_host_commands() if dev_id is not None: vol_id = EBSVol.get_volume_id_from_device(dev_id) if vol_id is None: EBSVol.log_warn("No volume to snapshot. vol_id: %r, dev_id %r", vol_id, dev_id) return vol = EBSVol.get_volume(vol_id) EBSVol.log_info("Creating snapshot for volume: %s", vol_id) snap = vol.create_snapshot(description) if wait_till_complete and (not CompEC2._wait_for_status_extended( snap, 'completed')): raise Exception("Could not create snapshot for volume " + vol_id) EBSVol.log_info("Created snapshot %s for volume %s", snap.id, vol_id) if tag is not None: EBSVol._ec2().create_tags([snap.id], {'Name': tag}) return snap.id