node-lxc 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +328 -0
  3. package/bin/x86_64-linux-gnu/node-lxc.node +0 -0
  4. package/examples/attach/index.ts +29 -0
  5. package/examples/attach-streams/index.ts +34 -0
  6. package/examples/checkpoint/index.ts +34 -0
  7. package/examples/clone/index.ts +34 -0
  8. package/examples/concurrent_create/index.ts +30 -0
  9. package/examples/concurrent_destroy/index.ts +23 -0
  10. package/examples/concurrent_shutdown/index.ts +28 -0
  11. package/examples/concurrent_start/index.ts +28 -0
  12. package/examples/concurrent_stop/index.ts +28 -0
  13. package/examples/config/index.ts +18 -0
  14. package/examples/console/index.ts +17 -0
  15. package/examples/console_async/index.ts +101 -0
  16. package/examples/create/index.ts +12 -0
  17. package/examples/create_snapshot/index.ts +10 -0
  18. package/examples/destroy/index.ts +10 -0
  19. package/examples/destroy_snapshots/index.ts +10 -0
  20. package/examples/device_add_remove/index.ts +11 -0
  21. package/examples/execute/index.ts +10 -0
  22. package/examples/freeze/index.ts +11 -0
  23. package/examples/images/index.ts +10 -0
  24. package/examples/interfaces/index.ts +10 -0
  25. package/examples/ipaddress/index.ts +12 -0
  26. package/examples/limit/index.ts +15 -0
  27. package/examples/list/index.ts +12 -0
  28. package/examples/list_keys/index.ts +10 -0
  29. package/examples/list_snapshots/index.ts +9 -0
  30. package/examples/reboot/index.ts +11 -0
  31. package/examples/rename/index.ts +11 -0
  32. package/examples/restore_snapshot/index.ts +11 -0
  33. package/examples/shutdown/index.ts +19 -0
  34. package/examples/start/index.ts +11 -0
  35. package/examples/stats/index.ts +48 -0
  36. package/examples/stop/index.ts +11 -0
  37. package/examples/unfreeze/index.ts +11 -0
  38. package/lib/binding.d.ts +6 -0
  39. package/lib/binding.js +32 -0
  40. package/lib/binding.js.map +1 -0
  41. package/lib/index.d.ts +612 -0
  42. package/lib/index.js +73 -0
  43. package/lib/index.js.map +1 -0
  44. package/lib/types/Image.d.ts +22 -0
  45. package/lib/types/Image.js +3 -0
  46. package/lib/types/Image.js.map +1 -0
  47. package/lib/types/LXC_ATTACH.d.ts +67 -0
  48. package/lib/types/LXC_ATTACH.js +72 -0
  49. package/lib/types/LXC_ATTACH.js.map +1 -0
  50. package/lib/types/LXC_CLONE.d.ts +34 -0
  51. package/lib/types/LXC_CLONE.js +39 -0
  52. package/lib/types/LXC_CLONE.js.map +1 -0
  53. package/lib/types/LXC_CREATE.d.ts +8 -0
  54. package/lib/types/LXC_CREATE.js +13 -0
  55. package/lib/types/LXC_CREATE.js.map +1 -0
  56. package/lib/types/LXC_LOGLEVEL.d.ts +15 -0
  57. package/lib/types/LXC_LOGLEVEL.js +20 -0
  58. package/lib/types/LXC_LOGLEVEL.js.map +1 -0
  59. package/lib/types/LXC_MIGRATE.d.ts +10 -0
  60. package/lib/types/LXC_MIGRATE.js +15 -0
  61. package/lib/types/LXC_MIGRATE.js.map +1 -0
  62. package/lib/types/LXC_MOUNT.d.ts +42 -0
  63. package/lib/types/LXC_MOUNT.js +45 -0
  64. package/lib/types/LXC_MOUNT.js.map +1 -0
  65. package/lib/types/Personality.d.ts +14 -0
  66. package/lib/types/Personality.js +19 -0
  67. package/lib/types/Personality.js.map +1 -0
  68. package/lib/types/bdev_specs.d.ts +48 -0
  69. package/lib/types/bdev_specs.js +3 -0
  70. package/lib/types/bdev_specs.js.map +1 -0
  71. package/lib/types/custom/ConsoleSession.d.ts +23 -0
  72. package/lib/types/custom/ConsoleSession.js +3 -0
  73. package/lib/types/custom/ConsoleSession.js.map +1 -0
  74. package/lib/types/custom/index.d.ts +1 -0
  75. package/lib/types/custom/index.js +18 -0
  76. package/lib/types/custom/index.js.map +1 -0
  77. package/lib/types/index.d.ts +20 -0
  78. package/lib/types/index.js +37 -0
  79. package/lib/types/index.js.map +1 -0
  80. package/lib/types/lxc_attach_env_policy.d.ts +8 -0
  81. package/lib/types/lxc_attach_env_policy.js +13 -0
  82. package/lib/types/lxc_attach_env_policy.js.map +1 -0
  83. package/lib/types/lxc_attach_options.d.ts +99 -0
  84. package/lib/types/lxc_attach_options.js +30 -0
  85. package/lib/types/lxc_attach_options.js.map +1 -0
  86. package/lib/types/lxc_clone_options.d.ts +52 -0
  87. package/lib/types/lxc_clone_options.js +7 -0
  88. package/lib/types/lxc_clone_options.js.map +1 -0
  89. package/lib/types/lxc_console_log.d.ts +10 -0
  90. package/lib/types/lxc_console_log.js +7 -0
  91. package/lib/types/lxc_console_log.js.map +1 -0
  92. package/lib/types/lxc_snapshot.d.ts +10 -0
  93. package/lib/types/lxc_snapshot.js +7 -0
  94. package/lib/types/lxc_snapshot.js.map +1 -0
  95. package/lib/types/migrate_opts.d.ts +17 -0
  96. package/lib/types/migrate_opts.js +7 -0
  97. package/lib/types/migrate_opts.js.map +1 -0
  98. package/package.json +88 -0
package/lib/index.d.ts ADDED
@@ -0,0 +1,612 @@
1
+ /**
2
+ * @author A.P.A. Slaa (a.p.a.slaa@projectsource.nl) ProjectSource V.O.F.
3
+ * @date 03-07-2024
4
+ */
5
+ import { bdev_specs, lxc_attach_options, lxc_clone_options, lxc_console_log, LXC_CREATE, LXC_MIGRATE, LXC_MOUNT, lxc_mount, lxc_snapshot, migrate_opts, ConsoleSession } from "./types";
6
+ export * from "./types";
7
+ export type ContainerState = "STOPPED" | "STARTING" | "RUNNING" | "STOPPING" | "ABORTING" | "FREEZING" | "FROZEN" | "THAWED";
8
+ export type ContainerStats = {
9
+ /** Current memory usage in bytes (cgroup v1: memory.usage_in_bytes) */
10
+ "memory.usage_in_bytes": string | null;
11
+ /** Memory limit in bytes (cgroup v1: memory.limit_in_bytes) */
12
+ "memory.limit_in_bytes": string | null;
13
+ /** Memory+swap usage in bytes (cgroup v1: memory.memsw.usage_in_bytes) */
14
+ "memory.memsw.usage_in_bytes": string | null;
15
+ /** Total CPU time consumed in nanoseconds (cgroup v1: cpuacct.usage) */
16
+ "cpuacct.usage": string | null;
17
+ /** CPU scheduler accounting stats (cgroup v1: cpu.stat) */
18
+ "cpu.stat": string | null;
19
+ /** Block I/O service bytes (cgroup v1: blkio.throttle.io_service_bytes) */
20
+ "blkio.throttle.io_service_bytes": string | null;
21
+ };
22
+ export type Container = {
23
+ /**
24
+ * Last error number and human-readable description of the last error that occurred.
25
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#aad1307b63ded0ac82e7a0adc06969dd8 error_num}
26
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a2fbfcf120528886aec7178e4d3631cba error_string}
27
+ */
28
+ get error(): {
29
+ num: number;
30
+ string: string | null;
31
+ };
32
+ /**
33
+ * Name of the container.
34
+ * Getting this property calls `lxc_container.name` directly.
35
+ * Setting this property calls `rename` — the container must be stopped.
36
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a369207c40b4946a04026861bfef3d86c rename}
37
+ */
38
+ get name(): string;
39
+ set name(newName: string);
40
+ /**
41
+ * Determine whether the container configuration file exists (`/var/lib/lxc/$name/config`).
42
+ * Does not indicate whether the container is running.
43
+ * @returns `true` if the container is defined (config exists), `false` otherwise.
44
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a84fd83757b47401b95ff01efae76d896 is_defined}
45
+ */
46
+ get defined(): boolean;
47
+ /**
48
+ * Determine the current state of the container.
49
+ * @returns One of the {@link ContainerState} string values.
50
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#aa071116fd2f39c4cbe62d171566d14b9 state}
51
+ */
52
+ get state(): ContainerState;
53
+ /**
54
+ * Determine whether the container is currently running.
55
+ * @returns `true` if running, `false` otherwise.
56
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#ab810a7cd940111dbb480eb0440f71abe is_running}
57
+ */
58
+ get running(): boolean;
59
+ /**
60
+ * Process ID of the container's init process as seen from outside the container.
61
+ * Returns -1 if the container is not running.
62
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a8ce63dc530f57a3a198ed2d0f0c229a9 init_pid}
63
+ */
64
+ get initPID(): number;
65
+ /**
66
+ * Current configuration file name (full path).
67
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#ab8e79d0775d59cb0007c7f5e56895a59 config_file_name}
68
+ */
69
+ get configFileName(): string;
70
+ /**
71
+ * Whether the container wishes to be daemonized (detached from the controlling terminal) on start.
72
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#aad6d903f5f22937f0662814ee4c1ac05 daemonize}
73
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a9872b6f471de0ccbb5151e692bdbfb3b want_daemonize}
74
+ */
75
+ get daemonize(): boolean;
76
+ set daemonize(value: boolean);
77
+ /**
78
+ * Full path to the container's configuration directory.
79
+ * Each container can have a custom configuration path; by default it is the `lxc.lxcpath`
80
+ * global config value (typically `/var/lib/lxc`).
81
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a3cdd629f0b11a313938178a46b18a263 get_config_path}
82
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#ad140523960327ab5537629ee8dc62dd3 set_config_path}
83
+ */
84
+ get configPath(): string;
85
+ set configPath(path: string);
86
+ new (name: string, configPath?: string, alt_file?: string): Container;
87
+ /**
88
+ * Freeze a running container (pause all processes via cgroup freezer).
89
+ * The container must be in the RUNNING state; it will transition to FROZEN.
90
+ * @returns {Promise<void>} Resolves when frozen; rejects on failure.
91
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#ab83d343ed927520ee693c3c0fc3514ca freeze}
92
+ */
93
+ freeze(): Promise<void>;
94
+ /**
95
+ * Thaw (unfreeze) a frozen container, resuming all paused processes.
96
+ * The container must be in the FROZEN state; it will transition back to RUNNING.
97
+ * @returns {Promise<void>} Resolves when thawed; rejects on failure.
98
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#ac1710a6788be63a2429918ec3724641e unfreeze}
99
+ */
100
+ unfreeze(): Promise<void>;
101
+ /**
102
+ * Load the specified configuration file for the container, replacing any previously loaded config.
103
+ * @param alt_file {string} Full path to the alternate configuration file to load.
104
+ * @returns {Promise<void>} Resolves on success; rejects if the file cannot be loaded.
105
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a1568b8bee1175956b9917dcf0458248a load_config}
106
+ */
107
+ loadConfig(alt_file: string): Promise<void>;
108
+ /**
109
+ * Start the container.
110
+ * If the container is already running, this is a no-op.
111
+ * @param useinit {number} Pass `1` to use `lxcinit` rather than `/sbin/init`. Default `0`.
112
+ * @param argv {string[]} Optional arguments to pass to the init process.
113
+ * @returns {Promise<void>} Resolves when the container has started; rejects on error.
114
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a599d630c220ee5ef2a9c6b79c7eb3b23 start}
115
+ */
116
+ start(useinit?: number, argv?: string[]): Promise<void>;
117
+ /**
118
+ * Stop the container by sending it a `SIGKILL`.
119
+ * If the container is already stopped, this is a no-op.
120
+ * @returns {Promise<void>} Resolves when stopped; rejects on error.
121
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a661d604dd5d29b5d6dd5d141d63c8539 stop}
122
+ */
123
+ stop(): Promise<void>;
124
+ /**
125
+ * Set whether all file descriptors should be closed before the container's init process starts.
126
+ * @param state {boolean} `true` to close all fds on startup.
127
+ * @returns {boolean} `true` on success.
128
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a2c979929461fcb4ebe96baed2b0acb8f want_close_all_fds}
129
+ */
130
+ wantCloseAllFds(state: boolean): Promise<void>;
131
+ /**
132
+ * Block until the container reaches the specified state or the timeout expires.
133
+ * @param state {ContainerState} The target state to wait for.
134
+ * @param timeout {number} Seconds to wait; `-1` waits forever, `0` returns immediately. Default `-1`.
135
+ * @returns {Promise<void>} Resolves when the state is reached; rejects on timeout or error.
136
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a103d932d1b2ba4e8b07100ef4dbd053f wait}
137
+ */
138
+ wait(state: ContainerState, timeout?: number): Promise<void>;
139
+ /**
140
+ * Set a single key/value pair in the container's in-memory configuration.
141
+ * Call `save()` afterwards to persist the change to disk.
142
+ * @param key {string} Configuration key (e.g. `"lxc.log.file"`).
143
+ * @param value {string} Value to set.
144
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a340914109541781444138be66b4e88eb set_config_item}
145
+ */
146
+ setConfigItem(key: string, value: string): void;
147
+ /**
148
+ * Delete the container and optionally its snapshots.
149
+ * The container must be stopped before calling this unless `force` is set.
150
+ * Internally calls `destroy_with_snapshots` when `include_snapshots` is `true`.
151
+ * @param options.include_snapshots {boolean} Destroy all snapshots too. Default `false`.
152
+ * @param options.force {boolean} Stop the container first if it is running. Default `false`.
153
+ * @returns {Promise<void>} Resolves on success; rejects if destruction fails.
154
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a284790c42e39e597eae61ae2d2995173 destroy}
155
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#af25cbca9e062b5fc9279753361391b85 destroy_with_snapshots}
156
+ */
157
+ destroy(options?: {
158
+ include_snapshots?: boolean;
159
+ force?: boolean;
160
+ }): Promise<void>;
161
+ /**
162
+ * Persist the container's in-memory configuration to a file.
163
+ * @param alt_file {string} Full path to the file to write. Pass the current `configFileName`
164
+ * to overwrite the existing config.
165
+ * @returns {Promise<void>} Resolves on success; rejects if the file cannot be written.
166
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#abea85657b8f816e7d2d5238c0d731a67 save_config}
167
+ */
168
+ save(alt_file: string): Promise<void>;
169
+ /**
170
+ * Create a new container using a template or a pre-built image.
171
+ * This runs the template script (e.g. `download`, `ubuntu`) to populate the rootfs.
172
+ * @param options.template {string} Template name to use (e.g. `"download"`, `"ubuntu"`). Default `"none"`.
173
+ * @param options.argv {string[]} Arguments to pass to the template script (e.g. distro/release/arch).
174
+ * @param options.bdevtype {string} Backing store type (`"dir"`, `"lvm"`, `"zfs"`, `"rbd"`, etc.). Default `"dir"`.
175
+ * @param options.bdev_specs {Partial<bdev_specs>} Backing store parameters (LVM VG, ZFS root, etc.).
176
+ * @param options.flags {LXC_CREATE} Creation flags (e.g. `LXC_CREATE.QUIET`).
177
+ * @returns {Promise<void>} Resolves when the container has been created; rejects on error.
178
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#ad2a402be12791e43dd016bba24e53b40 create}
179
+ */
180
+ create(options: {
181
+ template?: string;
182
+ argv?: string[];
183
+ bdevtype?: string;
184
+ bdev_specs?: Partial<bdev_specs>;
185
+ flags?: LXC_CREATE;
186
+ }): Promise<void>;
187
+ /**
188
+ * Request the container to reboot by sending it `SIGINT` to its init process.
189
+ * Waits up to `timeout` seconds for the reboot to complete.
190
+ * Internally uses `reboot2` which supports a timeout parameter.
191
+ * @param timeout {number} Seconds to wait; `-1` waits forever, `0` does not wait. Default `-1`.
192
+ * @returns {Promise<boolean>} Resolves with `true` if the reboot completed within the timeout.
193
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a5c6f030b9e8797cf9a4586b1fab6c3eb reboot2}
194
+ */
195
+ reboot(timeout?: number): Promise<boolean>;
196
+ /**
197
+ * Request the container to shut down gracefully by sending `SIGPWR` to its init process.
198
+ * Waits up to `timeout` seconds for the shutdown to complete.
199
+ * @param timeout {number} Seconds to wait; `-1` waits forever, `0` does not wait. Default `-1`.
200
+ * @returns {Promise<boolean>} Resolves with `true` if shutdown completed within the timeout.
201
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a9cfba9429c159612a8d6b768f6e27ade shutdown}
202
+ */
203
+ shutdown(timeout?: number): Promise<boolean>;
204
+ /**
205
+ * Completely clear the container's in-memory configuration.
206
+ * Does not affect the configuration file on disk. Call `loadConfig` to reload from disk.
207
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a2d40919280dbedd9d29417d5ca117e86 clear_config}
208
+ */
209
+ clearConfig(): void;
210
+ /**
211
+ * Clear a single key from the container's in-memory configuration.
212
+ * @param key {string} Name of the configuration key to remove (e.g. `"lxc.net.0.type"`).
213
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a4521fb10eee10cf6ca9b33d3ef1f996a clear_config_item}
214
+ */
215
+ clearConfigItem(key: string): void;
216
+ /**
217
+ * Retrieve the value of a configuration key from the container's in-memory config.
218
+ * Returns `null` if the key does not exist or has no value.
219
+ * @param key {string} Configuration key to retrieve (e.g. `"lxc.net.0.type"`).
220
+ * @returns {string | null} The value string, or `null` if absent.
221
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a7411db2a0e7a8471c41a4a58d8e83b33 get_config_item}
222
+ */
223
+ getConfigItem(key: string): string | null;
224
+ /**
225
+ * Retrieve the value of a configuration key from a **running** container's live state.
226
+ * Unlike `getConfigItem`, this reads values that may differ from the on-disk config
227
+ * (e.g. effective network settings, runtime cgroup values).
228
+ * Returns `null` if the key does not exist or the container is not running.
229
+ * @param key {string} Configuration key to retrieve.
230
+ * @returns {string | null} The live value string, or `null` if absent.
231
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#aeb0f5f1589ba5dc14d5d1e1c0cb87f96 get_running_config_item}
232
+ */
233
+ getRunningConfigItem(key: string): string | null;
234
+ /**
235
+ * Retrieve all configuration keys that match the given prefix.
236
+ * Use this to enumerate available keys, then call `getConfigItem` on each.
237
+ * For bulk reads, prefer `getConfigItems` which fetches keys and values in one call.
238
+ * @param prefix {string} Key prefix to filter by (e.g. `"lxc.net"`). Pass `undefined` for all keys.
239
+ * @returns {string[]} Array of matching key strings.
240
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a885bbd0d02c3771bcee7b02a2c398be9 get_keys}
241
+ */
242
+ getKeys(prefix?: string): string[];
243
+ /**
244
+ * Retrieve all network interfaces currently visible inside the container.
245
+ * The container must be running.
246
+ * @returns {Promise<string[]>} Array of interface name strings (e.g. `["lo", "eth0"]`).
247
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a50d09300fa69182156b58eb9ef288dbd get_interfaces}
248
+ */
249
+ getInterfaces(): Promise<string[]>;
250
+ /**
251
+ * Retrieve IPv4 addresses assigned to a container interface.
252
+ * The container must be running.
253
+ * @param iface {string} Network interface name (e.g. `"eth0"`).
254
+ * @param family {"inet"} Address family — use `"inet"` for IPv4.
255
+ * @returns {Promise<string[]>} Array of IPv4 address strings in dotted-decimal notation.
256
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a70b47b5719463e4c61ed097b285d9371 get_ips}
257
+ */
258
+ getIPs(iface: string, family: "inet"): Promise<string[]>;
259
+ /**
260
+ * Retrieve IPv6 addresses assigned to a container interface.
261
+ * The container must be running.
262
+ * @param iface {string} Network interface name (e.g. `"eth0"`).
263
+ * @param family {"inet6"} Address family — use `"inet6"` for IPv6.
264
+ * @param scope {number} IPv6 scope ID to filter by (e.g. `0` for global).
265
+ * @returns {Promise<string[]>} Array of IPv6 address strings.
266
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a70b47b5719463e4c61ed097b285d9371 get_ips}
267
+ */
268
+ getIPs(iface: string, family: "inet6", scope: number): Promise<string[]>;
269
+ /**
270
+ * Retrieve the value of a cgroup subsystem entry for the container.
271
+ * Returns `undefined` if the subsystem does not exist or is not available.
272
+ * @param subsys {string} cgroup subsystem path (e.g. `"memory.usage_in_bytes"`, `"cpu.stat"`).
273
+ * @returns {string | undefined} The cgroup value string, or `undefined`.
274
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a6202bf97cd77e208eed1845d5a911cbc get_cgroup_item}
275
+ */
276
+ getCGroupItem(subsys: string): string | undefined;
277
+ /**
278
+ * Set a cgroup subsystem value for the container.
279
+ * The container must be running for most cgroup writes to take effect.
280
+ * @param subsys {string} cgroup subsystem path (e.g. `"memory.limit_in_bytes"`).
281
+ * @param value {string} Value to write (e.g. `"536870912"` for 512 MiB).
282
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#aff7753133cff04ed1e48fdceaf490a28 set_cgroup_item}
283
+ */
284
+ setCGroupItem(subsys: string, value: string): void;
285
+ /**
286
+ * Clone (copy) a stopped container into a new container.
287
+ * The source container must be stopped.
288
+ * @param options {lxc_clone_options} Clone parameters including new name, backing store, and flags.
289
+ * @returns {Promise<Container>} Resolves with a Container instance for the new clone.
290
+ * @note If `bdevtype` is not specified and `LXC_CLONE_SNAPSHOT` is set in flags, the native
291
+ * backing store snapshot mechanism is used if available, otherwise overlayfs is used.
292
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#ada03abc45ce41a3229837858a25de841 clone}
293
+ */
294
+ clone(options: lxc_clone_options): Promise<Container>;
295
+ /**
296
+ * Allocate a console TTY file descriptor pair for the container without attaching to it.
297
+ * The returned `ttyfd` keeps the TTY allocated; close both descriptors when done.
298
+ * @param ttynum {number} TTY number to allocate, or `-1` for the first available. Default `-1`.
299
+ * @returns {Promise<[number, number]>} Tuple of `[ttyfd, ptxfd]` — the TTY and pseudoterminal master fds.
300
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a64b4ce75b807b21e42d4ccd024652973 console_getfd}
301
+ */
302
+ consoleGetFds(ttynum?: number): Promise<[number, number]>;
303
+ /**
304
+ * Allocate a console TTY and return an async event-emitting session object.
305
+ * The returned {@link ConsoleSession} emits `data` events with `Buffer` chunks and a `close` event
306
+ * when the session ends. Supports `write(data)`, `resize(cols, rows)`, and `close()`.
307
+ * This is a custom enhancement not directly in the LXC C API.
308
+ * @param ttynum {number} TTY number to allocate, or `-1` for the first available. Default `-1`.
309
+ * @returns {Promise<ConsoleSession>} Active console session.
310
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a64b4ce75b807b21e42d4ccd024652973 console_getfd}
311
+ */
312
+ consoleAsync(ttynum?: number): Promise<ConsoleSession>;
313
+ /**
314
+ * Allocate and run a console TTY, blocking until the user exits.
315
+ * This connects the calling process's stdio to the container console.
316
+ * Use `consoleAsync` instead for non-blocking programmatic access.
317
+ * @param ttynum {number} TTY number to allocate (`-1` = first available, `0` = console).
318
+ * @param stdio {[number, number, number]} File descriptors `[stdinfd, stdoutfd, stderrfd]` to use.
319
+ * @param escape {number} Escape character as integer (`1` = Ctrl+a, `2` = Ctrl+b, …).
320
+ * @returns {Promise<void>} Resolves when the user exits the console.
321
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a5ef781838651c315c8cdc6730586a554 console}
322
+ */
323
+ console(ttynum: number, stdio: [number, number, number], escape: number): Promise<void>;
324
+ /**
325
+ * Open a shell inside the container and wait for it to exit.
326
+ * Uses `lxc_attach_run_shell` internally, which spawns `/bin/sh` (or the container's default shell).
327
+ * The shell inherits the attach options (namespaces, environment, uid/gid, etc.).
328
+ * @param options {Partial<lxc_attach_options>} Attach options. Uses LXC defaults if omitted.
329
+ * @returns {Promise<number>} Exit code of the shell process.
330
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a1fd6ce7695e6a967efbb9dcc36952168 attach}
331
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__attach__options__t.html lxc_attach_options_t}
332
+ */
333
+ attach(options?: Partial<lxc_attach_options>): Promise<number>;
334
+ /**
335
+ * Create a container snapshot at the current state.
336
+ * Snapshots are stored as `snap<N>` under the container's snapshot directory
337
+ * (typically `/var/lib/lxc/<name>/snaps/snap<N>`).
338
+ * @param commentfile {string} Full path to a file containing a human-readable description of the snapshot.
339
+ * @returns {Promise<number>} The zero-based snapshot number assigned (e.g. `0` for `snap0`).
340
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#ab81bbbabd39179066c4bca619e3bcb7d snapshot}
341
+ */
342
+ snapshot(commentfile: string): Promise<number>;
343
+ /**
344
+ * List all snapshots for this container.
345
+ * @returns {Promise<lxc_snapshot[]>} Array of snapshot descriptor objects.
346
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#aba8a7bc21d7a805110563f5446d9fe82 snapshot_list}
347
+ */
348
+ snapshotList(): Promise<lxc_snapshot[]>;
349
+ /**
350
+ * Restore a container from a named snapshot.
351
+ * The restored container is a full copy of the snapshot placed at `newname` in the same lxcpath.
352
+ * @param snapname {string} Snapshot name (e.g. `"snap0"`).
353
+ * @param newname {string} Name for the restored container. Defaults to the current container's name,
354
+ * which replaces the container in-place (fails for overlay-based snapshots that pin the original).
355
+ * @returns {Promise<void>} Resolves when the restore is complete.
356
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#acc0a13de063830a2ccee54ff88f57f79 snapshot_restore}
357
+ */
358
+ snapshotRestore(snapname: string, newname?: string): Promise<void>;
359
+ /**
360
+ * Destroy a single named snapshot.
361
+ * @param snapname {string} Name of the snapshot to destroy (e.g. `"snap0"`).
362
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a80009a1f8c81e8c0776e9e05d18f0d6b snapshot_destroy}
363
+ */
364
+ snapshotDestroy(snapname: string): Promise<void>;
365
+ /**
366
+ * Destroy all snapshots for this container.
367
+ * @param all {true} Must be `true`.
368
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a16c2f4e7f308f8b1c0b281145cc9c845 snapshot_destroy_all}
369
+ */
370
+ snapshotDestroy(all: true): Promise<void>;
371
+ /**
372
+ * Add a host device node into a running container.
373
+ * @param src_path {string} Full path of the device on the host (e.g. `"/dev/sdb"`).
374
+ * @param dest_path {string | undefined} Path inside the container. Defaults to `src_path`.
375
+ * @returns {Promise<void>} Resolves on success; rejects on error.
376
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a269156192f005e5f3cd44f5834637023 add_device_node}
377
+ */
378
+ addDeviceNode(src_path: string, dest_path?: string): Promise<void>;
379
+ /**
380
+ * Remove a device node from a running container.
381
+ * @param src_path {string} Full path of the device on the host.
382
+ * @param dest_path {string | undefined} Path inside the container. Defaults to `src_path`.
383
+ * @returns {Promise<void>} Resolves on success; rejects on error.
384
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a3866a5cc79af7e8d8d6b15055f356f73 remove_device_node}
385
+ */
386
+ removeDeviceNode(src_path: string, dest_path?: string): Promise<void>;
387
+ /**
388
+ * Move a host network interface into a running container.
389
+ * @param dev {string} Name of the network device on the host (e.g. `"eth1"`).
390
+ * @param dst_dev {string | undefined} Name to use inside the container. Defaults to `dev`.
391
+ * @returns {Promise<void>} Resolves on success; rejects on error.
392
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a33aadfb28b145095bb7213b6bfb02b57 attach_interface}
393
+ */
394
+ attachInterface(dev: string, dst_dev?: string): Promise<void>;
395
+ /**
396
+ * Remove a network interface from a running container and return it to the host.
397
+ * @param dev {string} Name of the network device inside the container.
398
+ * @param dst_dev {string | undefined} Name to restore on the host. Defaults to `dev`.
399
+ * @returns {Promise<void>} Resolves on success; rejects on error.
400
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#ac00d4ee3286ca5c0f2d4283c283fc0ec detach_interface}
401
+ */
402
+ detachInterface(dev: string, dst_dev?: string): Promise<void>;
403
+ /**
404
+ * Checkpoint a running container using CRIU. The container state is written to `directory`
405
+ * and the container can optionally be stopped afterwards.
406
+ * @param directory {string} Directory path to write the checkpoint images to.
407
+ * @param stop {boolean} Stop the container after checkpointing. Default `false`.
408
+ * @param verbose {boolean} Enable verbose CRIU logging. Default `false`.
409
+ * @returns {Promise<void>} Resolves on success; rejects on error.
410
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a0a034333ca81e2a80b5e52bfadd73c5b checkpoint}
411
+ */
412
+ checkpoint(directory: string, stop?: boolean, verbose?: boolean): Promise<void>;
413
+ /**
414
+ * Restore a container from a CRIU checkpoint directory.
415
+ * @param directory {string} Directory path containing the CRIU checkpoint images.
416
+ * @param verbose {boolean} Enable verbose CRIU logging. Default `false`.
417
+ * @returns {Promise<void>} Resolves on success; rejects on error.
418
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#ac7c05a5b4bd5e85557dc080251da2db1 restore}
419
+ */
420
+ restore(directory: string, verbose?: boolean): Promise<void>;
421
+ /**
422
+ * Perform a migration operation (dump, restore, or pre-dump) using CRIU.
423
+ * Use the `LXC_MIGRATE` enum values for `cmd`.
424
+ * @param cmd {LXC_MIGRATE} Operation to perform (`MIGRATE_DUMP`, `MIGRATE_RESTORE`, or `MIGRATE_PRE_DUMP`).
425
+ * @param options {Partial<migrate_opts>} Migration options including directory, page server address, etc.
426
+ * @returns {Promise<void>} Resolves on success; rejects on error.
427
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#aaa8cbcb64d51efb940789863d22e9572 migrate}
428
+ */
429
+ migrate(cmd: LXC_MIGRATE, options?: Partial<migrate_opts>): Promise<void>;
430
+ /**
431
+ * Query or clear the container's in-kernel console ring buffer log.
432
+ * @param options {Partial<lxc_console_log>} Options controlling whether to read, clear, and how many bytes to return.
433
+ * @returns {Promise<string>} The console log data as a string.
434
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a1d9a42547c16a3350e47e9b8978692c1 console_log}
435
+ */
436
+ consoleLog(options?: Partial<lxc_console_log>): Promise<string>;
437
+ /**
438
+ * Bind-mount a host path into the running container.
439
+ * Equivalent to calling `mount(2)` inside the container's mount namespace.
440
+ * @param source {string} Host filesystem path to mount.
441
+ * @param target {string} Mount point inside the container.
442
+ * @param filesystemtype {string | undefined} Filesystem type (e.g. `"tmpfs"`), or `undefined` for bind mounts.
443
+ * @param mountflags {bigint | number | LXC_MOUNT} Flags passed to `mount(2)` (e.g. `MS_BIND`, `MS_RDONLY`).
444
+ * @param mnt {lxc_mount} Mount API version descriptor. Set `version` to `0`.
445
+ * @returns {Promise<void>} Resolves on success; rejects on error.
446
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a6a28265676c212bfe25dbe0c1f7e30ac mount}
447
+ */
448
+ mount(source: string, target: string, filesystemtype: string | undefined, mountflags: bigint | number | LXC_MOUNT, mnt: lxc_mount): Promise<void>;
449
+ /**
450
+ * Unmount a path inside the running container.
451
+ * @param source {string} Path inside the container to unmount.
452
+ * @param mountflags {bigint | number} Flags passed to `umount2(2)` (e.g. `MNT_DETACH`).
453
+ * @param mnt {lxc_mount} Mount API version descriptor. Set `version` to `0`.
454
+ * @returns {Promise<void>} Resolves on success; rejects on error.
455
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a57af1263431950dc4666ba75eda7a817 umount}
456
+ */
457
+ umount(source: string, mountflags: bigint | number, mnt: lxc_mount): Promise<void>;
458
+ /**
459
+ * Retrieve a file descriptor for the container's seccomp notification filter.
460
+ * Used to receive seccomp notifications from the container via `poll(2)`.
461
+ * The container does not need to be running; the fd is pre-loaded at container start.
462
+ * @returns {Promise<number>} The seccomp notification fd.
463
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#aa94c6d2e4f992a9323988e16c05215c2 seccomp_notify_fd}
464
+ */
465
+ seccompNotifyFd(): Promise<number>;
466
+ /**
467
+ * Retrieve a file descriptor for the **running** container's active seccomp filter.
468
+ * Unlike `seccompNotifyFd`, this reflects the live filter of a running container.
469
+ * @returns {Promise<number>} The active seccomp notification fd.
470
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a0247dee4857aa62cff8e76d007e33848 seccomp_notify_fd_active}
471
+ */
472
+ seccompNotifyFdActive(): Promise<number>;
473
+ /**
474
+ * Retrieve a pidfd for the container's init process.
475
+ * A pidfd is a file descriptor that refers to a process and is immune to PID reuse.
476
+ * Useful for safely signalling or polling the container's init with `waitid(P_PIDFD)`.
477
+ * @returns {Promise<number>} The pidfd of the container's init process.
478
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a8cdfb90d01607eb81405ee09504bc7e9 init_pidfd}
479
+ */
480
+ initPIDFd(): Promise<number>;
481
+ /**
482
+ * Retrieve a mount fd for the container's devpts instance.
483
+ * This fd can be used to access the container's pseudo-terminal device hierarchy.
484
+ * @returns {Promise<number>} The mount fd for the container's devpts.
485
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a863a304c9c98e570b016d59ec2016725 devpts_fd}
486
+ */
487
+ devptsFd(): Promise<number>;
488
+ /**
489
+ * Run a command inside the container and wait for it to exit.
490
+ * Uses `lxc_attach_run_command` internally. `argv[0]` is the program to run;
491
+ * subsequent entries are its arguments.
492
+ * @param options.argv {string[]} Command and arguments (e.g. `["/bin/ls", "-la", "/tmp"]`).
493
+ * @param options {Partial<lxc_attach_options>} Additional attach options (uid, gid, env, namespaces, etc.).
494
+ * @returns {Promise<number>} Exit code of the command that ran inside the container.
495
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a8a038faa0449ef8206311e8d5f47f370 attach_run_wait}
496
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__attach__options__t.html lxc_attach_options_t}
497
+ */
498
+ exec(options: Partial<lxc_attach_options> & {
499
+ argv: string[];
500
+ }): Promise<number>;
501
+ /**
502
+ * Set a global timeout for LXC operations on this container.
503
+ * After the timeout expires LXC will abort the operation with an error.
504
+ * Pass `-1` to disable the timeout (wait indefinitely).
505
+ * @param timeout {number} Timeout in seconds, or `-1` to disable.
506
+ * @returns {boolean} `true` on success.
507
+ * @note Requires LXC ≥ 4.0.12. Throws if the library version is older.
508
+ * @see {@link https://github.com/lxc/lxc/blob/main/src/lxc/lxccontainer.h set_timeout}
509
+ */
510
+ setTimeout(timeout: number): boolean;
511
+ /**
512
+ * Determine whether the calling process has sufficient privileges to control this container.
513
+ * Useful as a pre-flight check before attempting operations that require control privileges.
514
+ * @returns {boolean} `true` if the caller may control the container.
515
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a77091f6f92b534595602e433b717f5cd may_control}
516
+ */
517
+ mayControl(): boolean;
518
+ /**
519
+ * Retrieve all configuration keys and their values in a single call.
520
+ * More efficient than calling `getKeys(prefix)` followed by N `getConfigItem(key)` calls.
521
+ * @param prefix {string | undefined} Optional key prefix to filter by (e.g. `"lxc.net"`).
522
+ * Pass `undefined` to retrieve all keys.
523
+ * @returns {Record<string, string | null>} Object mapping each key to its value, or `null` if
524
+ * the key exists but has no value.
525
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a885bbd0d02c3771bcee7b02a2c398be9 get_keys}
526
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a7411db2a0e7a8471c41a4a58d8e83b33 get_config_item}
527
+ */
528
+ getConfigItems(prefix?: string): Record<string, string | null>;
529
+ /**
530
+ * Retrieve a snapshot of common resource usage metrics for a running container.
531
+ * Reads six cgroup v1 entries in a single async operation. Returns `null` for
532
+ * any metric not available on the host kernel or cgroup hierarchy.
533
+ * @returns {Promise<ContainerStats>} Object with cgroup metric values.
534
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html#a6202bf97cd77e208eed1845d5a911cbc get_cgroup_item}
535
+ */
536
+ stats(): Promise<ContainerStats>;
537
+ };
538
+ export type LXC = {
539
+ /**
540
+ * Return the LXC library version string.
541
+ * @returns {string} Version string (e.g. `"5.0.3"`).
542
+ * @see {@link https://github.com/lxc/lxc/blob/main/src/lxc/lxccontainer.h lxc_get_version}
543
+ */
544
+ GetVersion(): string;
545
+ /**
546
+ * Retrieve a global LXC configuration item.
547
+ * Common keys include `"lxc.lxcpath"` (container directory) and `"lxc.default_config"`.
548
+ * @param key {string} Global configuration key to retrieve.
549
+ * @returns {string} The value of the global configuration item.
550
+ * @see {@link https://github.com/lxc/lxc/blob/main/src/lxc/lxccontainer.h lxc_get_global_config_item}
551
+ */
552
+ GetGlobalConfigItem(key: string): string;
553
+ /**
554
+ * List the names of all defined and active containers.
555
+ * Equivalent to `list_defined_containers` ∪ `list_active_containers`.
556
+ * @param lxcpath {string | undefined} Container directory to search. Defaults to `lxc.lxcpath`.
557
+ * @returns {string[]} Array of container name strings.
558
+ * @see {@link https://github.com/lxc/lxc/blob/main/src/lxc/lxccontainer.h list_all_containers}
559
+ */
560
+ ListAllContainers(lxcpath?: string): string[];
561
+ /**
562
+ * List the names of all defined (configured but not necessarily running) containers.
563
+ * A container is defined if its configuration file exists.
564
+ * @param lxcpath {string | undefined} Container directory to search. Defaults to `lxc.lxcpath`.
565
+ * @returns {string[]} Array of container name strings.
566
+ * @see {@link https://github.com/lxc/lxc/blob/main/src/lxc/lxccontainer.h list_defined_containers}
567
+ */
568
+ ListAllDefinedContainers(lxcpath?: string): string[];
569
+ /**
570
+ * List the names of all currently active (running) containers.
571
+ * @param lxcpath {string | undefined} Container directory to search. Defaults to `lxc.lxcpath`.
572
+ * @returns {string[]} Array of container name strings.
573
+ * @see {@link https://github.com/lxc/lxc/blob/main/src/lxc/lxccontainer.h list_active_containers}
574
+ */
575
+ ListAllActiveContainers(lxcpath?: string): string[];
576
+ /**
577
+ * Determine whether a specific configuration key is supported by this LXC build.
578
+ * Useful before setting keys that may not exist in older LXC versions.
579
+ * @param key {string} Configuration key to test (e.g. `"lxc.cap.drop"`).
580
+ * @returns {boolean} `true` if the key is supported, `false` otherwise.
581
+ * @see {@link https://github.com/lxc/lxc/blob/main/src/lxc/lxccontainer.h lxc_config_item_is_supported}
582
+ */
583
+ ConfigItemIsSupported(key: string): boolean;
584
+ /**
585
+ * Determine whether a specific LXC API extension is available in this build.
586
+ * Extension names are stable strings such as `"container_snapshot_comments"`,
587
+ * `"mount_injection"`, or `"seccomp_notify"`.
588
+ * @param extension {string} Extension name to test.
589
+ * @returns {boolean} `true` if the extension is available, `false` otherwise.
590
+ * @see {@link https://github.com/lxc/lxc/blob/main/src/lxc/lxccontainer.h lxc_has_api_extension}
591
+ */
592
+ HasApiExtension(extension: string): boolean;
593
+ /**
594
+ * Return the list of valid container wait-state strings.
595
+ * These are the values accepted by `container.wait()` and returned by `container.state`.
596
+ * @returns {string[]} Array of state name strings (e.g. `["STOPPED", "STARTING", "RUNNING", ...]`).
597
+ * @see {@link https://github.com/lxc/lxc/blob/main/src/lxc/lxccontainer.h lxc_get_wait_states}
598
+ */
599
+ GetWaitStates(): string[];
600
+ /**
601
+ * Container class constructor. Create a new handle for an LXC container by name.
602
+ * @param name {string} Name of the container.
603
+ * @param configPath {string | undefined} Path to the LXC container directory. Defaults to `lxc.lxcpath`.
604
+ * @param alt_file {string | undefined} Path to an alternate configuration file to load.
605
+ * @see {@link https://linuxcontainers.org/lxc/apidoc/structlxc__container.html lxc_container}
606
+ */
607
+ Container: Container;
608
+ };
609
+ export declare const LXC: LXC;
610
+ export declare const GetVersion: () => string, GetGlobalConfigItem: (key: string) => string, ListAllContainers: (lxcpath?: string) => string[], ListAllDefinedContainers: (lxcpath?: string) => string[], ListAllActiveContainers: (lxcpath?: string) => string[], ConfigItemIsSupported: (key: string) => boolean, HasApiExtension: (extension: string) => boolean, GetWaitStates: () => string[], Container: Container;
611
+ export declare const Images: any;
612
+ export * from "./types";