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 = VirtualMachine(
    host="linux-server.lan",
    id="c7c2f567-064f-464e-9843-1ed55c04f35e",
    type=HypervisorType.KVM,
    auth=("user", "123456")
)

hvm = VirtualMachine(
    host="windows-server.lan",
    id="37a6cee8-f6ce-48c4-a635-7145e8770cca",
    type=HypervisorType.HYPERV,
    auth=("user", "123456")
)

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 *

hypervisor = Hypervisor(
    host="windows-server.lan",
    type=HypervisorType.HYPERV,
    auth=("user", "123456")
)

# OR

hypervisor = Hypervisor(
    host="linux-server.lan",
    type=HypervisorType.KVM,
    auth=("user", "123456")
)

for vm in hypervisor.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:

  • Managing snapshots
  • Managing virtual disks
  • Managing networks
  • Getting info about VM (state, description, guest OS, etc.)
  • Controling VM (run, shutdown, pause, etc)
  • Export/Import virtual machines
  • 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.6.1.tar.gz (14.8 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.6.1-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: virt_wrapper-0.6.1.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for virt_wrapper-0.6.1.tar.gz
Algorithm Hash digest
SHA256 2d8f5e6c8c302b1414e3ea211129c7d3a7bf2d97d5ba22a8e13152a4886f3a40
MD5 144d3e42afbdb865be80f9040aa805fa
BLAKE2b-256 8feefdf67085dd1aea8bcaab98ca102f8384f468a6869aa77d6837e40f99edee

See more details on using hashes here.

File details

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

File metadata

  • Download URL: virt_wrapper-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for virt_wrapper-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6e47540b7f44c35b7bc7a2772e4ead3568939636c7de2ef18f1e5677e74ebd3d
MD5 04739e075bc281bcbf269f85bd594962
BLAKE2b-256 ba703906da909de86cd155c2e73316dc0572c31c7793cd251bbb6402572f195f

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