def rip_expired_instances(): """Run periodically to remove expired instances""" server_mgr = admin_client_set().compute.servers for instance_data in InstanceDataDAO.expired_list(datetime.utcnow()): try: server_mgr.delete(instance_data.instance_id) AuditDAO.create_record(dict( resource=url_for('instances.delete_instance', instance_id=instance_data.instance_id), method='DELETE', response_status=200, message='Automatically deleted expired instance', )) except osc_exc.NotFound: InstanceDataDAO.delete(instance_data.instance_id) except Exception: current_app.logger.exception('Failed to delete expired instance %r' % instance_data.instance_id)
def rip_expired_instances(): """Run periodically to remove expired instances""" server_mgr = admin_client_set().compute.servers for instance_data in InstanceDataDAO.expired_list(datetime.utcnow()): try: server_mgr.delete(instance_data.instance_id) AuditDAO.create_record( dict( resource=url_for('instances.delete_instance', instance_id=instance_data.instance_id), method='DELETE', response_status=200, message='Automatically deleted expired instance', )) except osc_exc.NotFound: InstanceDataDAO.delete(instance_data.instance_id) except Exception: current_app.logger.exception( 'Failed to delete expired instance %r' % instance_data.instance_id)
def test_expired_list_empty(self): one_day_before = self.expires_at - timedelta(days=1) l = list(InstanceDataDAO.expired_list(one_day_before)) self.assertEquals(l, [])
def test_expired_list(self): l = list(InstanceDataDAO.expired_list(self.expires_at)) self.assertEquals(l, [InstanceDataDAO.get(self.instance_id)])