From nobody Mon Feb 9 00:06:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1649084769; cv=none; d=zohomail.com; s=zohoarc; b=ZdXY1ObHgWPvoPCERHSeUYgiur1pjbTrPK8bxIOzKdlD2pPyyglIKDyFWJJwssPZHTOuIwGFNeJPzUP+X0gG2EmE/3ZWDMqSjkSYIcrHjJujipjK9yj9rYrYmC4GawOWwVf72XpJLJEQxsl7SNCM7E8ZwiGU8nIhNncvLZW0WPM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1649084769; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=I60ER2CWCPRklHmNKtIROyhoEzh3ENbHlTZnueEvFmI=; b=lDm99nnfA6A3zafEEQVeI53mth+ov5907CXByNwOqeE8xJmjHOHttiJnPPiWgfkhMib5QKaA5yoUqL/dKDnBxyhPNfer0hIfygC0dd0NU0CtIzGJ/lS2BmTkrVyadmXQKCjbdQef7ljj5YvmTpK9JPVwAcTJ6wFlIWp99JSeJl4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 164908476919578.50600988799351; Mon, 4 Apr 2022 08:06:09 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-107-e-yybDXbOhqe4qW4QgIEbg-1; Mon, 04 Apr 2022 11:04:40 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A3F0E811E76; Mon, 4 Apr 2022 15:04:30 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E549C28107; Mon, 4 Apr 2022 15:04:30 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id A29CD194037C; Mon, 4 Apr 2022 15:04:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5D1E01940367 for ; Mon, 4 Apr 2022 15:04:28 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 422E314583CB; Mon, 4 Apr 2022 15:04:28 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD42914582FB for ; Mon, 4 Apr 2022 15:04:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649084768; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=I60ER2CWCPRklHmNKtIROyhoEzh3ENbHlTZnueEvFmI=; b=THFwvCe3Qzz8gzi1ljLPscySqGehmBlR0NHMZ+ZeNmYSKvyERzNairmA9duVBkFKs+eeBH H/q0yh389+iGpelegBySK7nheEbqd+GVpzeJCOXoukjuMkSV1AlthqQSisxuNLTge4iu8a ZDXDSSZ1R8vc9muG/9dCA2nxmNAEN90= X-MC-Unique: e-yybDXbOhqe4qW4QgIEbg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/7] docs: convert 'python' page to rst Date: Mon, 4 Apr 2022 17:04:19 +0200 Message-Id: <3b0132a8c82d040d9cbc31357c73913caf8fcd9d.1649084492.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: application/octet-stream; x-default=true X-Zoho-Virus-Status: 1 X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1649084770780100001 From: Pavel Hrdina Signed-off-by: Pavel Hrdina Signed-off-by: Peter Krempa --- docs/meson.build | 2 +- docs/python.html.in | 72 ----------------------------------------- docs/python.rst | 79 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 73 deletions(-) delete mode 100644 docs/python.html.in create mode 100644 docs/python.rst diff --git a/docs/meson.build b/docs/meson.build index e73cb3c6cd..9022e761ca 100644 --- a/docs/meson.build +++ b/docs/meson.build @@ -29,7 +29,6 @@ docs_html_in_files = [ 'formatstoragecaps', 'index', 'internals', - 'python', 'remote', 'storage', 'tlscerts', @@ -102,6 +101,7 @@ docs_rst_files = [ 'php', 'platforms', 'programming-languages', + 'python', 'securityprocess', 'strategy', 'styleguide', diff --git a/docs/python.html.in b/docs/python.html.in deleted file mode 100644 index 0f804da8c3..0000000000 --- a/docs/python.html.in +++ /dev/null @@ -1,72 +0,0 @@ - - - - -

Python API bindings

- -

The Python binding should be complete and are mostly automatically -generated from the formal description of the API in xml. The bindings are -articulated around 2 classes virConnect and virDomain mapping to -the C types. Functions in the C API taking either type as argument then -becomes methods for the classes, their name is just stripped from the -virConnect or virDomain(Get) prefix and the first letter gets converted to -lower case, for example the C functions:

-

- int virConnectNumOfDomains -(virConnectPtr conn); -

-

- int virDomainSetMaxMemory -(virDomainPtr domain, unsigned long memory); -

-

become

-

- virConnect::numOfDomains(self) -

-

- virDomain::setMaxMemory(self, memory) -

-

This process is fully automated, you can get a summary of the conversion -in the file libvirtclass.txt present in the python dir or in the docs.There -is a couple of function who don't map directly to their C counterparts due to -specificities in their argument conversions:

-
    -
  • virConnectListDomains - is replaced by virDomain::listDomainsID(self) which returns - a list of the integer ID for the currently running domains
  • -
  • virDomainGetInfo - is replaced by virDomain::info() which returns a list of -
    1. state: one of the state values (virDomainState)
    2. maxMemory: the maximum memory used by the domain
    3. memory: the current amount of memory used by the domain
    4. nbVirtCPU: the number of virtual CPU
    5. cpuTime: the time used by the domain in nanoseconds
  • -
-

So let's look at a simple example:

-
import libvirt
-import sys
-
-try:
-    conn = libvirt.openReadOnly(None)
-except libvirt.libvirtError:
-    print('Failed to open connection to the hypervisor')
-    sys.exit(1)
-
-try:
-    dom0 = conn.lookupByName("Domain-0")
-except libvirt.libvirtError:
-    print('Failed to find the main domain')
-    sys.exit(1)
-
-print("Domain 0: id %d running %s" % (dom0.ID(), dom0.OSType()))
-print(dom0.info())
-

There is not much to comment about it, it really is a straight mapping -from the C API, the only points to notice are:

-
    -
  • the import of the module called libvirt
  • -
  • getting a connection to the hypervisor, in that case using the - openReadOnly function allows the code to execute as a normal user.
  • -
  • getting an object representing the Domain 0 using lookupByName
  • -
  • if the domain is not found a libvirtError exception will be raised
  • -
  • extracting and printing some information about the domain using - various methods - associated to the virDomain class.
  • -
- - diff --git a/docs/python.rst b/docs/python.rst new file mode 100644 index 0000000000..aa1bddc4e1 --- /dev/null +++ b/docs/python.rst @@ -0,0 +1,79 @@ +=================== +Python API bindings +=================== + +The Python binding should be complete and are mostly automatically generated +from the formal description of the API in xml. The bindings are articulated +around 2 classes ``virConnect`` and virDomain mapping to the C types. Functions +in the C API taking either type as argument then becomes methods for the +classes, their name is just stripped from the virConnect or virDomain(Get) +prefix and the first letter gets converted to lower case, for example the C +functions: + +``int virConnectNumOfDomains (virConnectPtr conn);`` + +``int virDomainSetMaxMemory (virDomainPtr domain, unsigned long memory);`` + +become + +``virConnect::numOfDomains(self)`` + +``virDomain::setMaxMemory(self, memory)`` + +This process is fully automated, you can get a summary of the conversion in the +file libvirtclass.txt present in the python dir or in the docs.There is a couple +of function who don't map directly to their C counterparts due to specificities +in their argument conversions: + +- ``virConnectListDomains`` is replaced by ``virDomain::listDomainsID(self)`` + which returns a list of the integer ID for the currently running domains + +- ``virDomainGetInfo`` is replaced by ``virDomain::info()`` which returns a + list of + + #. state: one of the state values (virDomainState) + + #. maxMemory: the maximum memory used by the domain + + #. memory: the current amount of memory used by the domain + + #. nbVirtCPU: the number of virtual CPU + + #. cpuTime: the time used by the domain in nanoseconds + +So let's look at a simple example: + +:: + + import libvirt + import sys + + try: + conn = libvirt.openReadOnly(None) + except libvirt.libvirtError: + print('Failed to open connection to the hypervisor') + sys.exit(1) + + try: + dom0 = conn.lookupByName("Domain-0") + except libvirt.libvirtError: + print('Failed to find the main domain') + sys.exit(1) + + print("Domain 0: id %d running %s" % (dom0.ID(), dom0.OSType())) + print(dom0.info()) + +There is not much to comment about it, it really is a straight mapping from the +C API, the only points to notice are: + +- the import of the module called ``libvirt`` + +- getting a connection to the hypervisor, in that case using the openReadOnly + function allows the code to execute as a normal user. + +- getting an object representing the Domain 0 using lookupByName + +- if the domain is not found a libvirtError exception will be raised + +- extracting and printing some information about the domain using various + methods associated to the virDomain class. -- 2.35.1