def resource_get_all(context): results = model_query(context, models.Resource).all() if not results: raise NotFound('no resources were found') return results
def raw_template_get_all(context): results = model_query(context, models.RawTemplate).all() if not results: raise NotFound('no raw templates were found') return results
def resource_get(context, resource_id): result = model_query(context, models.Resource).get(resource_id) if not result: raise NotFound("resource with id %s not found" % resource_id) return result
def raw_template_get(context, template_id): result = model_query(context, models.RawTemplate).get(template_id) if not result: raise NotFound("raw template with id %s not found" % template_id) return result
def resource_get_all_by_stack(context, stack_id): results = model_query(context, models.Resource).\ filter_by(stack_id=stack_id).all() if not results: raise NotFound("no resources for stack_id %s were found" % stack_id) return results
def watch_rule_update(context, watch_id, values): wr = watch_rule_get(context, watch_id) if not wr: raise NotFound('Attempt to update a watch with id: %s %s' % (watch_id, 'that does not exist')) wr.update(values) wr.save(_session(context))
def watch_data_delete(context, watch_name): ds = model_query(context, models.WatchRule).\ filter_by(name=watch_name).all() if not ds: raise NotFound('Attempt to delete watch_data with name: %s %s' % (watch_name, 'that does not exist')) session = Session.object_session(ds) for d in ds: session.delete(d) session.flush()
def watch_rule_delete(context, watch_name): wr = model_query(context, models.WatchRule).\ filter_by(name=watch_name).first() if not wr: raise NotFound('Attempt to delete a watch_rule with name: %s %s' % (watch_name, 'that does not exist')) session = Session.object_session(wr) for d in wr.watch_data: session.delete(d) session.delete(wr) session.flush()
def stack_update(context, stack_id, values): stack = stack_get(context, stack_id) if not stack: raise NotFound('Attempt to update a stack with id: %s %s' % (stack_id, 'that does not exist')) old_template_id = stack.raw_template_id stack.update(values) stack.save(_session(context)) # When the raw_template ID changes, we delete the old template # after storing the new template ID if stack.raw_template_id != old_template_id: session = Session.object_session(stack) rt = raw_template_get(context, old_template_id) session.delete(rt) session.flush()
def stack_delete(context, stack_id): s = stack_get(context, stack_id) if not s: raise NotFound('Attempt to delete a stack with id: %s %s' % (stack_id, 'that does not exist')) session = Session.object_session(s) for e in s.events: session.delete(e) for r in s.resources: session.delete(r) rt = s.raw_template uc = s.user_creds session.delete(s) session.delete(rt) session.delete(uc) session.flush()