virt-lightning


Namevirt-lightning JSON
Version 2.3.0 PyPI version JSON
download
home_page
SummaryDeploy your testing VM in a couple of seconds
upload_time2023-04-22 23:06:07
maintainer
docs_urlNone
author
requires_python>=3.8
license
keywords libvirt cloud qemu cloudinit
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 🗲 spawn Cloud instances on libvirt!🗲


[![Build Status](https://travis-ci.org/virt-lightning/virt-lightning.svg?branch=master)](https://travis-ci.org/virt-lightning/virt-lightning)
[![PyPI version](https://badge.fury.io/py/virt-lightning.svg)](https://badge.fury.io/py/virt-lightning)
[![Documentation](https://shields.io/static/v1?message=Documentation&color=blue)](https://virt-lightning.org/)

![Logo](https://github.com/virt-lightning/virt-lightning/raw/master/logo/logo_no_text.png)

You want to spawn local VM quickly.. Like... really quickly. You want them to be as generical as possible. Actually you would like to reuse some existing cloud images!

This is the right tool for you.

Virt-Lightning exposes a CLI inspired by the Cloud and Vagrant.
It can also prepare the Ansible inventory file.

This is handy to quickly validate a new Ansible playbook, or a role on a large number of environments.

### example: less than 30 seconds to spawn an instance ⚡

In a nutshell:

```shell
echo "- distro: centos-7" > virt-lightning.yaml
vl up
vl ansible_inventory > inventory
ansible all -m ping -i inventory
```

### example: or 75 seconds for 10 nodes lab ⚡

During this recording, we:

1. use the list of distribution to generate a virt-lightning.yaml file.
2. we then create a environment based on this file
3. once the environment is ready, we generate an Ansible inventory file
4. and we use it to call Ansible's ping module on all the host.

[![demo](https://asciinema.org/a/230671.svg)](https://asciinema.org/a/230671?autoplay=1)

## Pre-requirements

- Python 3.8 or greater.
- The Python3 binding for libvirt, the package is probably called `python3-libvirt`.
- You make also want to install `python3-urwid` if you want to get the fancy list of VM. This dependency is optional.
- Libvirt must be running, most of the time you just need to run: `sudo systemctl start --now libvirtd`
- Finally, be sure your user can access the system libvirt daemon, e.g with: `virsh -c qemu:///system`

## Installation

```shell
pip3 install --user virt-lightning
```

If you use Ubuntu, you will need the `--no-deps` argument (See: https://github.com/pypa/pip/issues/4222).

`virt-lightning` will be installed in ~/.local/bin/. Add it in your `$PATH` if
it's not already the case. For instance if you use:

```shell
echo "export PATH=$PATH:~/.local/bin/" >> ~/.bashrc
source ~/.bashrc
```

# Fetch some images

Before you start your first VM, you need to fetch the images. To do so,
you just use the `vl fetch` command:

```shell
$ vl fetch fedora-32
```

# Actions

`vl` is an alias for `virt-lightning`, you can us both. In the rest of the document
we use the shortest version.

## **vl distro_list**

List the distro images that can be used. Its output is compatible with `vl up`. You can initialize a new configuration with: `vl distro_list > virt-lightning.yaml`.

## **vl up**

`virt-lightning` will read the `virt-lightning.yaml` file from the current directory and prepare the associated VM.

## **vl down**

Destroy all the VM managed by Virt-Lightning.

## **vl start**

Start a specific VM, without reading the `virt-lightning.yaml` file.

## **vl stop**

Stop just one VM.

## **vl status**

List the VM, their IP and if they are reachable.

## **vl ansible_inventory**

Export an inventory in the Ansible format.

## **vl ssh**

Show up a menu to select a host and open a ssh connection.

[![vl ssh](https://asciinema.org/a/230675.svg)](https://asciinema.org/a/230675?autoplay=1)

## **vl console**

Like `vl ssh` but with the serial console of the VM.

[![vl ssh](https://asciinema.org/a/230677.svg)](https://asciinema.org/a/230677?autoplay=1)


## **vl viewer**

Like `vl console` but with the SPICE console of the VM. Requires `virt-viewer`.

## **vl fetch**

Fetch a VM image. [You can find here a list of the available images](https://virt-lightning.org/images/). You can also update the custom configuration to add a private image hub.

# Configuration

## Global configuration

If `~/.config/virt-lightning/config.ini` exists, Virt-Lightning will read
its configuration there.

```ini
[main]
network_name = virt-lightning
root_password = root
storage_pool = virt-lightning
network_auto_clean_up = True
ssh_key_file = ~/.ssh/id_rsa.pub
```

**network_name**: if you want to use an alternative libvirt network

**root_password**: the root password

**storage_pool**: if you want to use an alternative libvirt storage pool

**network_auto_clean_up**: if you want to automatically remove a network when running `virt-lightning down`

**ssh_key_file**: if you want to use an alternative public key

**private_hub**: if you need to set additional url from where images should be retrieved, update the configuration file `~/.config/virt-lightning/config.ini` adding the following
```
[main]
private_hub=url1,url2
```

## VM configuration keys

A VM can be tuned at two different places with the following keys:

- `distro`: the name of the base distro image to use, it's the only mandatory parameter.
- `name`: the VM name
- `memory`: the amount of memory to dedicate to the VM
- `vcpus`: the number of vcpu to dedicate to the VM
- `root_password`: the root password in clear text
- `ssh_key_file`: the path of the public key for connecting to the VM
- `groups`: this list of groups will be used if you generate an Ansible inventory.
- `disks`: a list of disks to create and attach to the VM. The first one is used as the root disk. Default to `[{"size": 15}]`
    - `size` the size of the disk in GB. Default is `1`.
- `networks`: a list of network to attach to the VM. The default is: one virtio interface attached to `virt-lightning` network.
    - `network`: the name of the libvirt network. Default is the key `network_name` from the configuration (`virt-lightning` by default). The key cannot be used with `bridge`.
    - `ipv4`: a static IPv4. Default is a dynamic IPv4 address.
    - `nic_model`: the libvirt driver to use. Default is `virtio`
    - `mac`: an optional static MAC address, e.g: '52:54:00:71:b1:b6'
    - `bridge`: optional, the name of a bridge to connect too. This key replace the `network` key.
    - `virtualport_type`: The type of the virtualport, currently, this is can be used with `bridge`.

### Example: a `virt-lightning.yaml` file:

```yaml
- name: esxi-vcenter
  distro: esxi-6.7
  memory: 12000
  root_disk_size: 30
  vcpus: 2
  root_password: '!234AaAa56'
  groups: ['all_esxi']
- name: esxi1
  distro: esxi-6.7
  memory: 4096
  vcpus: 1
  root_password: '!234AaAa56'
  groups: ['all_esxi', 'esxi_lab']
- name: esxi2
  distro: esxi-6.7
  memory: 4096
  vcpus: 1
  root_password: '!234AaAa56'
  groups: ['all_esxi', 'esxi_lab']
- name: centos-7
  distro: centos-7
  networks:
    - network: default
      ipv4: 192.168.122.50
  bootcmd:
    - yum update -y
```

### Example: connect to an OpenvSwitch bridge

```yaml
- name: controller
  distro: fedora-35
  - bridge: my-ovs-bridge-name
    virtualport_type: openvswitch
```

### You can also associate some parameters to the distro image itself

```shell
cat /var/lib/virt-lightning/pool/upstream/esxi-6.7.yaml
username: root
python_interpreter: /bin/python
memory: 4096
networks:
  - network: virt-lightning
    nic_model: virtio
  - network: default
    nic_model: e1000
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "virt-lightning",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "libvirt,cloud,qemu,cloudinit",
    "author": "",
    "author_email": "Gon\u00e9ri Le Bouder <goneri@lebouder.net>",
    "download_url": "https://files.pythonhosted.org/packages/62/75/2ba547ed39e6a7c627462b8fa99dd26883a57747a8b655bf50e404164598/virt-lightning-2.3.0.tar.gz",
    "platform": null,
    "description": "# \ud83d\uddf2 spawn Cloud instances on libvirt!\ud83d\uddf2\n\n\n[![Build Status](https://travis-ci.org/virt-lightning/virt-lightning.svg?branch=master)](https://travis-ci.org/virt-lightning/virt-lightning)\n[![PyPI version](https://badge.fury.io/py/virt-lightning.svg)](https://badge.fury.io/py/virt-lightning)\n[![Documentation](https://shields.io/static/v1?message=Documentation&color=blue)](https://virt-lightning.org/)\n\n![Logo](https://github.com/virt-lightning/virt-lightning/raw/master/logo/logo_no_text.png)\n\nYou want to spawn local VM quickly.. Like... really quickly. You want them to be as generical as possible. Actually you would like to reuse some existing cloud images!\n\nThis is the right tool for you.\n\nVirt-Lightning exposes a CLI inspired by the Cloud and Vagrant.\nIt can also prepare the Ansible inventory file.\n\nThis is handy to quickly validate a new Ansible playbook, or a role on a large number of environments.\n\n### example: less than 30 seconds to spawn an instance \u26a1\n\nIn a nutshell:\n\n```shell\necho \"- distro: centos-7\" > virt-lightning.yaml\nvl up\nvl ansible_inventory > inventory\nansible all -m ping -i inventory\n```\n\n### example: or 75 seconds for 10 nodes lab \u26a1\n\nDuring this recording, we:\n\n1. use the list of distribution to generate a virt-lightning.yaml file.\n2. we then create a environment based on this file\n3. once the environment is ready, we generate an Ansible inventory file\n4. and we use it to call Ansible's ping module on all the host.\n\n[![demo](https://asciinema.org/a/230671.svg)](https://asciinema.org/a/230671?autoplay=1)\n\n## Pre-requirements\n\n- Python 3.8 or greater.\n- The Python3 binding for libvirt, the package is probably called `python3-libvirt`.\n- You make also want to install `python3-urwid` if you want to get the fancy list of VM. This dependency is optional.\n- Libvirt must be running, most of the time you just need to run: `sudo systemctl start --now libvirtd`\n- Finally, be sure your user can access the system libvirt daemon, e.g with: `virsh -c qemu:///system`\n\n## Installation\n\n```shell\npip3 install --user virt-lightning\n```\n\nIf you use Ubuntu, you will need the `--no-deps` argument (See: https://github.com/pypa/pip/issues/4222).\n\n`virt-lightning` will be installed in ~/.local/bin/. Add it in your `$PATH` if\nit's not already the case. For instance if you use:\n\n```shell\necho \"export PATH=$PATH:~/.local/bin/\" >> ~/.bashrc\nsource ~/.bashrc\n```\n\n# Fetch some images\n\nBefore you start your first VM, you need to fetch the images. To do so,\nyou just use the `vl fetch` command:\n\n```shell\n$ vl fetch fedora-32\n```\n\n# Actions\n\n`vl` is an alias for `virt-lightning`, you can us both. In the rest of the document\nwe use the shortest version.\n\n## **vl distro_list**\n\nList the distro images that can be used. Its output is compatible with `vl up`. You can initialize a new configuration with: `vl distro_list > virt-lightning.yaml`.\n\n## **vl up**\n\n`virt-lightning` will read the `virt-lightning.yaml` file from the current directory and prepare the associated VM.\n\n## **vl down**\n\nDestroy all the VM managed by Virt-Lightning.\n\n## **vl start**\n\nStart a specific VM, without reading the `virt-lightning.yaml` file.\n\n## **vl stop**\n\nStop just one VM.\n\n## **vl status**\n\nList the VM, their IP and if they are reachable.\n\n## **vl ansible_inventory**\n\nExport an inventory in the Ansible format.\n\n## **vl ssh**\n\nShow up a menu to select a host and open a ssh connection.\n\n[![vl ssh](https://asciinema.org/a/230675.svg)](https://asciinema.org/a/230675?autoplay=1)\n\n## **vl console**\n\nLike `vl ssh` but with the serial console of the VM.\n\n[![vl ssh](https://asciinema.org/a/230677.svg)](https://asciinema.org/a/230677?autoplay=1)\n\n\n## **vl viewer**\n\nLike `vl console` but with the SPICE console of the VM. Requires `virt-viewer`.\n\n## **vl fetch**\n\nFetch a VM image. [You can find here a list of the available images](https://virt-lightning.org/images/). You can also update the custom configuration to add a private image hub.\n\n# Configuration\n\n## Global configuration\n\nIf `~/.config/virt-lightning/config.ini` exists, Virt-Lightning will read\nits configuration there.\n\n```ini\n[main]\nnetwork_name = virt-lightning\nroot_password = root\nstorage_pool = virt-lightning\nnetwork_auto_clean_up = True\nssh_key_file = ~/.ssh/id_rsa.pub\n```\n\n**network_name**: if you want to use an alternative libvirt network\n\n**root_password**: the root password\n\n**storage_pool**: if you want to use an alternative libvirt storage pool\n\n**network_auto_clean_up**: if you want to automatically remove a network when running `virt-lightning down`\n\n**ssh_key_file**: if you want to use an alternative public key\n\n**private_hub**: if you need to set additional url from where images should be retrieved, update the configuration file `~/.config/virt-lightning/config.ini` adding the following\n```\n[main]\nprivate_hub=url1,url2\n```\n\n## VM configuration keys\n\nA VM can be tuned at two different places with the following keys:\n\n- `distro`: the name of the base distro image to use, it's the only mandatory parameter.\n- `name`: the VM name\n- `memory`: the amount of memory to dedicate to the VM\n- `vcpus`: the number of vcpu to dedicate to the VM\n- `root_password`: the root password in clear text\n- `ssh_key_file`: the path of the public key for connecting to the VM\n- `groups`: this list of groups will be used if you generate an Ansible inventory.\n- `disks`: a list of disks to create and attach to the VM. The first one is used as the root disk. Default to `[{\"size\": 15}]`\n    - `size` the size of the disk in GB. Default is `1`.\n- `networks`: a list of network to attach to the VM. The default is: one virtio interface attached to `virt-lightning` network.\n    - `network`: the name of the libvirt network. Default is the key `network_name` from the configuration (`virt-lightning` by default). The key cannot be used with `bridge`.\n    - `ipv4`: a static IPv4. Default is a dynamic IPv4 address.\n    - `nic_model`: the libvirt driver to use. Default is `virtio`\n    - `mac`: an optional static MAC address, e.g: '52:54:00:71:b1:b6'\n    - `bridge`: optional, the name of a bridge to connect too. This key replace the `network` key.\n    - `virtualport_type`: The type of the virtualport, currently, this is can be used with `bridge`.\n\n### Example: a `virt-lightning.yaml` file:\n\n```yaml\n- name: esxi-vcenter\n  distro: esxi-6.7\n  memory: 12000\n  root_disk_size: 30\n  vcpus: 2\n  root_password: '!234AaAa56'\n  groups: ['all_esxi']\n- name: esxi1\n  distro: esxi-6.7\n  memory: 4096\n  vcpus: 1\n  root_password: '!234AaAa56'\n  groups: ['all_esxi', 'esxi_lab']\n- name: esxi2\n  distro: esxi-6.7\n  memory: 4096\n  vcpus: 1\n  root_password: '!234AaAa56'\n  groups: ['all_esxi', 'esxi_lab']\n- name: centos-7\n  distro: centos-7\n  networks:\n    - network: default\n      ipv4: 192.168.122.50\n  bootcmd:\n    - yum update -y\n```\n\n### Example: connect to an OpenvSwitch bridge\n\n```yaml\n- name: controller\n  distro: fedora-35\n  - bridge: my-ovs-bridge-name\n    virtualport_type: openvswitch\n```\n\n### You can also associate some parameters to the distro image itself\n\n```shell\ncat /var/lib/virt-lightning/pool/upstream/esxi-6.7.yaml\nusername: root\npython_interpreter: /bin/python\nmemory: 4096\nnetworks:\n  - network: virt-lightning\n    nic_model: virtio\n  - network: default\n    nic_model: e1000\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Deploy your testing VM in a couple of seconds",
    "version": "2.3.0",
    "split_keywords": [
        "libvirt",
        "cloud",
        "qemu",
        "cloudinit"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "21eb44f61f7b586a60d6ef67dde1fc8773a59cfb5bf47183c0b3b6186b2247df",
                "md5": "5b1a57a6b5d3746eab400ea5f9fc44e6",
                "sha256": "84b7b02e580ce7ba2c3d990bed122956151ee3e9536cf8f0f19206726c36cc6f"
            },
            "downloads": -1,
            "filename": "virt_lightning-2.3.0-py3-none-any.whl",
            "has_sig": true,
            "md5_digest": "5b1a57a6b5d3746eab400ea5f9fc44e6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 29576,
            "upload_time": "2023-04-22T23:06:06",
            "upload_time_iso_8601": "2023-04-22T23:06:06.391461Z",
            "url": "https://files.pythonhosted.org/packages/21/eb/44f61f7b586a60d6ef67dde1fc8773a59cfb5bf47183c0b3b6186b2247df/virt_lightning-2.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "62752ba547ed39e6a7c627462b8fa99dd26883a57747a8b655bf50e404164598",
                "md5": "a3ea87b1a2738d076bba41862c7bcf52",
                "sha256": "f3c1337c8e4a655024ac3e1eb7f03fe5d93783adf850bd8d1035df4c41df9b2f"
            },
            "downloads": -1,
            "filename": "virt-lightning-2.3.0.tar.gz",
            "has_sig": true,
            "md5_digest": "a3ea87b1a2738d076bba41862c7bcf52",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 75562,
            "upload_time": "2023-04-22T23:06:07",
            "upload_time_iso_8601": "2023-04-22T23:06:07.994854Z",
            "url": "https://files.pythonhosted.org/packages/62/75/2ba547ed39e6a7c627462b8fa99dd26883a57747a8b655bf50e404164598/virt-lightning-2.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-22 23:06:07",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "virt-lightning"
}
        
Elapsed time: 0.05856s