示例#1
0
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)
示例#2
0
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)
示例#3
0
 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, [])
示例#4
0
 def test_expired_list(self):
     l = list(InstanceDataDAO.expired_list(self.expires_at))
     self.assertEquals(l, [InstanceDataDAO.get(self.instance_id)])
示例#5
0
 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, [])
示例#6
0
 def test_expired_list(self):
     l = list(InstanceDataDAO.expired_list(self.expires_at))
     self.assertEquals(l, [InstanceDataDAO.get(self.instance_id)])