{"id":18795506,"url":"https://github.com/fmenabe/python-kvm","last_synced_at":"2025-04-13T15:41:00.210Z","repository":{"id":6580144,"uuid":"7822378","full_name":"fmenabe/python-kvm","owner":"fmenabe","description":"Module for managing KVM hosts.","archived":false,"fork":false,"pushed_at":"2021-05-04T10:11:10.000Z","size":128,"stargazers_count":46,"open_issues_count":0,"forks_count":17,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-27T06:34:42.741Z","etag":null,"topics":["kvm","python","virsh"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fmenabe.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-25T15:10:17.000Z","updated_at":"2024-09-07T13:01:34.000Z","dependencies_parsed_at":"2022-09-22T08:07:16.795Z","dependency_job_id":null,"html_url":"https://github.com/fmenabe/python-kvm","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fmenabe%2Fpython-kvm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fmenabe%2Fpython-kvm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fmenabe%2Fpython-kvm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fmenabe%2Fpython-kvm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fmenabe","download_url":"https://codeload.github.com/fmenabe/python-kvm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248681494,"owners_count":21144700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["kvm","python","virsh"],"created_at":"2024-11-07T21:34:20.551Z","updated_at":"2025-04-13T15:41:00.180Z","avatar_url":"https://github.com/fmenabe.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"python-kvm\n==========\n\nThis module aims to manage KVM hypervisors. For this it use the\n`unix module \u003chttps://github.com/fmenabe/python-unix\u003e`_ which allow to manage\nUnix-like systems, both locally and remotely, in the same by overloading class\ninstances. This module is just a wrapper to the ``virsh`` command. It parse\noutputs of the ``virsh`` command (both XML and text). Commands are grouped in\nchilds objects accessible via properties.\n\nInstallation\n------------\nThis module is compatible with python2.7 and python 3.*. The module is\non **PyPi** so you can use the ``pip`` command for installing it.\n\nFor example, to use ``kvm`` in a virtualenv:\n\n.. code:: bash\n\n   $ virtualenv env/ --prompt \"(myprog)\"\n   $ . ./env/bin/activate\n   (myprog) $ pip install kvm\n\nOtherwise sources are on github: https://github.com/fmenabe/python-kvm\n\nUsage\n-----\nYou need to import the necessary classes from ``unix`` module. An hypervisor is\nrepresented by the **Hypervisor** object and must wrap an object of type\n``unix.Local`` or ``unix.Remote``. It theorically support any Unix system, but\ndisks manipulations need *nbd* module to be loaded so it is better to use an\n``unix.linux.Linux`` host.\n\n.. code-block:: python\n\n    \u003e\u003e\u003e from unix import Local, Remote, UnixError\n    \u003e\u003e\u003e from unix.linux import Linux\n    \u003e\u003e\u003e import kvm\n    \u003e\u003e\u003e import json\n    \u003e\u003e\u003e localhost = kvm.Hypervisor(Linux(Local()))\n    \u003e\u003e\u003e localhost.hypervisor.nodeinfo()\n    {'nb_cpu': 1,\n     'nb_threads_per_core': 2,\n     'memory': 16331936,\n     'numa_cells': 1,\n     'cpu_model': 'x86_64',\n     'nb_cores_per_cpu': 4,\n     'nb_cores': 8,\n     'cpu_freq': 1340}\n    \u003e\u003e\u003e localhost.list_domains(all=True)\n    {'guest1': {'id': -1, 'state': 'shut off'}}\n    {'guest2': {'id': 1, 'state': 'running'}}\n    \u003e\u003e\u003e localhost.domain.start('guest1')\n    # Wait a few seconds for the domain to start.\n    \u003e\u003e\u003e localhost.domain.state('guest1')\n    'running'\n    \u003e\u003e\u003e localhost.domain.id('guest1')\n    2\n    \u003e\u003e\u003e print(json.dumps(localhost.domain.conf('guest1'), indent=2))\n    # json is use for pretty printing the dictionnary containing the\n    # configuration.\n    {\n      \"@type\": \"kvm\",\n      \"name\": \"guest1\",\n      \"uuid\": \"ed68d942-5d4b-7bba-4d74-7d44d73779d3\",\n      \"memory\": {\n        \"@unit\": \"KiB\",\n        \"#text\": \"2097152\"\n      },\n      ...\n    }\n    \u003e\u003e\u003e localhost.list_networks()\n    {'default': {'autostart': True, 'persistent': True, 'state': 'active'}}\n\n    \u003e\u003e\u003e host = Remote()\n    \u003e\u003e\u003e host.connect('hypervisor1')\n    \u003e\u003e\u003e host = kvm.Hypervisor(Linux(host))\n    \u003e\u003e\u003e host.hypervisor.nodeinfo()\n    {'cores_per_socket': 12,\n     'cpu_frequency': '2200 MHz',\n     'cpu_model': 'x86_64',\n     'cpu_sockets': 2,\n     'cpus': 24,\n     'memory_size': '98974432 kB',\n     'numa_cells': 1,\n     'threads_per_core': 1}\n    \u003e\u003e\u003e host.list_domains(all=True)\n    {'guest1': {'id': 1, 'state': 'running'}}\n    {'guest2': {'id': 2, 'state': 'running'}}\n    \u003e\u003e\u003e host.domain.shutdown('guest2')\n    # Wait for the domain to stop.\n    \u003e\u003e\u003e host.domain.state('guest1')\n    'shut off'\n\n    # Using the context manager for the connecion.\n    \u003e\u003e\u003e from unix.linux as linux, kvm\n    \u003e\u003e\u003e with linux.connect('hypervisor1') as host:\n    ...   host = kvm.Hypervisor(host)\n    ...   host.hypervisor.node_info()\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffmenabe%2Fpython-kvm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffmenabe%2Fpython-kvm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffmenabe%2Fpython-kvm/lists"}