Skip to main content

Wrapper that was developed in order to manage libvirt virtual machines

Project description

Description

Python wrapper for managing virtual infrastructure based on Hyper-V or KVM (libvirt)

Example usage

Get access to particular VM by UUID

from virt_wrapper import *

kvm_driver = KernelVirtualMachineDriver(
    host="linux-server.lan",
    uuid="c7c2f567-064f-464e-9843-1ed55c04f35e",
    auth=("user", "123456"),
)
kvm = VirtualMachine(driver=kvm)

hvm_driver = HyperVirtualMachineDriver(
    host="windows-server.lan",
    uuid="37a6cee8-f6ce-48c4-a635-7145e8770cca",
    auth=("user", "123456"),
)
hvm = VirtualMachine(driver=hvm_driver)

print(f"Virtual machine on Linux has name: {kvm.name()}\nVirtual machine on Windows has name: {hvm.name()}")

Get all VMs on particular hypervisor

from virt_wrapper import *

host_driver = HyperVirtualHostDriver(
    address="windows-server.lan",
    auth=("user", "123456"),
)
host = Host(driver=host_driver)

# OR

host_driver = KernelVirtualHostDriver(
    address="linux-server.lan",
    auth=("user", "123456"),
)
host = Host(driver=host_driver)

for vm in host.virtual_machines():
    print(vm.name())

Requirements

KVM

  • SSH-key must be imported on target server
  • User must have full access to libvirt
usermod <your_user> -aG libvirt
systemctl restart libvirtd

Hyper-V

  • User must have full access to Hyper-V
  • WinRM must be enabled with this parameters
    • HTTPS
    • Basic auth
# Enables the WinRM service and sets up the HTTP listener
Enable-PSRemoting -Force

# Create HTTPS listener
$httpsParams = @{
    ResourceURI = 'winrm/config/listener'
    SelectorSet = @{
        Transport = "HTTPS"
        Address   = "*"
    }
    ValueSet = @{
        CertificateThumbprint = ""
        Enabled               = $true
    }
}
New-WSManInstance @httpsParams

# Enable basic auth
Set-Item -Path WSMan:\localhost\Service\Auth\Basic -Value $true

# Opens port 5986 for all profiles
$firewallParams = @{
    Action      = 'Allow'
    Description = 'Inbound rule for Windows Remote Management via WS-Management. [TCP 5986]'
    Direction   = 'Inbound'
    DisplayName = 'Windows Remote Management (HTTPS-In)'
    LocalPort   = 5986
    Profile     = 'Any'
    Protocol    = 'TCP'
}
New-NetFirewallRule @firewallParams

Available functions:

  • Getting and managing snapshots
  • Getting virtual disks
  • Getting network adapters
  • Getting state
  • Getting description
  • Getting guest OS (guest tools must be installed)
  • Managing of VM state (run, shutdown, poweroff, save, suspend, resume)
  • Getting list of all VMs on host
  • Resize virtual disks
  • Export/Import virtual machines

TODO

  • Migrating
  • Cloning

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

virt_wrapper-0.2.0.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

virt_wrapper-0.2.0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file virt_wrapper-0.2.0.tar.gz.

File metadata

  • Download URL: virt_wrapper-0.2.0.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for virt_wrapper-0.2.0.tar.gz
Algorithm Hash digest
SHA256 695bab664f16eeaf47a0c2fe03d319ac0c9120b6391b669838928000a94d206f
MD5 5539577df5b256f87eb83201972793a5
BLAKE2b-256 213758558146066c79eada46a8dec7ad3d359b0d0f212aae31ea92322a1822cf

See more details on using hashes here.

File details

Details for the file virt_wrapper-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: virt_wrapper-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for virt_wrapper-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be7fabc726c7a72ffcff8d746e278493a3527e0f16707f1da23593704a9ad22b
MD5 0d2e11bd81be8a1be16d13dfb2b2911f
BLAKE2b-256 2836f19ec978ca05f6bbdce67ec839c79479323f25b24ab87009ae907961408f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page