TypeScript examples

Generated from eve-iac OpenAPI/semantics. Do not edit manually.

Task-oriented examples using the current public SDK. These snippets are generated with the API reference.

Import versus from_eve

  • Import (importProject / import_project / ImportProject) clones an existing EVE source lab into a new IaC project and a managed working copy. It must not mutate source_lab.
  • from_eve is reconcileProject with direction: "from_eve". It updates files in an existing project from that project's managed lab. It is not Import.

Create a client

import { createEveIacClient } from "@eve-iac/sdk";

const client = createEveIacClient({
  url: "https://eve.example:8787",
  token: "",
  caPem,
  timeoutMs: 15000,
});

Authenticate / login

import { createEveIacClient } from "@eve-iac/sdk";

const anon = createEveIacClient({ url, token: "", caPem });
const session = await anon.login({ username: "admin", password: "secret" });
const client = createEveIacClient({ url, token: session.token ?? "", caPem });

Get session

const session = await client.getSession();

List templates

const templates = await client.listTemplates();
const provisioned = await client.listTemplates({ provisioned: "true" });

Import an existing EVE-NG lab

const imported = await client.importProject({
  lab: "/IaC/example.unl",
  manifest,
  yaml,
  files,
});
// Import clones source_lab. It is not reconcile from_eve.

Validate

const result = await client.validateProject({ lab, manifest, yaml, files });

Plan

const plan = await client.planProject({ lab, manifest, yaml, files });
// Omitted direction is to_eve. Plan never writes Local files or EVE.

Deploy

const deployed = await client.deployProject({ lab, manifest, yaml, files });

Reconcile to_eve

const applied = await client.reconcileProject({
  lab,
  manifest,
  yaml,
  files,
  direction: "to_eve",
});

Reconcile from_eve

const pulled = await client.reconcileProject({
  lab,
  manifest,
  yaml,
  files,
  direction: "from_eve",
});
// Persist Local files yourself; this SDK call does not write the Git tree.

Status

const status = await client.getProjectStatus({ lab, manifest, yaml, files });

Inspect

const observed = await client.inspectProject({ lab, manifest, yaml, files });

Start nodes

const result = await client.execProject({ lab, manifest, yaml, files, action: "start" });

Stop nodes

const result = await client.execProject({ lab, manifest, yaml, files, action: "stop" });

Wipe nodes

const result = await client.execProject({ lab, manifest, yaml, files, action: "wipe" });

List consoles

const consoles = await client.listProjectConsoles({ lab, manifest, yaml, files });

Execute a console command

const data = await client.execConsole({ lab, node: "n_1", command: "show version" });

Stream console

const attached = await client.attachConsole({ lab, node: "n_1" });
const ticket = attached.stream?.split("/").pop() ?? "";
const sock = await client.streamConsole(ticket);

Error handling

import { AgentError, isAuthError } from "@eve-iac/sdk";

try {
  await client.getSession();
} catch (err) {
  if (isAuthError(err)) {
    throw new Error((err as AgentError).code);
  }
  throw err;
}