All Projects → fmenabe → python-kvm

fmenabe / python-kvm

Licence: other
Module for managing KVM hosts.

Programming Languages

python
139335 projects - #7 most used programming language

Labels

Projects that are alternatives of or similar to python-kvm

deploy-vm
Libvirt wrapper to spawn VMs using cloud images
Stars: ✭ 56 (+43.59%)
Mutual labels:  kvm
vrnetlab
Run virtual routers with docker
Stars: ✭ 879 (+2153.85%)
Mutual labels:  kvm
halcyon-vagrant-kubernetes
Vagrant deployment mechanism for halcyon-kubernetes.
Stars: ✭ 12 (-69.23%)
Mutual labels:  kvm
ganeti-rpm
Ganeti RPM Packaging
Stars: ✭ 23 (-41.03%)
Mutual labels:  kvm
os
OS for Pi-KVM based on Arch Linux ARM
Stars: ✭ 42 (+7.69%)
Mutual labels:  kvm
terraform-kvm-kubespray
Set up Kubernetes cluster using KVM, Terraform and Kubespray
Stars: ✭ 55 (+41.03%)
Mutual labels:  kvm
home-lab
Documentation and configurations for my home lab
Stars: ✭ 41 (+5.13%)
Mutual labels:  kvm
gpu-passthrough
A GPU passthrough tutorial using libvirt and KVM on GNU/Linux
Stars: ✭ 57 (+46.15%)
Mutual labels:  kvm
md server
Standalone EC2 metadata server to simplify the user of vendor cloud images with standalone kvm/libvirt
Stars: ✭ 36 (-7.69%)
Mutual labels:  kvm
ansible virtualization
Ansible Collection: Virtualization roles
Stars: ✭ 31 (-20.51%)
Mutual labels:  kvm
LEDs-single-gpu-passthrough
Single GPU passthrough guide 单显卡直通教程资源
Stars: ✭ 87 (+123.08%)
Mutual labels:  kvm
okd-lab
Controlled Environment for OKD4 experiments
Stars: ✭ 24 (-38.46%)
Mutual labels:  kvm
birsh
virsh replacement in bash
Stars: ✭ 14 (-64.1%)
Mutual labels:  kvm
IntroVirt
IntroVirt is an guest introspection library for KVM
Stars: ✭ 23 (-41.03%)
Mutual labels:  kvm
barrier
Open-source KVM software
Stars: ✭ 17,366 (+44428.21%)
Mutual labels:  kvm
kernel new features
一个深挖 Linux 内核的新功能特性,以 io_uring, cgroup, ebpf, llvm 为代表,包含开源项目,代码案例,文章,视频,架构脑图等
Stars: ✭ 1,094 (+2705.13%)
Mutual labels:  kvm
packer-kvm
Create VM templates with Packer for usage with Libvirt/KVM virtualization : CentOS 7, CentOS 8, CentOS 8 Stream, Alma Linux, Rocky Linux, Bionic (Ubuntu 1804), Focal (Ubuntu 2004), Debian 11 (stable), Kali Linux, Fedora 33 and Fedora 34.
Stars: ✭ 99 (+153.85%)
Mutual labels:  kvm
cv4pve-botgram
Telegram Bot for Proxmox VE
Stars: ✭ 26 (-33.33%)
Mutual labels:  kvm
fog05
End-to-End Compute, Storage and Networking Virtualisation.
Stars: ✭ 50 (+28.21%)
Mutual labels:  kvm
virtnbdbackup
Backup utiliy for Libvirt / qemu / kvm supporting incremental and differencial backups.
Stars: ✭ 62 (+58.97%)
Mutual labels:  kvm

python-kvm

This module aims to manage KVM hypervisors. For this it use the unix module which allow to manage Unix-like systems, both locally and remotely, in the same by overloading class instances. This module is just a wrapper to the virsh command. It parse outputs of the virsh command (both XML and text). Commands are grouped in childs objects accessible via properties.

Installation

This module is compatible with python2.7 and python 3.*. The module is on PyPi so you can use the pip command for installing it.

For example, to use kvm in a virtualenv:

$ virtualenv env/ --prompt "(myprog)"
$ . ./env/bin/activate
(myprog) $ pip install kvm

Otherwise sources are on github: https://github.com/fmenabe/python-kvm

Usage

You need to import the necessary classes from unix module. An hypervisor is represented by the Hypervisor object and must wrap an object of type unix.Local or unix.Remote. It theorically support any Unix system, but disks manipulations need nbd module to be loaded so it is better to use an unix.linux.Linux host.

>>> from unix import Local, Remote, UnixError
>>> from unix.linux import Linux
>>> import kvm
>>> import json
>>> localhost = kvm.Hypervisor(Linux(Local()))
>>> localhost.hypervisor.nodeinfo()
{'nb_cpu': 1,
 'nb_threads_per_core': 2,
 'memory': 16331936,
 'numa_cells': 1,
 'cpu_model': 'x86_64',
 'nb_cores_per_cpu': 4,
 'nb_cores': 8,
 'cpu_freq': 1340}
>>> localhost.list_domains(all=True)
{'guest1': {'id': -1, 'state': 'shut off'}}
{'guest2': {'id': 1, 'state': 'running'}}
>>> localhost.domain.start('guest1')
# Wait a few seconds for the domain to start.
>>> localhost.domain.state('guest1')
'running'
>>> localhost.domain.id('guest1')
2
>>> print(json.dumps(localhost.domain.conf('guest1'), indent=2))
# json is use for pretty printing the dictionnary containing the
# configuration.
{
  "@type": "kvm",
  "name": "guest1",
  "uuid": "ed68d942-5d4b-7bba-4d74-7d44d73779d3",
  "memory": {
    "@unit": "KiB",
    "#text": "2097152"
  },
  ...
}
>>> localhost.list_networks()
{'default': {'autostart': True, 'persistent': True, 'state': 'active'}}

>>> host = Remote()
>>> host.connect('hypervisor1')
>>> host = kvm.Hypervisor(Linux(host))
>>> host.hypervisor.nodeinfo()
{'cores_per_socket': 12,
 'cpu_frequency': '2200 MHz',
 'cpu_model': 'x86_64',
 'cpu_sockets': 2,
 'cpus': 24,
 'memory_size': '98974432 kB',
 'numa_cells': 1,
 'threads_per_core': 1}
>>> host.list_domains(all=True)
{'guest1': {'id': 1, 'state': 'running'}}
{'guest2': {'id': 2, 'state': 'running'}}
>>> host.domain.shutdown('guest2')
# Wait for the domain to stop.
>>> host.domain.state('guest1')
'shut off'

# Using the context manager for the connecion.
>>> from unix.linux as linux, kvm
>>> with linux.connect('hypervisor1') as host:
...   host = kvm.Hypervisor(host)
...   host.hypervisor.node_info()
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].