Method for batch automatic deployment of QEMU virtual machines and bridge network configuration

By automatically obtaining and filling in the bridged network IP of the virtual machine, the problems of low deployment efficiency and difficulty in network configuration are solved, and fast and efficient virtual machine deployment and automated bridged network configuration are achieved, suitable for large-scale virtualization environments .

CN118573573BActive Publication Date: 2024-11-15KYLIN CORP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411060040.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-05
Publication Date
2024-11-15
Estimated Expiration
2044-08-05

AI Technical Summary

Technical Problem

Traditional virtual machines are inefficient and error-prone, especially in large-scale environments. The existing technology cannot automatically configure the IP address of the virtual machine, making it difficult to communicate network between the virtual machine and physical devices.

Method used

By pulling the prepared disk image file from the preset qcow2 mirror repository, obtaining network card information to determine the subnet environment, automatically obtaining and filling in the ifcfg network card configuration file of the available bridged network IP to the virtual machine, and importing the disk image file to Build a virtual machine to realize automated bridge network configuration.

Benefits of technology

It greatly improves the deployment efficiency and configuration accuracy of virtual machines, reduces the risks of manual operations and errors, and is suitable for large-scale virtualization environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118573573B_ABST
    Figure CN118573573B_ABST
Patent Text Reader

Abstract

The present application relates to a method for batch automated deployment of QEMU virtual machines and bridge network configuration, and relates to the field of testing. The method includes pulling a prepared qcow2 disk image file from a preset qcow2 image repository, obtaining network card information and subnet environment information on the QEMU host, and obtaining the available bridge network IPs corresponding to multiple virtual machines to be built in the current subnet segment host address 1‑255 based on the network card information and subnet environment information, filling the obtained multiple available bridge network IPs into the ifcfg network card configuration files corresponding to the multiple virtual machines to be built, and passing them into the qcow2 disks corresponding to the multiple virtual machines to be built, importing the prepared qcow2 disk image file to create multiple virtual machines to be built, and completing the construction of multiple virtual machines to be built. The present application achieves the effect of fast and efficient batch automated deployment of virtual machines.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of testing, and in particular to a method for batch automated deployment of QEMU virtual machines and bridge network configuration. Background Art

[0002] In the field of testing, it is often necessary to build a test environment in a virtual operating system. Compared with using physical machines to build test environments in large quantities, using virtual machines can save hardware costs and shorten installation time and test environment recovery time. Traditional virtual machine deployment requires manual operation, which is inefficient and error-prone for large-scale virtualization environments.

[0003] Chinese patent CN201711228869 discloses a method and device for automatically deploying and installing a system for an ESXI virtual machine. By generating an image file of an unattended operating system and copying the customized image to a designated ESXI host, a virtual machine is established on the ESXI host according to the configured virtual machine parameters and the customized image. The implementation process specifically includes: firstly, using an image mounting tool to mount the original image iso file, then using kickstart to edit the ks.cfg file to make a response file, putting ks.cfg into the original image iso file system, then modifying the isolinux .cfg file boot option in the original image iso file system, and then remaking the image iso file. After making the required image, the customized image is copied to the designated ESXI host through a secure file transfer protocol, a virtual machine is established on the designated ESXI host, and the parameters of the established virtual machine are configured, including hardware parameter configuration and operation parameter configuration.

[0004] Its virtual machine automatic deployment device includes three modules. The first module is used to generate an image file of an unattended operating system and customize the image based on the image file; the second module is used to copy the customized image to a specified ESXI host; and the third module is used to establish a virtual machine on the ESXI host based on the configured virtual machine parameters and the customized image.

[0005] By editing and remaking the virtual machine image iso file for virtual machine installation, the installation process is still required after downloading the iso image, which will take a lot of installation time when deploying virtual machines on a large scale. In addition, the existing technology establishes a virtual machine on the ESXI host through the configured virtual machine parameters and the customized iso image, in which the virtual machine network settings are configured through parameters, but it does not automatically configure the virtual machine IP address, which brings certain difficulties to the network communication between the virtual machine and other physical devices. In the scenario where the virtual machine needs to interact with other physical devices, the existing technology has certain limitations. . Summary of the invention

[0006] To solve the above problems, the present invention provides a method for batch automatic deployment of QEMU virtual machines and bridge network configuration, which adopts the following technical solutions:

[0007] The method of batch automatic deployment of QEMU virtual machines and bridge network configuration includes:

[0008] Pull a prepared qcow2 disk image file from a preset qcow2 image warehouse, wherein the preset qcow2 image warehouse includes multiple qcow2 disk image files, and the qcow2 disk image file includes an installed operating system and required software;

[0009] Obtain network card information on the QEMU host, determine subnet environment information based on the network card information, and obtain available bridge network IPs corresponding to multiple virtual machines to be built in the current subnet segment host address 1-255 based on the subnet environment information;

[0010] Fill the obtained multiple available bridge network IPs into the ifcfg network card configuration files respectively corresponding to the multiple virtual machines to be built, and transfer the ifcfg network card configuration files filled with the available bridge network IPs into the qcow2 disks respectively corresponding to the multiple virtual machines to be built, to complete the network configuration of the multiple virtual machines to be built;

[0011] Import the prepared qcow2 disk image file to create the multiple virtual machines to be built, and complete the construction of the multiple virtual machines to be built.

[0012] In another possible implementation, the prepared qcow2 disk image file is pulled from the preset qcow2 image repository, including:

[0013] Configure the QEMU host and the preset qcow2 image repository without password to pull the qcow2 disk image file.

[0014] In another possible implementation, based on the subnet environment information, obtaining available bridge network IPs corresponding to multiple virtual machines to be constructed in the current subnet segment host address 1-255 respectively includes:

[0015] Based on the subnet environment information, the available bridge network IPs corresponding to the multiple virtual machines to be constructed in the current subnet network segment host address 1-255 are obtained through a ping command loop.

[0016] In another possible implementation, any available bridge network IP obtained is filled into the ifcfg network card configuration files corresponding to the corresponding virtual machines to be built, and the ifcfg network card configuration files filled with the available bridge network IP are respectively transferred to the qcow2 disk of the corresponding virtual machines to be built, to complete the network configuration of the corresponding virtual machines to be built, including:

[0017] Use the virt-copy-out command to transfer the ifcfg network card configuration file under the / etc / sysconfig / network-scripts path in the qcow2 disk of the corresponding virtual machine to be built to the QEMU host;

[0018] Set the network card BOOTPROTO=none to static IP mode, modify and fill in the available bridge network IP, mask and gateway to be the same as the subnet environment information of the current QEMU host, and set the network card onboot=yes to start the machine automatically;

[0019] Through the virt-copy-in command, the ifcfg network card configuration file containing the available bridge network IP is re-transferred to the / etc / sysconfig / network-scripts path in the qcow2 disk of the corresponding virtual machine to be built to overwrite the original network card configuration file, thereby completing the network configuration of the corresponding virtual machine to be built.

[0020] In another possible implementation, importing the prepared qcow2 disk image file to create the multiple virtual machines to be constructed, and completing the construction of the multiple virtual machines to be constructed, includes:

[0021] Check whether the libvirtd service on the QEMU host is enabled;

[0022] If enabled, the prepared qcow2 disk image file is directly imported through the virt-install command to create the multiple virtual machines to be built;

[0023] If not, start the libvirtd service, and use the virt-install command to import the prepared qcow2 disk image file to create the multiple virtual machines to be built.

[0024] In another possible implementation, the method further includes:

[0025] By checking the virtual machine domain list, it is determined whether the multiple virtual machines to be built are successfully created. If not, an error is reported and the system exits.

[0026] If yes, then use the ping command to check whether the bridge network IPs of the multiple virtual machines to be built can communicate normally. If the communication is normal, it is determined that the network configuration is successful. If not, it will report an error and exit.

[0027] In summary, this application includes the following beneficial technical effects:

[0028] By directly importing existing qcow2 disk image files to batch install virtual machines, deployment efficiency is greatly improved. By automatically obtaining and filling in available bridge network IPs, the accuracy and availability of bridge network configuration are ensured, avoiding the tediousness and errors of manual configuration, and achieving fast and efficient virtual machine deployment and automated bridge network configuration, which greatly improves deployment efficiency and configuration accuracy, reduces the risk of manual operation and errors, and can meet the needs of large-scale virtualization environment deployment. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] Figure 1 It is a flow chart of the method for batch automated deployment of QEMU virtual machines and bridge network configuration in an embodiment of the present application. DETAILED DESCRIPTION

[0030] After reading this specification, those skilled in the art may make non-creative modifications to this embodiment as needed, but such modifications are protected by patent law as long as they are within the scope of the claims of this application.

[0031] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings of the specification. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0032] In addition, the term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article, unless otherwise specified, generally means that the associated objects before and after are in an "or" relationship.

[0033] The embodiments of the present application will be further described in detail below in conjunction with the accompanying drawings.

[0034] The embodiment of the present application provides a method for batch automated deployment of QEMU virtual machines and bridge network configuration. QEMU is an open source virtualization software that provides command line tools and APIs. You can write scripts or use automation tools to achieve batch automated deployment of virtual machines. At the same time, QEMU also supports the configuration of bridged networks, connecting virtual machines directly to physical networks, providing independent IP addresses and network access capabilities, and can achieve direct communication between virtual machines and other physical devices, building a more flexible network architecture. Through QEMU batch automated deployment of virtual machines and configuration of bridged networks, the deployment efficiency of virtualized environments can be improved, configuration errors and consistency issues can be reduced, and the automation level and efficiency of system management can be improved, which is of great significance for the construction and management of large-scale virtualized environments.

[0035] like Figure 1 As shown, the method specifically includes:

[0036] Step S101, pull the prepared qcow2 disk image file from the preset qcow2 image repository.

[0037] The preset qcow2 image repository includes multiple qcow2 disk image files, and the qcow2 disk image files include an installed operating system and required software.

[0038] For the embodiment of the present application, the preset qcow2 image warehouse is a pre-set image warehouse, and the administrator stores the virtual machine qcow2 disk image file of the installed operating system and related software on a server with an enabled ftp service as the preset qcow2 image warehouse. The QEMU host needs to be configured with the preset qcow2 image warehouse without secrets to facilitate pulling the qcow2 disk image file, and the virtual machine qcow2 image storage path is set by parameters.

[0039] Step S102, obtaining network card information on the QEMU host, determining subnet environment information based on the network card information, and obtaining available bridge network IPs corresponding to multiple virtual machines to be built in the current subnet segment host address 1-255 based on the subnet environment information.

[0040] For the embodiment of the present application, there may be multiple network cards on the QEMU host, but only one network card is in a communication state. For example, the QEMU host currently has network card A, network card B and network card C. The network card information on the QEMU host is obtained through the ip address command, and it is clear that the network card in the current communication state of the QEMU host is network card A, and the corresponding network card information network card A communication IP is 192.168.122.1. Based on the network card information, the subnet environment information is determined to be 192.168.122. Subsequently, the ping command will be used to loop from 192.168.122.1-192.168.122.255 to obtain the available bridge network IPs corresponding to the multiple virtual machines to be built.

[0041] Step S103, fill the obtained multiple available bridge network IPs into the ifcfg network card configuration files corresponding to the multiple virtual machines to be built, and transfer the ifcfg network card configuration files filled with the available bridge network IPs into the qcow2 disks corresponding to the multiple virtual machines to be built, so as to complete the network configuration of the multiple virtual machines to be built.

[0042] For the embodiment of the present application, in order to facilitate the description, the network configuration process of a single virtual machine to be constructed will be described in detail later. The specific network configuration process includes:

[0043] First, use the virt-copy-out command to transfer the ifcfg network card configuration file in the / etc / sysconfig / network-scripts path in the qcow2 disk of the corresponding virtual machine to be built to the QEMU host, then set the network card BOOTPROTO=none, that is, the static IP mode, modify and fill in the available bridge network IP, mask and gateway to be the same as the subnet environment information of the current QEMU host, set the network card onboot=yes, that is, the boot-up automatic mode, and then use the virt-copy-in command to re-transfer the ifcfg network card configuration file containing the available bridge network IP to the / etc / sysconfig / network-scripts path in the qcow2 disk of the corresponding virtual machine to be built to overwrite the original network card configuration file, so that after the subsequent virtual machine to be built is created, it can automatically load the ifcfg network card configuration file with the available bridge network IP added through self-startup, thereby completing the network configuration of the corresponding virtual machine to be built, thereby greatly simplifying the network configuration process after the virtual machine is installed.

[0044] Step S104, importing the prepared qcow2 disk image file to create multiple virtual machines to be built, and completing the construction of the multiple virtual machines to be built.

[0045] For the embodiment of the present application, when importing the qcow2 disk image file, it is necessary to first detect whether the libvirtd service on the QEMU host is turned on. If not, the libvirtd service needs to be turned on. After ensuring that the libvirtd service is in the turned-on state, the prepared qcow2 disk image file is imported through the virt-install command to create multiple virtual machines to be built, thereby completing the construction of multiple virtual machines to be built.

[0046] Specifically, when the prepared qcow2 disk image file is imported through the virt-install command to create a new virtual machine to be built, the basic configuration parameters and network mode of the virtual machine to be built need to be set through command line parameters, where the basic configuration parameters include: virtual machine name, number of virtual machine CPUs, virtual machine memory size, and virtual machine installation path. In the network mode, the network type is set to passthrough, the network source is the QEMU host bridge network port, the network source mode is bridged, and the network card type is virtio. The network configuration automatically takes effect after the virtual machine to be built is started.

[0047] Furthermore, after the virtual machine to be built is created, in order to ensure normal use, creation verification and network verification are required, wherein creation verification refers to determining whether the virtual machine to be built is successfully created by checking the virtual machine domain list. If not, an error is reported and the system exits. If successful, network verification is further performed. Network verification is to check through the ping command whether the bridge network IP of the virtual machine to be built can communicate normally. If it can communicate normally, it means that the network configuration of the virtual machine to be built is successful. If not, it means that the network configuration has failed and normal communication is impossible, and an error is reported and the system exits.

[0048] The present invention installs virtual machines in batches by directly importing existing qcow2 disk image files, which greatly improves deployment efficiency. By automatically obtaining and filling in available bridge network IPs, the accuracy and availability of bridge network configuration are ensured, the tediousness and errors of manual configuration are avoided, and fast and efficient virtual machine deployment and automated bridge network configuration are achieved, which greatly improves deployment efficiency and configuration accuracy, reduces the risks of manual operation and errors, and is suitable for the needs of large-scale virtualization environment deployment.

[0049] The above are only some implementation methods of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A method for batch automated deployment of QEMU virtual machines and bridge network configuration, characterized in that: include: Pull a prepared qcow2 disk image file from a preset qcow2 image warehouse, wherein the preset qcow2 image warehouse includes multiple qcow2 disk image files, and the qcow2 disk image file includes an installed operating system and required software; Obtain network card information on the QEMU host, determine subnet environment information based on the network card information, and obtain available bridge network IPs corresponding to multiple virtual machines to be built in the current subnet segment host address 1-255 based on the subnet environment information; Fill the obtained multiple available bridge network IPs into the ifcfg network card configuration files respectively corresponding to the multiple virtual machines to be built, and transfer the ifcfg network card configuration files filled with the available bridge network IPs into the qcow2 disks respectively corresponding to the multiple virtual machines to be built, to complete the network configuration of the multiple virtual machines to be built; Import the prepared qcow2 disk image file to create the multiple virtual machines to be built, and complete the construction of the multiple virtual machines to be built; Based on the subnet environment information, the available bridge network IPs corresponding to the multiple virtual machines to be built in the current subnet network segment host address 1-255 are obtained, including: Based on the subnet environment information, the available bridge network IPs corresponding to the multiple virtual machines to be constructed in the current subnet network segment host address 1-255 are obtained through a ping command loop.

2. The method for batch automated deployment of QEMU virtual machines and bridge network configuration according to claim 1, characterized in that: Pull the prepared qcow2 disk image files from the preset qcow2 image repository, including: Configure the QEMU host and the preset qcow2 image repository without password to pull the qcow2 disk image file.

3. The method for batch automated deployment of QEMU virtual machines and bridge network configuration according to claim 1, characterized in that: Fill any available bridge network IP obtained into the ifcfg network card configuration file corresponding to the corresponding virtual machine to be built, and transfer the ifcfg network card configuration file filled with the available bridge network IP into the qcow2 disk of the corresponding virtual machine to be built, to complete the network configuration of the corresponding virtual machine to be built, including: Use the virt-copy-out command to transfer the ifcfg network card configuration file under the / etc / sysconfig / network-scripts path in the qcow2 disk of the corresponding virtual machine to be built to the QEMU host; Set the network card BOOTPROTO=none to static IP mode, modify and fill in the available bridge network IP, mask and gateway to be the same as the subnet environment information of the current QEMU host, and set the network card onboot=yes to start the machine automatically; Through the virt-copy-in command, the ifcfg network card configuration file containing the available bridge network IP is re-transferred to the / etc / sysconfig / network-scripts path in the qcow2 disk of the corresponding virtual machine to be built to overwrite the original network card configuration file, thereby completing the network configuration of the corresponding virtual machine to be built.

4. The method for batch automated deployment of QEMU virtual machines and bridge network configuration according to claim 1, Its characteristics are The step of importing the prepared qcow2 disk image file to create the multiple virtual machines to be constructed and completing the construction of the multiple virtual machines to be constructed includes: Check whether the libvirtd service on the QEMU host is enabled; If enabled, the prepared qcow2 disk image file is directly imported through the virt-install command to create the multiple virtual machines to be built; If not, start the libvirtd service, and use the virt-install command to import the prepared qcow2 disk image file to create the multiple virtual machines to be built.

5. The method for batch automated deployment of QEMU virtual machines and bridge network configuration according to claim 1, characterized in that: The method further comprises: By checking the virtual machine domain list, it is determined whether the multiple virtual machines to be built are created successfully. If not, an error is reported and the system is exited. If so, a ping command is used to check whether the bridge network IPs of the multiple virtual machines to be built can communicate normally. If the communication is normal, it is determined that the network configuration is successful. If not, an error is reported and the system is exited.