static FnCall *DefaultServiceBundleCall(const Promise *pp, ServicePolicy service_policy) { Rlist *args = NULL; switch (service_policy) { case SERVICE_POLICY_START: RlistAppend(&args, pp->promiser, RVAL_TYPE_SCALAR); RlistAppend(&args, "start", RVAL_TYPE_SCALAR); break; case SERVICE_POLICY_RESTART: RlistAppend(&args, pp->promiser, RVAL_TYPE_SCALAR); RlistAppend(&args, "restart", RVAL_TYPE_SCALAR); break; case SERVICE_POLICY_RELOAD: RlistAppend(&args, pp->promiser, RVAL_TYPE_SCALAR); RlistAppend(&args, "restart", RVAL_TYPE_SCALAR); break; case SERVICE_POLICY_STOP: case SERVICE_POLICY_DISABLE: default: RlistAppend(&args, pp->promiser, RVAL_TYPE_SCALAR); RlistAppend(&args, "stop", RVAL_TYPE_SCALAR); break; } FnCall *call = FnCallNew("standard_services", args); return call; }
FnCall *ExpandFnCall(EvalContext *ctx, const char *ns, const char *scope, const FnCall *f) { FnCall *result = NULL; if (IsCf3VarString(f->name)) { // e.g. usebundle => $(m)(arg0, arg1); Buffer *buf = BufferNewWithCapacity(CF_MAXVARSIZE); ExpandScalar(ctx, ns, scope, f->name, buf); result = FnCallNew(BufferData(buf), ExpandList(ctx, ns, scope, f->args, false)); BufferDestroy(buf); } else { result = FnCallNew(f->name, ExpandList(ctx, ns, scope, f->args, false)); } return result; }
static FnCall *DefaultServiceBundleCall(const Promise *pp, const char *service_policy) { Rlist *args = NULL; FnCall *call = NULL; RlistAppend(&args, pp->promiser, RVAL_TYPE_SCALAR); RlistAppend(&args, service_policy, RVAL_TYPE_SCALAR); Rval name = DefaultBundleConstraint(pp, "service"); if (PolicyGetBundle(PolicyFromPromise(pp), PromiseGetBundle(pp)->ns, "agent", (char *)name.item)) { Log(LOG_LEVEL_VERBOSE, "Found service special bundle %s in ns %s\n", (char *)name.item, PromiseGetBundle(pp)->ns); call = FnCallNew(name.item, args); } else { call = FnCallNew("standard_services", args); } return call; }
FnCall *FnCallCopyRewriter(const FnCall *f, JsonElement *map) { return FnCallNew(f->name, RlistCopyRewriter(f->args, map)); }
static PromiseResult DoVerifyServices(EvalContext *ctx, Attributes a, Promise *pp) { FnCall *default_bundle = NULL; Rlist *args = NULL; // Need to set up the default service pack to eliminate syntax if (ConstraintGetRvalValue(ctx, "service_bundle", pp, RVAL_TYPE_SCALAR) == NULL) { switch (a.service.service_policy) { case SERVICE_POLICY_START: RlistAppendScalar(&args, pp->promiser); RlistAppendScalar(&args, "start"); break; case SERVICE_POLICY_RESTART: RlistAppendScalar(&args, pp->promiser); RlistAppendScalar(&args, "restart"); break; case SERVICE_POLICY_RELOAD: RlistAppendScalar(&args, pp->promiser); RlistAppendScalar(&args, "reload"); break; case SERVICE_POLICY_STOP: case SERVICE_POLICY_DISABLE: default: RlistAppendScalar(&args, pp->promiser); RlistAppendScalar(&args, "stop"); break; } default_bundle = FnCallNew("standard_services", args); PromiseAppendConstraint(pp, "service_bundle", (Rval) {default_bundle, RVAL_TYPE_FNCALL }, "any", false); a.havebundle = true; } // Set $(this.service_policy) for flexible bundle adaptation switch (a.service.service_policy) { case SERVICE_POLICY_START: EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_THIS, "service_policy", "start", DATA_TYPE_STRING, "goal=state,source=promise"); break; case SERVICE_POLICY_RESTART: EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_THIS, "service_policy", "restart", DATA_TYPE_STRING, "goal=state,source=promise"); break; case SERVICE_POLICY_RELOAD: EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_THIS, "service_policy", "reload", DATA_TYPE_STRING, "goal=state,source=promise"); break; case SERVICE_POLICY_STOP: case SERVICE_POLICY_DISABLE: default: EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_THIS, "service_policy", "stop", DATA_TYPE_STRING, "goal=state,source=promise"); break; } const Bundle *bp = PolicyGetBundle(PolicyFromPromise(pp), NULL, "agent", default_bundle->name); if (!bp) { bp = PolicyGetBundle(PolicyFromPromise(pp), NULL, "common", default_bundle->name); } PromiseResult result = PROMISE_RESULT_NOOP; if (default_bundle && bp == NULL) { cfPS(ctx, LOG_LEVEL_INFO, PROMISE_RESULT_FAIL, pp, a, "Service '%s' could not be invoked successfully", pp->promiser); result = PromiseResultUpdate(result, PROMISE_RESULT_FAIL); } if (!DONTDO) { result = PromiseResultUpdate(result, VerifyMethod(ctx, "service_bundle", a, pp)); // Send list of classes to set privately? } return result; }
FnCall *FnCallCopy(const FnCall *f) { return FnCallNew(f->name, RlistCopy(f->args)); }
FnCall *FnCallCopy(const FnCall *f) { CfDebug("CopyFnCall()\n"); return FnCallNew(f->name, RlistCopy(f->args)); }
FnCall *ExpandFnCall(const char *contextid, FnCall *f, int expandnaked) { CfDebug("ExpandFnCall()\n"); return FnCallNew(f->name, ExpandList(contextid, f->args, false)); }
FnCall *ExpandFnCall(EvalContext *ctx, const char *contextid, FnCall *f) { CfDebug("ExpandFnCall()\n"); return FnCallNew(f->name, ExpandList(ctx, contextid, f->args, false)); }
static void DoVerifyServices(EvalContext *ctx, Attributes a, Promise *pp, const ReportContext *report_context) { FnCall *default_bundle = NULL; Rlist *args = NULL; // Need to set up the default service pack to eliminate syntax if (ConstraintGetRvalValue(ctx, "service_bundle", pp, RVAL_TYPE_SCALAR) == NULL) { switch (a.service.service_policy) { case SERVICE_POLICY_START: RlistAppendScalar(&args, pp->promiser); RlistAppendScalar(&args, "start"); break; case SERVICE_POLICY_RESTART: RlistAppendScalar(&args, pp->promiser); RlistAppendScalar(&args, "restart"); break; case SERVICE_POLICY_RELOAD: RlistAppendScalar(&args, pp->promiser); RlistAppendScalar(&args, "restart"); break; case SERVICE_POLICY_STOP: case SERVICE_POLICY_DISABLE: default: RlistAppendScalar(&args, pp->promiser); RlistAppendScalar(&args, "stop"); break; } default_bundle = FnCallNew("default:standard_services", args); PromiseAppendConstraint(pp, "service_bundle", (Rval) {default_bundle, RVAL_TYPE_FNCALL }, "any", false); a.havebundle = true; } // Set $(this.service_policy) for flexible bundle adaptation switch (a.service.service_policy) { case SERVICE_POLICY_START: ScopeNewScalar("this", "service_policy", "start", DATA_TYPE_STRING); break; case SERVICE_POLICY_RESTART: ScopeNewScalar("this", "service_policy", "restart", DATA_TYPE_STRING); break; case SERVICE_POLICY_RELOAD: ScopeNewScalar("this", "service_policy", "reload", DATA_TYPE_STRING); break; case SERVICE_POLICY_STOP: case SERVICE_POLICY_DISABLE: default: ScopeNewScalar("this", "service_policy", "stop", DATA_TYPE_STRING); break; } const Bundle *bp = PolicyGetBundle(PolicyFromPromise(pp), NULL, "agent", default_bundle->name); if (!bp) { bp = PolicyGetBundle(PolicyFromPromise(pp), NULL, "common", default_bundle->name); } if (default_bundle && bp == NULL) { cfPS(ctx, OUTPUT_LEVEL_INFORM, CF_FAIL, "", pp, a, " !! Service %s could not be invoked successfully\n", pp->promiser); } if (!DONTDO) { VerifyMethod(ctx, "service_bundle", a, pp, report_context); // Send list of classes to set privately? } }
FnCall *ExpandFnCall(EvalContext *ctx, const char *ns, const char *scope, FnCall *f) { return FnCallNew(f->name, ExpandList(ctx, ns, scope, f->args, false)); }