1.1.0 • Published 3 years ago

multipass-control v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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: npm.io npm.io npm.io

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 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"
    }
  }
}

const main = async () => { const listInstance = await localImages(); return listInstance; }

<details>
    <summary>Click here to see sample output</summary>

        {
          "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"
            }
          ]
        }

</details>

### Launch instances
This function will create and start a new instance based on the object provided as argument.

```js
const { launchImage } = require("multipass-control")

const main = async () => {
    const launchInstance = await launchImage({ 
        image: "core18", 
        name: "flattering-racoons" 
    });
    return launchInstance;
}

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 NameRequiredDescription
imageyesThe type of instance you want to create, from the list obtained here
namenoName 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'.
memorynoNumber of CPUs to allocate
disknoDisk space to allocate. Positive integers, in bytes, or with K, M, G suffix.
cpunoNumber 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;
}

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;
}

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;
}

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;
}

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 NameRequiredDescription
nameyesThe name of the instance you want to execute the command on
cmdyesThe 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
}