|
| 1 | +export type AttachOptions = { |
| 2 | + /** |
| 3 | + * - Flags to control the attach behavior. |
| 4 | + */ |
| 5 | + attachFlags?: number; |
| 6 | + /** |
| 7 | + * - Namespaces to be used. |
| 8 | + */ |
| 9 | + namespaces?: number; |
| 10 | + /** |
| 11 | + * - Personality to be set. |
| 12 | + */ |
| 13 | + personality?: number; |
| 14 | + /** |
| 15 | + * - Initial working directory. |
| 16 | + */ |
| 17 | + initialCwd?: string; |
| 18 | + /** |
| 19 | + * - User ID to be set. |
| 20 | + */ |
| 21 | + uid?: number; |
| 22 | + /** |
| 23 | + * - Group ID to be set. |
| 24 | + */ |
| 25 | + gid?: number; |
| 26 | + /** |
| 27 | + * - Environment policy to be set. |
| 28 | + */ |
| 29 | + envPolicy?: number; |
| 30 | + /** |
| 31 | + * - Extra environment variables. |
| 32 | + */ |
| 33 | + extraEnvVars?: string[]; |
| 34 | + /** |
| 35 | + * - Extra environment variables to keep. |
| 36 | + */ |
| 37 | + extraKeepEnv?: string[]; |
| 38 | + /** |
| 39 | + * - File descriptor for standard input. |
| 40 | + */ |
| 41 | + stdinFd?: number; |
| 42 | + /** |
| 43 | + * - File descriptor for standard output. |
| 44 | + */ |
| 45 | + stdoutFd?: number; |
| 46 | + /** |
| 47 | + * - File descriptor for standard error. |
| 48 | + */ |
| 49 | + stderrFd?: number; |
| 50 | + /** |
| 51 | + * - File descriptor for logging. |
| 52 | + */ |
| 53 | + logFd?: number; |
| 54 | + /** |
| 55 | + * - LSM (Linux Security Module) label. |
| 56 | + */ |
| 57 | + lsmLabel?: string; |
| 58 | + /** |
| 59 | + * - Array of group IDs. |
| 60 | + */ |
| 61 | + groups?: number[]; |
| 62 | +}; |
| 63 | +export type CreateFromTemplateOpts = { |
| 64 | + distro: string; |
| 65 | + release: string; |
| 66 | + arch: string; |
| 67 | +}; |
| 68 | +/** |
| 69 | + * @typedef {Object} AttachOptions |
| 70 | + * @property {number} [attachFlags] - Flags to control the attach behavior. |
| 71 | + * @property {number} [namespaces] - Namespaces to be used. |
| 72 | + * @property {number} [personality] - Personality to be set. |
| 73 | + * @property {string} [initialCwd] - Initial working directory. |
| 74 | + * @property {number} [uid] - User ID to be set. |
| 75 | + * @property {number} [gid] - Group ID to be set. |
| 76 | + * @property {number} [envPolicy] - Environment policy to be set. |
| 77 | + * @property {string[]} [extraEnvVars] - Extra environment variables. |
| 78 | + * @property {string[]} [extraKeepEnv] - Extra environment variables to keep. |
| 79 | + * @property {number} [stdinFd] - File descriptor for standard input. |
| 80 | + * @property {number} [stdoutFd] - File descriptor for standard output. |
| 81 | + * @property {number} [stderrFd] - File descriptor for standard error. |
| 82 | + * @property {number} [logFd] - File descriptor for logging. |
| 83 | + * @property {string} [lsmLabel] - LSM (Linux Security Module) label. |
| 84 | + * @property {number[]} [groups] - Array of group IDs. |
| 85 | + */ |
| 86 | +/** |
| 87 | + * @typedef {Object} CreateFromTemplateOpts |
| 88 | + * @property {string} distro |
| 89 | + * @property {string} release |
| 90 | + * @property {string} arch |
| 91 | + */ |
| 92 | +export class LxcContainer { |
| 93 | + /** |
| 94 | + * Lists all LXC containers. |
| 95 | + * |
| 96 | + * @function |
| 97 | + * @name listContainers |
| 98 | + * @param {string} lxcPath |
| 99 | + * @static |
| 100 | + * @returns {Promise<string[]>} - An array of container names. |
| 101 | + */ |
| 102 | + static listContainers(lxcPath: string): Promise<string[]>; |
| 103 | + constructor(opts: any); |
| 104 | + /** |
| 105 | + * Runs a command and waits for it to finish. |
| 106 | + * |
| 107 | + * @function |
| 108 | + * @name runWait |
| 109 | + * @memberof LxcContainer |
| 110 | + * @param {Object} params - The parameters for the program to run in the container. |
| 111 | + * @param {string} params.program - The program to run. |
| 112 | + * @param {string[]} params.argv - The arguments to provide to the command/program. |
| 113 | + * @param {AttachOptions} params.options - The attach options. |
| 114 | + * @returns {Promise<number>} |
| 115 | + */ |
| 116 | + runWait(params: { |
| 117 | + program: string; |
| 118 | + argv: string[]; |
| 119 | + options: AttachOptions; |
| 120 | + }): Promise<number>; |
| 121 | + /** |
| 122 | + * Queries the console output of the LXC container. |
| 123 | + * |
| 124 | + * @function |
| 125 | + * @name queryConsole |
| 126 | + * @returns {Promise<string>} - The console output. |
| 127 | + */ |
| 128 | + queryConsole(): Promise<string>; |
| 129 | + /** |
| 130 | + * Gets the network interfaces of the LXC container. |
| 131 | + * |
| 132 | + * @function |
| 133 | + * @name getInterfaces |
| 134 | + * @returns {Promise<string[]>} - An array of network interfaces. |
| 135 | + */ |
| 136 | + getInterfaces(): Promise<string[]>; |
| 137 | + /** |
| 138 | + * Gets the IP addresses of the LXC container. |
| 139 | + * |
| 140 | + * @function |
| 141 | + * @name getIps |
| 142 | + * @param {string} interfaceName |
| 143 | + * @param {string} family |
| 144 | + * @param {number?} scope |
| 145 | + * @returns {Promise<string[]>} - An array of IP addresses. |
| 146 | + */ |
| 147 | + getIps( |
| 148 | + interfaceName: string, |
| 149 | + family: string, |
| 150 | + scope: number | null, |
| 151 | + ): Promise<string[]>; |
| 152 | + /** |
| 153 | + * Gets the PID of the LXC container. |
| 154 | + * |
| 155 | + * @function |
| 156 | + * @name getPid |
| 157 | + * @returns {Promise<number>} - The PID of the container. |
| 158 | + */ |
| 159 | + getPid(): Promise<number>; |
| 160 | + /** |
| 161 | + * Reboots the LXC container. |
| 162 | + * |
| 163 | + * @function |
| 164 | + * @name reboot |
| 165 | + * @param {number} timeoutSeconds |
| 166 | + * @returns {Promise<void>} |
| 167 | + */ |
| 168 | + reboot(timeoutSeconds: number): Promise<void>; |
| 169 | + /** |
| 170 | + * Shuts down the LXC container. |
| 171 | + * |
| 172 | + * @function |
| 173 | + * @name shutdown |
| 174 | + * @param {number} timeoutSeconds |
| 175 | + * @returns {Promise<void>} |
| 176 | + */ |
| 177 | + shutdown(timeoutSeconds: number): Promise<void>; |
| 178 | + /** |
| 179 | + * Destroys the LXC container. |
| 180 | + * |
| 181 | + * @function |
| 182 | + * @name destroy |
| 183 | + * @returns {Promise<void>} |
| 184 | + */ |
| 185 | + destroy(): Promise<void>; |
| 186 | + /** |
| 187 | + * Waits for the LXC container to reach a specific state. |
| 188 | + * |
| 189 | + * @function |
| 190 | + * @name waitForState |
| 191 | + * @param {string} state - The state to wait for. |
| 192 | + * @param {number} timeSeconds - The time to wait for the container to enter the state |
| 193 | + * @returns {Promise<void>} |
| 194 | + */ |
| 195 | + waitForState(state: string, timeoutSeconds: any): Promise<void>; |
| 196 | + /** |
| 197 | + * Gets the state of the LXC container. |
| 198 | + * |
| 199 | + * @function |
| 200 | + * @name getState |
| 201 | + * @returns {Promise<string>} - The state of the container. |
| 202 | + */ |
| 203 | + getState(): Promise<string>; |
| 204 | + /** |
| 205 | + * Creates an LXC container from a template. |
| 206 | + * |
| 207 | + * @function |
| 208 | + * @name createFromTemplate |
| 209 | + * @memberof LxcContainer |
| 210 | + * @param {CreateFromTemplateOpts} opts |
| 211 | + * @returns {Promise<void>} |
| 212 | + */ |
| 213 | + createFromTemplate(opts: CreateFromTemplateOpts): Promise<void>; |
| 214 | + /** |
| 215 | + * Stops the LXC container. |
| 216 | + * |
| 217 | + * @function |
| 218 | + * @name stop |
| 219 | + * @param {number} timeoutSeconds |
| 220 | + * @returns {Promise<void>} |
| 221 | + */ |
| 222 | + stop(timeoutSeconds: number): Promise<void>; |
| 223 | + /** |
| 224 | + * Starts the LXC container. |
| 225 | + * |
| 226 | + * @function |
| 227 | + * @name start |
| 228 | + * @returns {Promise<void>} |
| 229 | + */ |
| 230 | + start(): Promise<void>; |
| 231 | + #private; |
| 232 | +} |
0 commit comments