Difference between virsh command and calling libvirt api

Answer: virsh is a package of libvirt API

What is libvirt

libvirt is a collection of software used to manage virtual machines or virtualization functions , mainly including:

   1. libvirt API

   2. The libvirtd process

   3. The three parts of the virsh tool set. The original purpose was to provide a unified management interface for different hypervisors.

The details are as follows:

1. Libvirt API

For specific versions of APIs, please refer to: http://libvirt.org/hvsupport.html . The libvirt api mainly provides unified interfaces for different virtualization technology solutions . Its design ideas are:
(1) isolation from HV API changes-isolation The impact of the underlying hardware virtualization interface on the upper layer
(2) portable across HV-supports a variety of os, such as linux, windows, solaris, etc.
(3) rapid application development-provides packaged API to speed up the software development process
(4) TLS, SASL, SSH, PolicyKit-provides various encryption protocols to ensure the secure access of upper-layer applications to lower-layer resources.
By encapsulating the most primitive C library, interfaces of multiple programming languages ​​are realized: Perl, Python, OCaml, Java, Ruby, C # , Php, and encapsulate the protocols commonly used in application layer programming to form different protocol libraries, which are easy to call in application layer programming. Currently, they mainly support:

1. Mapping to CIM / DMTF: The libvirt-cim
  public information model CIM is a conceptual model for describing management information that has nothing to do with the specific implementation.
2. Mapping to AMQP / QMF: libvirt-qmf
  AMQP is a standard protocol at the application layer that provides unified messaging services. It is a binary protocol that provides asynchronous, safe, and efficient interaction between client applications and message middleware .
  Clients and message middleware based on this protocol can deliver messages without being restricted by different products such as client / middleware and different development languages.
3. Mapping to SNMP: libvirt-snmp
  This library makes libvirt have SNMP function, developers can monitor and set the information of different
domains on each node through SNMP 4. Mapping to GObject: libvirt-glib

2. The daemon process (libvirtd)

The background process mainly implements the following functions:

(1) Remote agent
  All commands sent by remote client are monitored and executed by the process
(2) Local environment initialization
  libvirt service start and stop, user connection response, etc.
(3) Register various drivers (qemu, xen, storage according to the environment …) Implementation
  Different virtualization technologies are implemented in the form of Driver. Since e799bee5baa6e59b9ee7ad9431333337376364 provided by libvirt is a unified interface, each Driver is to implement these interfaces, that is, to register Driver in libvirt

3. virsh toolset  

  It is the encapsulation of libvirt API and the external interface provided by Command Line Interface.

4. Create a virtual machine instance code execution path through the virsh command or interface:

( 1) virsh command or API interface c to create a virtual machine-interface layer
     virsh create vm.xml or virDomainPtr virDomainCreateXML (virConnectPtr conn, const char * xmlDesc, unsigned int flags)
(2) call the unified interface provided by libvirt-abstract driver Layer
  conn-> driver-> domainCreateXML (conn, xmlDesc, flags); // DomainCreateXML here is an abstract unified interface, there is no need to care whether the underlying driver is kvm or xen
(3) Call the corresponding virtualization of the underlying Technical interface-specific driver layer
  domainCreateXML = qemuDomainCreateXML; // If driver = qemu, then the qemu called here is registered to the function qemuDomainCreateXML on the abstract driver layer
(4) Assemble the shell command and execute
  qemu as an example, qemuDomainCreateXML First, it will assemble a command to create a virtual machine, such as qemu -hda disk.img, and then create a new thread to execute
  back to think about. Libvirt uses 4 steps to enter the command at the bottom of the shell to complete the operation Abstract encapsulation is provided to provide application developers with a unified and easy to use mouth.

5. Abstract driver layer

    Currently, libvirt has the following types of abstract drivers. Each type of driver represents an abstract package of a functional module:

(1) Virtualized driver (virDriverPtr)
(2) Virtual network driver (virNetworkDriverPtr)
(3) Physical network card driver (virInterfaceDriverPtr)
(4) Storage driver (virStorageDriverPtr)
(5) Monitor driver (virDeviceMonitorPtr)
(6) Security driver (virSecretDriverPtr) )
(7) Filter driver (virNWFilterDriverPtr)
(8) State driver (virStateDriverPtr)

Guess you like

Origin www.cnblogs.com/dingyunfeng/p/12735554.html