def detach(self, force=False): state = self.attachment_state if state == 'available' or state == None or state == 'detaching': print 'already detached' return None ec2 = self.get_ec2_connection() ec2.detach_volume(self.volume_id, self.server.instance_id, self.device, force) self.server = None self.put()
def detach(self, force=False): state = self.attachment_state if state == 'available' or state is None or state == 'detaching': print('already detached') return None ec2 = self.get_ec2_connection() ec2.detach_volume(self.volume_id, self.server.instance_id, self.device, force) self.server = None self.put()
def destroy_volume(mount_point, volume): # mount volume TODO check was unmounted status = subprocess.call(['umount', mount_point]) # detach volume ec2.detach_volume(volume.id) # wait until volume's attachment state is 'None' while volume.attachment_state() is not None: time.sleep(1) volume.update() # delete volume ec2.delete_volume(volume.id)
_sh_err_exit(lambda: sh.sudo.mkfs(DEVICE, t="ext4"), 'making ext4 file system') if not os.path.exists(MOUNT): os.makedirs(MOUNT) _sh_err_exit(lambda: sh.sudo.mount(DEVICE, MOUNT), 'mounting device at ' + MOUNT) _sh_err_exit( lambda: sh.sudo.chown('-R', str(os.getuid()) + ':' + str(os.getgid()), MOUNT ), 'changing file owmership') _sh_err_exit(lambda: sh.sudo.umount(MOUNT), 'ummounting device from ' + MOUNT) os.rmdir(MOUNT) print('creating snapshot...') snap = vol.create_snapshot('JuliaBox User Disk Snapshot') _status_err_exit(snap, 'completed', 'creating snapshot') print('created snapshot ' + snap.id) print('adding tags...') ec2.create_tags([snap.id], {'Name': 'jbox_user_disk_snapshot'}) print('detaching volume...') ec2.detach_volume(vol.id, instance_id=instance_id, device=DEVICE) _status_err_exit(vol, 'available', 'detaching volume') print('deleting volume...') ec2.delete_volume(vol.id) print('done.')
print("attaching at " + DEVICE + " ...") ec2.attach_volume(vol.id, instance_id, DEVICE) if (not _wait_for_status(vol, 'in-use')) or (not _wait_for_device(DEVICE)): _err_exit("attaching at " + DEVICE) _sh_err_exit(lambda: sh.sudo.mkfs(DEVICE, t="ext4"), 'making ext4 file system') if not os.path.exists(MOUNT): os.makedirs(MOUNT) _sh_err_exit(lambda: sh.sudo.mount(DEVICE, MOUNT), 'mounting device at ' + MOUNT) _sh_err_exit(lambda: sh.sudo.chown('-R', str(os.getuid())+':'+str(os.getgid()), MOUNT), 'changing file owmership') _sh_err_exit(lambda: sh.sudo.umount(MOUNT), 'ummounting device from ' + MOUNT) os.rmdir(MOUNT) print('creating snapshot...') snap = vol.create_snapshot('JuliaBox User Disk Snapshot') _status_err_exit(snap, 'completed', 'creating snapshot') print('created snapshot ' + snap.id) print('adding tags...') ec2.create_tags([snap.id], {'Name': 'jbox_user_disk_snapshot'}) print('detaching volume...') ec2.detach_volume(vol.id, instance_id=instance_id, device=DEVICE) _status_err_exit(vol, 'available', 'detaching volume') print ('deleting volume...') ec2.delete_volume(vol.id) print('done.')