static bool cmdSecretDefine(vshControl *ctl, const vshCmd *cmd) { const char *from = NULL; char *buffer; virSecretPtr res; char uuid[VIR_UUID_STRING_BUFLEN]; bool ret = false; virshControlPtr priv = ctl->privData; if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) return false; if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) return false; if (!(res = virSecretDefineXML(priv->conn, buffer, 0))) { vshError(ctl, _("Failed to set attributes from %s"), from); goto cleanup; } if (virSecretGetUUIDString(res, &(uuid[0])) < 0) { vshError(ctl, "%s", _("Failed to get UUID of created secret")); goto cleanup; } vshPrintExtra(ctl, _("Secret %s created\n"), uuid); ret = true; cleanup: VIR_FREE(buffer); if (res) virSecretFree(res); return ret; }
ERL_NIF_TERM vert_virSecretDefineXML(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) { VERT_RESOURCE *vp = NULL; ErlNifBinary xml = {0}; u_int32_t flags = 0; VERT_RESOURCE *sp = NULL; VERT_GET_RESOURCE(0, vp, VERT_RES_CONNECT); VERT_GET_IOLIST(1, xml); VERT_GET_UINT(2, flags); VERT_BIN_APPEND_NULL(xml); VERT_RES_ALLOC(sp, VERT_RES_SECRET, vp->conn); sp->res = virSecretDefineXML(vp->res, (char *)xml.data, flags); if (sp->res == NULL) { enif_release_resource(sp); return verterr(env); } return vert_make_resource(env, sp, atom_secret); }