multipass-control
v1.1.0
Published
A package to control multipass from within your NodeJS application like launching an image, stopping or deleting images. This package requires Multipass to be installed on your system.
Downloads
5
Maintainers
Readme
Multipass Control
What is it?
A package to control Multipass VM manager from within your NodeJS application for controls like launching, stopping or deleting Ubuntu images. This package requires an installation of Multipass on your system.
Works on:
Installation
To install the package:
Using NPM:
npm install multipass-control
Using Yarn:
yarn add multipass-control
Usage
You can perform the following tasks using multipass-control:
- List available instances
- List installed instances
- Launch instance
- Instance information
- Start instances
- Stop instances
- Restart instances
- Suspend instances
- Delete instances
- Recover instances
- Execute command on instances
- Purge deleted instances
List available images
This function returns a JSON object with aliases that can be used to launch instances on your device along with information about them. This function does not take any parameters.
const { findImages } = require("multipass-control")
const main = async () => {
const availableImages = await findImages();
return availableImages;
}
{
"errors": [],
"images": {
"18.04": {
"aliases": ["bionic"],
"os": "Ubuntu",
"release": "18.04 LTS",
"remote": "",
"version": "20210604"
},
"20.04": {
"aliases": ["focal", "lts"],
"os": "Ubuntu",
"release": "20.04 LTS",
"remote": "",
"version": "20210603"
},
"20.10": {
"aliases": ["groovy"],
"os": "Ubuntu",
"release": "20.10",
"remote": "",
"version": "20210604"
},
"appliance:adguard-home": {
"aliases": [],
"os": "Ubuntu",
"release": "AdGuard Home Appliance",
"remote": "appliance",
"version": "20200812"
},
"appliance:mosquitto": {
"aliases": [],
"os": "Ubuntu",
"release": "Mosquitto Appliance",
"remote": "appliance",
"version": "20200812"
},
"appliance:nextcloud": {
"aliases": [],
"os": "Ubuntu",
"release": "Nextcloud Appliance",
"remote": "appliance",
"version": "20200812"
},
"appliance:openhab": {
"aliases": [],
"os": "Ubuntu",
"release": "openHAB Home Appliance",
"remote": "appliance",
"version": "20200812"
},
"appliance:plexmediaserver": {
"aliases": [],
"os": "Ubuntu",
"release": "Plex Media Server Appliance",
"remote": "appliance",
"version": "20200812"
},
"core": {
"aliases": ["core16"],
"os": "Ubuntu",
"release": "Core 16",
"remote": "",
"version": "20200818"
},
"core18": {
"aliases": [],
"os": "Ubuntu",
"release": "Core 18",
"remote": "",
"version": "20200812"
},
"snapcraft:core18": {
"aliases": [],
"os": "",
"release": "Snapcraft builder for Core 18",
"remote": "snapcraft",
"version": "20201111"
},
"snapcraft:core20": {
"aliases": [],
"os": "",
"release": "Snapcraft builder for Core 20",
"remote": "snapcraft",
"version": "20201111"
}
}
}
List installed instances
This function returns a JSON object containing all the created instances along with some of their properties.
const { localImages } = require("multipass-control")
const main = async () => {
const listInstance = await localImages();
return listInstance;
}
{
"list": [
{
"ipv4": [],
"name": "Rabbit-Hole",
"release": "Core 16",
"state": "Suspended"
},
{
"ipv4": ["N/A"],
"name": "primary",
"release": "20.04 LTS",
"state": "Running"
},
{
"ipv4": ["N/A"],
"name": "included-rudd",
"release": "Core 16",
"state": "Running"
}
]
}
Launch instances
This function will create and start a new instance based on the object provided as argument.
const { launchImage } = require("multipass-control")
const main = async () => {
const launchInstance = await launchImage({
image: "core18",
name: "flattering-racoons"
});
return launchInstance;
}
{
"successful": true,
"error": null,
"output": "Launched: flattering-racoons"
}
The function takes image
as a necessary object property, however you can customize your instance by providing other properties as well. These are all the properties the object takes:
| Property Name | Required | Description |
| :-----------: | :------: | :--------- |
| image
| yes | The type of instance you want to create, from the list obtained here |
| name
| no | Name for the instance you would like to give. If it is 'primary' (the configured primary instance name), the user's home directory is mounted inside the newly launched instance, in 'Home'. |
| memory
| no | Number of CPUs to allocate |
| disk
| no | Disk space to allocate. Positive integers, in bytes, or with K, M, G suffix. |
| cpu
| no | Number of CPUs to allocate. Minimum: 1, default: 1. |
Instance information
This function returns a JSON object with properties of the instances provided as arguments
const { imageInfo } = require("multipass-control")
const main = async () => {
const instanceInformation = await imageInfo("flattering-racoons");
return instanceInformation;
}
{
"errors": [],
"info": {
"flattering-racoons": {
"disks": { "sda1": { "total": "104071168", "used": "104071168" } },
"image_hash": "db3a6130f46f8d84adb792a95081671a14d8b90c6ddda7b3e25a1d7d4c0e98b4",
"image_release": "Core 16",
"ipv4": ["N/A"],
"load": [0, 0, 0],
"memory": { "total": 511766528, "used": 40534016 },
"mounts": {},
"release": "Core 16",
"state": "Running"
}
}
}
Start instances
This function will start the instance provided as the argument.
const { startImage } = require("multipass-control")
const main = async () => {
const startInstance = await startImage("flattering-racoons");
return startInstance;
}
{
"successful": true,
"error": null
}
Stop instances
This function will stop the instance provided as the argument.
const { stopImage } = require("multipass-control")
const main = async () => {
const stopInstance = await stopImage("flattering-racoons");
return stopInstance;
}
{
"successful": true,
"error": null
}
Restart instances
This function will restart the instance provided as the argument.
const { restartImage } = require("multipass-control")
const main = async () => {
const restartInstance = await restartImage("flattering-racoons");
return restartInstance;
}
{
"successful": true,
"error": null
}
Suspend instances
This function will suspend the instance provided as the argument.
const { suspendImage } = require("multipass-control")
const main = async () => {
const suspendInstance = await suspendImage("flattering-racoons");
return suspendInstance;
}
{
"successful": true,
"error": null
}
Delete instances
This function will delete the instance provided as the argument.
const { deleteImage } = require("multipass-control")
const main = async () => {
const deleteInstance = await deleteImage("flattering-racoons");
return deleteInstance;
}
{
"successful": true,
"error": null
}
Recover instances
This function will recover the deleted instance provided as the argument.
const { recoverImage } = require("multipass-control")
const main = async () => {
const recoverInstance = await recoverImage("flattering-racoons");
return recoverInstance;
}
{
"successful": true,
"error": null
}
Execute command on instances
This function will execute the command on the instance provided as the argument.
const { executeCommand } = require("multipass-control")
const main = async () => {
const executing = await executeCommand({
name: "flattering-racoons",
cmd: "pwd",
});
return availableImages;
}
{
"successful": true,
"error": null,
"output": "/home/ubuntu"
}
The function takes name
and cmd
as a necessary object property, however you can customize your instance by providing other properties as well. These are all the properties the object takes:
| Property Name | Required | Description |
| :-----------: | :------: | :--------- |
| name
| yes | The name of the instance you want to execute the command on |
| cmd
| yes | The command you want to execute on the instance |
Keep in mind that all commands are run with respect to /home/ubuntu
directory.
Purge deleted instances
This function will remove all deleted instances from your system permanently
const { purgeImages } = require("multipass-control")
const main = async () => {
const purgeInstances = await purgeImages();
return purgeInstances;
}
{
"successful": true,
"error": null
}