def stack_get_by_name(context, stack_name): query = soft_delete_aware_query( context, models.Stack ).filter(sqlalchemy.or_( models.Stack.tenant == context.tenant_id, models.Stack.stack_user_project_id == context.tenant_id) ).filter_by(name=stack_name) return query.first()
def stack_get_by_name(context, stack_name): query = soft_delete_aware_query(context, models.Stack).\ filter(sqlalchemy.or_( models.Stack.tenant == context.tenant_id, models.Stack.stack_user_project_id == context.tenant_id )).\ filter_by(name=stack_name) return query.first()
def software_deployment_get_all(context, server_id=None): sd = models.SoftwareDeployment query = model_query(context, sd).filter( sqlalchemy.or_( sd.tenant == context.tenant_id, sd.stack_user_project_id == context.tenant_id)).order_by( sd.created_at) if server_id: query = query.filter_by(server_id=server_id) return query.all()
def software_deployment_get_all(context, server_id=None): sd = models.SoftwareDeployment query = ( model_query(context, sd) .filter(sqlalchemy.or_(sd.tenant == context.tenant_id, sd.stack_user_project_id == context.tenant_id)) .order_by(sd.created_at) ) if server_id: query = query.filter_by(server_id=server_id) return query.all()
def purge_deleted(age, granularity='days'): try: age = int(age) except ValueError: raise exception.Error(_("age should be an integer")) if age < 0: raise exception.Error(_("age should be a positive integer")) if granularity not in ('days', 'hours', 'minutes', 'seconds'): raise exception.Error( _("granularity should be days, hours, minutes, or seconds")) if granularity == 'days': age = age * 86400 elif granularity == 'hours': age = age * 3600 elif granularity == 'minutes': age = age * 60 time_line = timeutils.utcnow() - datetime.timedelta(seconds=age) engine = get_engine() meta = sqlalchemy.MetaData() meta.bind = engine stack = sqlalchemy.Table('stack', meta, autoload=True) stack_lock = sqlalchemy.Table('stack_lock', meta, autoload=True) resource = sqlalchemy.Table('resource', meta, autoload=True) resource_data = sqlalchemy.Table('resource_data', meta, autoload=True) event = sqlalchemy.Table('event', meta, autoload=True) raw_template = sqlalchemy.Table('raw_template', meta, autoload=True) user_creds = sqlalchemy.Table('user_creds', meta, autoload=True) service = sqlalchemy.Table('service', meta, autoload=True) syncpoint = sqlalchemy.Table('sync_point', meta, autoload=True) # find the soft-deleted stacks that are past their expiry stack_where = sqlalchemy.select([stack.c.id]).where( stack.c.deleted_at < time_line) # delete stack locks (just in case some got stuck) stack_lock_del = stack_lock.delete().where( stack_lock.c.stack_id.in_(stack_where)) engine.execute(stack_lock_del) # delete resource_data res_where = sqlalchemy.select([resource.c.id]).where( resource.c.stack_id.in_(stack_where)) res_data_del = resource_data.delete().where( resource_data.c.resource_id.in_(res_where)) engine.execute(res_data_del) # delete resources res_del = resource.delete().where(resource.c.stack_id.in_(stack_where)) engine.execute(res_del) # delete events event_del = event.delete().where(event.c.stack_id.in_(stack_where)) engine.execute(event_del) # clean up any sync_points that may have lingered sync_del = syncpoint.delete().where(syncpoint.c.stack_id.in_(stack_where)) engine.execute(sync_del) # delete the stacks stack_del = stack.delete().where(stack.c.deleted_at < time_line) engine.execute(stack_del) # delete orphaned raw templates raw_templ_sel = raw_template.c.id.in_( sqlalchemy.select([raw_template.c.id]).select_from( sqlalchemy.join( raw_template, stack, sqlalchemy.or_( stack.c.prev_raw_template_id == raw_template.c.id, stack.c.raw_template_id == raw_template.c.id), isouter=True)).where(stack.c.id == None)) # noqa raw_templ_del = raw_template.delete().where(raw_templ_sel) engine.execute(raw_templ_del) # purge any user creds that are no longer referenced stack_creds_sel = sqlalchemy.select([stack.c.user_creds_id]) user_creds_sel = sqlalchemy.not_(user_creds.c.id.in_(stack_creds_sel)) usr_creds_del = user_creds.delete().where(user_creds_sel) engine.execute(usr_creds_del) # Purge deleted services srvc_del = service.delete().where(service.c.deleted_at < time_line) engine.execute(srvc_del)
def purge_deleted(age, granularity='days'): try: age = int(age) except ValueError: raise exception.Error(_("age should be an integer")) if age < 0: raise exception.Error(_("age should be a positive integer")) if granularity not in ('days', 'hours', 'minutes', 'seconds'): raise exception.Error( _("granularity should be days, hours, minutes, or seconds")) if granularity == 'days': age = age * 86400 elif granularity == 'hours': age = age * 3600 elif granularity == 'minutes': age = age * 60 time_line = timeutils.utcnow() - datetime.timedelta(seconds=age) engine = get_engine() meta = sqlalchemy.MetaData() meta.bind = engine stack = sqlalchemy.Table('stack', meta, autoload=True) stack_lock = sqlalchemy.Table('stack_lock', meta, autoload=True) resource = sqlalchemy.Table('resource', meta, autoload=True) resource_data = sqlalchemy.Table('resource_data', meta, autoload=True) event = sqlalchemy.Table('event', meta, autoload=True) raw_template = sqlalchemy.Table('raw_template', meta, autoload=True) user_creds = sqlalchemy.Table('user_creds', meta, autoload=True) service = sqlalchemy.Table('service', meta, autoload=True) syncpoint = sqlalchemy.Table('sync_point', meta, autoload=True) # find the soft-deleted stacks that are past their expiry stack_where = sqlalchemy.select([stack.c.id ]).where(stack.c.deleted_at < time_line) # delete stack locks (just in case some got stuck) stack_lock_del = stack_lock.delete().where( stack_lock.c.stack_id.in_(stack_where)) engine.execute(stack_lock_del) # delete resource_data res_where = sqlalchemy.select([resource.c.id]).where( resource.c.stack_id.in_(stack_where)) res_data_del = resource_data.delete().where( resource_data.c.resource_id.in_(res_where)) engine.execute(res_data_del) # delete resources res_del = resource.delete().where(resource.c.stack_id.in_(stack_where)) engine.execute(res_del) # delete events event_del = event.delete().where(event.c.stack_id.in_(stack_where)) engine.execute(event_del) # clean up any sync_points that may have lingered sync_del = syncpoint.delete().where(syncpoint.c.stack_id.in_(stack_where)) engine.execute(sync_del) # delete the stacks stack_del = stack.delete().where(stack.c.deleted_at < time_line) engine.execute(stack_del) # delete orphaned raw templates raw_templ_sel = raw_template.c.id.in_( sqlalchemy.select([raw_template.c.id]).select_from( sqlalchemy.join( raw_template, stack, sqlalchemy.or_( stack.c.prev_raw_template_id == raw_template.c.id, stack.c.raw_template_id == raw_template.c.id), isouter=True)).where(stack.c.id == None)) # noqa raw_templ_del = raw_template.delete().where(raw_templ_sel) engine.execute(raw_templ_del) # purge any user creds that are no longer referenced stack_creds_sel = sqlalchemy.select([stack.c.user_creds_id]) user_creds_sel = sqlalchemy.not_(user_creds.c.id.in_(stack_creds_sel)) usr_creds_del = user_creds.delete().where(user_creds_sel) engine.execute(usr_creds_del) # Purge deleted services srvc_del = service.delete().where(service.c.deleted_at < time_line) engine.execute(srvc_del)