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 *
import asyncio
def main():
kvm = await VirtualMachine.connect(
host="linux-server.lan",
uuid="c7c2f567-064f-464e-9843-1ed55c04f35e",
platform=HypervisorPlatform.KVM,
auth=("user", "123456")
)
kvm_name = await kvm.name()
hvm = await VirtualMachine.connect(
host="windows-server.lan",
uuid="37a6cee8-f6ce-48c4-a635-7145e8770cca",
platform=HypervisorPlatform.HYPERV,
auth=("user", "123456")
)
hvm_name = await hvm.name()
print(f"Virtual machine on Linux has name: {kvm_name}\nVirtual machine on Windows has name: {hvm_name}")
if __name__ == "__main__":
asyncio.run(main())
Get all VMs on particular hypervisor
from virt_wrapper import *
hypervisor = Hypervisor(
host="windows-server.lan",
platform=HypervisorPlatform.HYPERV,
auth=("user", "123456")
)
# OR
hypervisor = Hypervisor(
host="linux-server.lan",
platform=HypervisorPlatform.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
Release history Release notifications | RSS feed
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.8.5.tar.gz
(15.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file virt_wrapper-0.8.5.tar.gz.
File metadata
- Download URL: virt_wrapper-0.8.5.tar.gz
- Upload date:
- Size: 15.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c8b2486952aa5c3aae2802235c191b89671927d6267b1d2bd658d43a2edf904
|
|
| MD5 |
ca76839c9ea410647662eff3ab51f811
|
|
| BLAKE2b-256 |
09e468b2a8b3743d30f71c171a38c28b20253f3d3faf5d3869b0fd0f93356fc0
|
File details
Details for the file virt_wrapper-0.8.5-py3-none-any.whl.
File metadata
- Download URL: virt_wrapper-0.8.5-py3-none-any.whl
- Upload date:
- Size: 22.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49040bf5ddf9c30e06245f27e89e6fbdb07a38e3de873d28c305cc12120941a1
|
|
| MD5 |
fd28ea1a078b308aefc69eb3d2801f05
|
|
| BLAKE2b-256 |
8723db9561d56ffe18ed8880d48f0916c6c7a9dd5bfa65bf7bc0613c55443dd5
|