def delete(machineguid): """ Delete a vmachine @param machineguid: guid of the machine """ machine = VMachine(machineguid) storagedriver_mountpoint, storagedriver_storage_ip = None, None try: storagedriver = [ storagedriver for storagedriver in machine.vpool.storagedrivers if storagedriver.storagerouter.pmachine_guid == machine.pmachine_guid ][0] storagedriver_mountpoint = storagedriver.mountpoint storagedriver_storage_ip = storagedriver.storage_ip except Exception as ex: logger.debug( 'No mountpoint info could be retrieved. Reason: {0}'.format( str(ex))) storagedriver_mountpoint = None disks_info = [] for vd in machine.vdisks: for storagedriver in vd.vpool.storagedrivers: if storagedriver.storagerouter.pmachine_guid == machine.pmachine_guid: disks_info.append( (storagedriver.mountpoint, vd.devicename)) if machine.pmachine: # Allow hypervisor id node, lookup strategy is hypervisor dependent try: hypervisor_id = machine.hypervisor_id if machine.pmachine.hvtype == 'KVM': hypervisor_id = machine.name # On KVM we can lookup the machine by name, not by id hv = Factory.get(machine.pmachine) hv.delete_vm(hypervisor_id, storagedriver_mountpoint, storagedriver_storage_ip, machine.devicename, disks_info, True) except Exception as exception: logger.error('Deletion of vm on hypervisor failed: {0}'.format( str(exception)), print_msg=True) for disk in machine.vdisks: logger.debug('Deleting disk {0} with guid: {1}'.format( disk.name, disk.guid)) for junction in disk.mds_services: junction.delete() disk.delete() logger.debug('Deleting vmachine {0} with guid {1}'.format( machine.name, machine.guid)) machine.delete()
def delete(machineguid): """ Delete a vmachine @param machineguid: guid of the machine """ machine = VMachine(machineguid) storagedriver_mountpoint, storagedriver_storage_ip = None, None try: storagedriver = [storagedriver for storagedriver in machine.vpool.storagedrivers if storagedriver.storagerouter.pmachine_guid == machine.pmachine_guid][0] storagedriver_mountpoint = storagedriver.mountpoint storagedriver_storage_ip = storagedriver.storage_ip except Exception as ex: VMachineController._logger.debug('No mountpoint info could be retrieved. Reason: {0}'.format(str(ex))) storagedriver_mountpoint = None disks_info = [] for vd in machine.vdisks: for storagedriver in vd.vpool.storagedrivers: if storagedriver.storagerouter.pmachine_guid == machine.pmachine_guid: disks_info.append((storagedriver.mountpoint, vd.devicename)) if machine.pmachine: # Allow hypervisor id node, lookup strategy is hypervisor dependent try: hypervisor_id = machine.hypervisor_id if machine.pmachine.hvtype == 'KVM': hypervisor_id = machine.name # On KVM we can lookup the machine by name, not by id hv = Factory.get(machine.pmachine) hv.delete_vm(hypervisor_id, storagedriver_mountpoint, storagedriver_storage_ip, machine.devicename, disks_info, True) except Exception as exception: VMachineController._logger.error('Deletion of vm on hypervisor failed: {0}'.format(str(exception)), print_msg=True) for disk in machine.vdisks: VMachineController._logger.debug('Deleting disk {0} with guid: {1}'.format(disk.name, disk.guid)) for junction in disk.mds_services: junction.delete() disk.delete() VMachineController._logger.debug('Deleting vmachine {0} with guid {1}'.format(machine.name, machine.guid)) machine.delete()
def test_happypath(self): """ Validates the happy path; Hourly snapshots are taken with a few manual consistents every now an then. The delelete policy is exectued every day """ # Setup # There are 2 machines; one with two disks, one with one disk and an additional disk vmachine_1 = VMachine() vmachine_1.name = 'vmachine_1' vmachine_1.save() vdisk_1_1 = VDisk() vdisk_1_1.name = 'vdisk_1_1' vdisk_1_1.volume_id = 'vdisk_1_1' vdisk_1_1.vmachine = vmachine_1 vdisk_1_1.save() vdisk_1_2 = VDisk() vdisk_1_2.name = 'vdisk_1_2' vdisk_1_2.volume_id = 'vdisk_1_2' vdisk_1_2.vmachine = vmachine_1 vdisk_1_2.save() vmachine_2 = VMachine() vmachine_2.name = 'vmachine_2' vmachine_2.save() vdisk_2_1 = VDisk() vdisk_2_1.name = 'vdisk_2_1' vdisk_2_1.volume_id = 'vdisk_2_1' vdisk_2_1.vmachine = vmachine_2 vdisk_2_1.save() vdisk_3 = VDisk() vdisk_3.name = 'vdisk_3' vdisk_3.volume_id = 'vdisk_3' vdisk_3.save() for disk in [vdisk_1_1, vdisk_1_2, vdisk_2_1, vdisk_3]: [ dynamic for dynamic in disk._dynamics if dynamic.name == 'snapshots' ][0].timeout = 0 # Run the testing scenario debug = True amount_of_days = 50 now = int(mktime(datetime.now().date().timetuple())) # Last night minute = 60 hour = minute * 60 day = hour * 24 for d in xrange(0, amount_of_days): base_timestamp = now + (day * d) print '' print 'Day cycle: {}: {}'.format( d, datetime.fromtimestamp(base_timestamp).strftime('%Y-%m-%d')) # At the start of the day, delete snapshot policy runs at 00:30 print '- Deleting snapshots' ScheduledTaskController.deletescrubsnapshots( timestamp=base_timestamp + (minute * 30)) # Validate snapshots print '- Validating snapshots' for vdisk in [vdisk_3 ]: # [vdisk_1_1, vdisk_1_2, vdisk_2_1, vdisk_3]: self._validate(vdisk, d, now, amount_of_days, debug) # During the day, snapshots are taken # - Create non consistent snapshot every hour, between 2:00 and 22:00 # - Create consistent snapshot at 6:30, 12:30, 18:30 print '- Creating snapshots' for h in xrange(2, 23): timestamp = base_timestamp + (hour * h) for vm in [vmachine_1, vmachine_2]: VMachineController.snapshot(machineguid=vm.guid, label='ss_i_{}:00'.format( str(h)), is_consistent=False, timestamp=timestamp) if h in [6, 12, 18]: ts = (timestamp + (minute * 30)) VMachineController.snapshot(machineguid=vm.guid, label='ss_c_{}:30'.format( str(h)), is_consistent=True, timestamp=ts) VDiskController.create_snapshot(diskguid=vdisk_3.guid, metadata={ 'label': 'ss_i_{}:00'.format( str(h)), 'is_consistent': False, 'timestamp': timestamp, 'machineguid': None }) if h in [6, 12, 18]: ts = (timestamp + (minute * 30)) VDiskController.create_snapshot(diskguid=vdisk_3.guid, metadata={ 'label': 'ss_c_{}:30'.format( str(h)), 'is_consistent': True, 'timestamp': ts, 'machineguid': None }) for vdisk in vmachine_1.vdisks: vdisk.delete() vmachine_1.delete() for vdisk in vmachine_2.vdisks: vdisk.delete() vmachine_2.delete() vdisk_3.delete()