A virtual machine configuration method, device, program product and storage medium
By receiving user instructions, dynamic host configuration protocol and zone matching rules, it automatically identifies and configures virtual machines, solving the inefficiency and error problems caused by manual intervention in existing technologies and realizing efficient and automated virtual machine configuration.
Patent Information
- Application Number
- CN202511073006.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-01
- Publication Date
- 2025-10-10
- Estimated Expiration
- 2045-08-01
AI Technical Summary
Existing virtual machine configuration methods require manual intervention and are prone to errors, resulting in image diversification and repackaging, low efficiency, and inability to quickly adapt to network environments in different regions.
By receiving the user's virtual machine creation instructions, using the Dynamic Host Configuration Protocol to obtain network configuration information, combined with pre-determined area matching rules and configuration template library, it automatically identifies the target area where the virtual machine is located and performs efficient configuration.
It achieves fully automated configuration of virtual machines, reduces human errors, improves configuration efficiency and version update efficiency, and reduces operation and maintenance costs.
Smart Images

Figure CN120560786B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the field of data processing, and in particular to a virtual machine configuration method, device, program product and storage medium. BACKGROUND
[0002] Cloud computing abstracts a large number of servers, storages and network resources into a resource pool that can be elastically scaled, and virtualization technology cuts a physical machine into multiple virtual machines so that applications can be used as needed. When hundreds or thousands of virtual machines need to be quickly online in different cities and different network partitions, the configuration of the virtual machines needs to be performed, for example, configuring parameters such as an Internet Protocol (IP) address, a gateway, a firewall, a time source and a software source for each virtual machine.
[0003] The current virtual machine configuration method is mostly to write the configuration in advance into an image, or to manually or remotely modify the configuration after the machine is started. In this way, different images need to be made for virtual machines in different regions, resulting in more and more images, and all the images need to be repackaged when a patch is released, and the manual script is prone to errors. This method is slow and prone to errors, and reduces the efficiency of virtual machine configuration. SUMMARY
[0004] Embodiments of the present application provide a virtual machine configuration method, device, program product and storage medium, which can automatically identify and efficiently configure virtual machines in different regions, free from repeated packaging and manual intervention, and improve the efficiency of virtual machine configuration.
[0005] In a first aspect, embodiments of the present application provide a virtual machine configuration method, comprising:
[0006] receiving a virtual machine creation instruction sent by a user; the virtual machine creation instruction includes network information, and the network information includes a dynamic host configuration protocol;
[0007] creating and starting the virtual machine based on the virtual machine creation instruction, and obtaining network configuration information based on the virtual machine and the dynamic host configuration protocol;
[0008] determining a target region where the virtual machine is located according to the network configuration information and a predetermined region matching rule;
[0009] determining a target configuration file corresponding to the target region based on a predetermined configuration template library, configuring the virtual machine according to the target configuration file, and running the configured virtual machine.
[0010] In a second aspect, embodiments of the present application provide a virtual machine configuration device, comprising:
[0011] A data receiving module is configured to receive a virtual machine creation instruction sent by a user; the virtual machine creation instruction includes network information, and the network information includes a dynamic host configuration protocol;
[0012] An information acquisition module, configured to create and start the virtual machine based on the virtual machine creation instruction, and acquire network configuration information based on the virtual machine and the dynamic host configuration protocol;
[0013] A region determination module, configured to determine a target region where the virtual machine is located based on the network configuration information and a predetermined region matching rule;
[0014] The automatic configuration module is used to determine a target configuration file corresponding to the target area based on a predetermined configuration template library, configure the virtual machine according to the target configuration file, and run the configured virtual machine.
[0015] In a third aspect, an embodiment of the present invention further provides an electronic device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein when the processor executes the program, a virtual machine configuration method as described in any one of the embodiments of the present invention is implemented.
[0016] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a virtual machine configuration method as described in any one of the embodiments of the present invention.
[0017] In a fifth aspect, an embodiment of the present invention provides a computer program product, comprising a computer program, which, when executed by a processor, implements a virtual machine configuration method as described in any one of the embodiments of the present invention.
[0018] In an embodiment of the present invention, a virtual machine creation instruction is received from a user; the virtual machine creation instruction includes network information, including Dynamic Host Configuration Protocol (DHCP). A virtual machine is created and started based on the virtual machine creation instruction, and network configuration information is obtained based on the virtual machine and DHCP. The target region of the virtual machine is determined based on the network configuration information and predetermined region matching rules. A target configuration file corresponding to the target region is determined based on a predetermined configuration template library, the virtual machine is configured according to the target configuration file, and the configured virtual machine is run. The method of this embodiment of the present invention can automatically identify the target region of the virtual machine based on the network configuration information. Based on the target region, the corresponding configuration template is automatically loaded to ensure that the virtual machine's network configuration, service configuration, and security policy meet regional requirements, thereby improving the efficiency of automatic virtual machine configuration. Furthermore, by using the configuration template, when the virtual machine's configuration information changes, the template only needs to be updated for the change to take effect in the newly started virtual machine, thereby improving the efficiency of version updates. In other words, in this method of this embodiment of the present invention, the user only needs to send a virtual machine creation instruction containing network information, eliminating the need for manual virtual machine configuration. This automated virtual machine configuration reduces human error, improves operation and maintenance efficiency, and reduces operation and maintenance costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. It should be understood that the following drawings only illustrate certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other relevant drawings can be obtained based on these drawings without paying any creative work.
[0020] Figure 1 A flowchart of a virtual machine configuration method provided by an embodiment of the present invention;
[0021] Figure 2 A schematic diagram of the structure of a virtual machine configuration device provided by an embodiment of the present invention;
[0022] Figure 3 A schematic structural diagram of an electronic device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0023] The present invention will be further described in detail below with reference to the accompanying drawings and examples. It will be understood that the specific embodiments described herein are intended only to illustrate the present invention and are not intended to limit the present invention. It should also be noted that, for ease of description, the accompanying drawings only illustrate portions relevant to the present invention, not all structures.
[0024] Figure 1This is a flowchart of a virtual machine configuration method provided by an embodiment of the present invention. The method of the embodiment of the present invention can fully automatically identify and efficiently configure virtual machines in different areas, eliminating repeated packaging and manual intervention, and improving the configuration efficiency of virtual machines. The method can be executed by a virtual machine configuration device provided by an embodiment of the present invention, and the device can be implemented in software and / or hardware. The following embodiments will be described using the device integrated into an electronic device as an example. The electronic device can be a server, a cloud server, or a computer device, etc. Figure 1 , the method may specifically include the following steps:
[0025] Step 101: Receive a virtual machine creation instruction sent by a user.
[0026] The virtual machine creation instructions include network information, which includes the Dynamic Host Configuration Protocol. The Dynamic Host Configuration Protocol (DHCP) is a network protocol used to automatically assign network configuration information such as the virtual machine's IP address, subnet mask, and gateway. During the virtual machine creation process, the virtual machine can obtain network configuration through DHCP, avoiding the complexity and errors of manual configuration. In this solution, the virtual machine creation instructions also include image information and resource requirements. Image information includes the image identifier used by the virtual machine, and resource requirements include the CPU resources, memory resources, and storage resources required by the virtual machine. In a multi-cloud environment, different cloud platforms typically have different image formats and configuration requirements. The image in this solution includes an initialization script that automatically obtains network configuration information and completes configuration at startup. This allows the same image to be used on different cloud platforms, eliminating the need to customize the image for each platform.
[0027] Specifically, in the field of cloud computing and virtualization operations, users need to rapidly deploy large numbers of virtual machines (VMs) on various cloud platforms. Cloud platforms must configure VMs based on specific business needs and network environments to ensure they operate correctly within designated network zones. For example, in a government cloud environment, users need to rapidly deploy VMs in different network zones (such as the government extranet or the internet). To create a VM, users can send a VM creation command to the cloud platform through the platform's front-end interface or application programming interface (API). The cloud platform then automatically creates and configures the VM based on the command.
[0028] Step 102: Create and start a virtual machine based on the virtual machine creation instruction, and obtain network configuration information based on the virtual machine and the Dynamic Host Configuration Protocol.
[0029] Among them, network configuration information is the network parameters required by the virtual machine when running. Network configuration information is used to instruct the virtual machine how to access the network and communicate with other devices. Different network areas correspond to different network configuration information. Specifically, after receiving the virtual machine creation instruction sent by the user, the cloud platform can parse the virtual machine creation instruction, determine the corresponding physical host based on the parsed result, and create the virtual machine on the physical host. In this solution, optionally, creating and starting a virtual machine based on the virtual machine creation instruction includes the following steps A1-A3:
[0030] Step A1: In response to a virtual machine creation instruction, obtain device resources of each physical host, and determine a target physical host according to the device resources.
[0031] The cloud platform is connected to multiple physical hosts. A physical host is the server that actually runs virtual machines. Physical host device resources include CPU usage, memory usage, and storage usage. The target physical host is the physical host used to create a virtual machine for the user.
[0032] In an optional embodiment, after receiving a virtual machine creation instruction from a user, the cloud platform may parse the instruction and, based on the instruction, determine the resource requirements of the virtual machine to be created (including the CPU resources, memory resources, and storage resources required by the virtual machine). After determining the resource requirements of the virtual machine, the cloud platform may collect the device resources of each physical host in real time, match the resource requirements of the virtual machine with the device resources of each physical host, determine a physical host capable of hosting or suitable for hosting the virtual machine to be created, and determine this physical host as the target physical host.
[0033] Step A2: Determine the image corresponding to the image information from the image repository, and copy the image corresponding to the image information to the target physical host.
[0034] An image is a template for a virtual machine's operating system and pre-installed software. The cloud platform includes an image repository, which stores images for different regions, operating systems, and software. The virtual machine creation instruction includes image information, which includes the user-specified image. After determining the target physical host, the cloud platform searches the image repository for the image corresponding to the virtual machine creation instruction and copies or transfers the corresponding image to the target physical host via the cloud platform's internal network.
[0035] Step A3: Determine the network interface of the virtual machine based on the network information, and create and start the virtual machine on the target physical host according to the network interface.
[0036] Network information also includes network interfaces, which correspond to the network zone of the target physical host and are used to control network communications for the virtual machine. After copying the image to the target physical host, the cloud platform parses the network information and generates a network interface configuration file for the virtual machine based on this information, ensuring that the virtual machine can connect to the user-specified network after startup. Furthermore, the virtual machine is created and started on the target physical host.
[0037] By collecting real-time device resources from each physical host, the cloud platform can accurately match the resource requirements of virtual machines and deploy them on the most appropriate physical host, improving resource utilization and ensuring virtual machine performance. Rapid image replication over the internal network reduces image transfer time. After image replication and network configuration are completed on the target physical host, the cloud platform can quickly start the virtual machine, shortening the time from creation to availability.
[0038] After the cloud platform creates and starts a virtual machine on the target physical host, the virtual machine enters the initialization state. The virtual machine can obtain network configuration information based on the dynamic host configuration protocol. In this solution, optionally, obtaining network configuration information based on the virtual machine and the dynamic host configuration protocol includes: sending a network configuration request to the dynamic host configuration protocol server through the virtual machine according to the dynamic host configuration protocol; and receiving the network configuration information returned by the dynamic host configuration protocol server based on the network configuration request.
[0039] DHCP is used to automatically allocate and manage IP addresses and other network configuration parameters for network devices. When a virtual machine starts and initializes its network interface, it can send a broadcast message, known as a network configuration request, to a DHCP server on the network. The network configuration request is used to inquire whether there is a DHCP server on the network that can provide network configuration information. After receiving the network configuration request sent by the virtual machine, the DHCP server on the network parses the network configuration request and extracts information such as the virtual machine's LAN address from the network configuration request. Based on its own configuration policy and information such as the virtual machine's LAN address, the DHCP server assigns an available DHCP server address to the virtual machine and generates a response message, known as the network configuration information. The network configuration information includes the network configuration required by the virtual machine, such as the virtual machine's IP address, subnet mask, gateway, and DHCP server address.
[0040] In an alternative embodiment, after the virtual machine is started and successfully obtains the network configuration information, the virtual machine can record the network configuration information in a DHCP lease file of the virtual machine. The DHCP lease file records important information such as the IP address, subnet mask, and gateway of each network card of the virtual machine. Further, the virtual machine can read the DHCP lease file, organize the information of the DHCP lease file into a table, and generate a network parameter matrix according to the table. The virtual machine can include one or more network cards, including a main network card. The virtual machine can determine the relationship between the network cards according to the parameter matrix, and establish a topology model according to the relationship between the network cards. In the process of establishing the topology model, the virtual machine focuses on the gateway information of the main interface. For example, if the gateway information of the main interface is 172.16.0.1, the virtual machine can record the last digit 1 of the gateway and use it as a reference point for subsequent network configuration.
[0041] In actual application, there can be a case that some network cards are not assigned a gateway. In this case, the virtual machine can use the gateway information of the main interface to automatically complete the information. For example, if the gateway of the main interface is 172.16.0.1 and the slave interface has no gateway, the virtual machine can automatically assign 172.16.0.1 as the gateway of the slave interface, thereby ensuring that all network cards can work normally. In this way, the virtual machine can have a comprehensive understanding and configuration of the network topology of itself, and prepare for subsequent area identification.
[0042] Step 103, determining the target area where the virtual machine is located according to the network configuration information and the pre-determined area matching rule.
[0043] The area in the present scheme is the network environment or business logic partition where the virtual machine is located, which can be divided according to network topology, business needs, and security policies, etc. The area matching rule is pre-configured according to specific needs and field big data, which defines how to determine the area where the virtual machine is located according to the network configuration information. Specifically, after the network configuration information is determined and the network topology of the virtual machine is comprehensively understood according to the network configuration information, the target area where the virtual machine is located can be determined according to the network configuration information and the pre-determined area matching rule. In the present scheme, the target area where the virtual machine is located can be determined according to the network configuration information and the pre-determined area matching rule, which includes the following steps B1-B4:
[0044] Step B1: analyzing the network configuration information through the initialization script in the image to obtain the key configuration information of the virtual machine.
[0045] Key configuration information includes the virtual machine's Internet Protocol address, subnet mask, gateway, and the server address of the Dynamic Host Configuration Protocol server. An image is a template for a virtual machine's operating system and pre-installed software. It contains all the files and configuration information required to start the virtual machine. Images can be copied to different physical hosts to quickly create new virtual machine instances. An initialization script is a script file pre-installed in the image. The initialization script automatically runs when the virtual machine is first started. It is responsible for parsing network configuration information, determining the virtual machine's region, and automatically configuring it according to pre-set rules.
[0046] Specifically, after obtaining the network configuration information, the initialization script can read the network configuration information, extract the virtual machine IP address, subnet mask, gateway and DHCP server address from the network configuration information, obtain key configuration information, and store the key configuration information in the variables of the initialization script, or write the key configuration information to a temporary file for use in subsequent steps.
[0047] Step B2: Determine the number of network adapters in the virtual machine. If the virtual machine has only one network adapter, perform a basic subnet match on the virtual machine's Internet Protocol address based on the region matching rule and subnet mask to obtain a basic subnet match result. If the basic subnet match result is a successful match, determine the target region based on the basic subnet corresponding to the basic subnet match result.
[0048] A basic subnet is a network range defined by an IP address and a subnet mask. The subnet mask defines which portion of an IP address is the network address and which is the host address. Using a subnet mask, a large network can be divided into multiple small basic subnets, each of which can be managed independently. For example, a subnet mask of 255.255.0.0 indicates that the first 16 bits are the network address, and the last 16 bits are the host address. Therefore, the basic subnet 172.16.0.0 / 16 represents the IP address range from 172.16.0.0 to 172.16.255.255.
[0049] Specifically, when a virtual machine has only one network card, its network configuration is relatively simple, with only one IP address and subnet mask. When a virtual machine has only one network card, the area where the virtual machine is located can be directly determined through basic subnet matching. In an optional embodiment, the initialization script can determine the number of network cards in the virtual machine by checking the network interface of the virtual machine. At the same time, the initialization script can determine the IP address and subnet mask of the virtual machine from key configuration information. Furthermore, the initialization script can determine the network address corresponding to the virtual machine based on the IP address and subnet mask of the virtual machine, match the network address with each basic subnet, and if the network address corresponding to the IP address belongs to a basic subnet, the basic subnet matching result is determined to be a successful match.
[0050] For example, the IP address of the virtual machine is 172.16.8.45, and the subnet mask is 255.255.0.0.
[0051] Convert the IP address to binary form: 10101100.00010000.00001000.00101101;
[0052] Convert the subnet mask to binary form: 11111111.111111111.00000000.00000000.
[0053] According to the IP address and subnet mask, the binary form of the network address is calculated through bitwise AND operation: 10101100.00010000.000000000.00000000, and the network address is further determined to be: 172.16.0.0.
[0054] The basic subnet matching rule predefines the basic subnets for the government extranet area as 172.16.0.0 / 16 and 172.26.0.0 / 16. Matching these with the network address shows that the network address 172.16.0.0 belongs to 172.16.0.0 / 16. Therefore, the basic subnet matching result is a successful match, further confirming that the target area is the government extranet area.
[0055] Step B3: If the basic subnet matching result is a match failure, the Internet Protocol address of the virtual machine is matched with each predetermined range to obtain a range matching result; if the range matching result is a match success, the target area is determined according to the predetermined range corresponding to the range matching result.
[0056] If the basic subnet match fails, meaning the virtual machine's network address doesn't match any predefined subnets, the initialization script can attempt a range match. Range matching is suitable for more fine-grained network planning. Specifically, when the basic subnet match fails, the virtual machine's Internet Protocol address is matched against each predetermined range. If the virtual machine's IP address matches a predefined IP range, the range match is considered a successful match. If the range match fails, a safe exit mechanism is triggered, pausing the virtual machine configuration and outputting a prompt indicating the unmatched area.
[0057] For example, the region matching rule defines the basic subnets for the government extranet as 172.16.0.0 / 16 and 172.26.0.0 / 16. The virtual machine's IP address is 172.15.245, and the subnet mask is 255.255.0.0. The virtual machine's network address, 172.15.0.0, does not belong to 172.16.0.0 / 16 or 172.26.0.0 / 16, so the basic subnet match is determined to have failed. Furthermore, a range match is performed: the region matching rule defines the Internet region's IP ranges as: 172.15.240.0 to 172.15.249.0; 172.25.240.0 to 172.25.249.0; and 172.35.240.0 to 172.35.249.0. The virtual machine's IP address is 172.15.245, which falls within the range of 172.15.240.0 to 172.15.249.0. Therefore, the range match result is determined to be a successful match. The target region is further determined to be the Internet region.
[0058] Step B4: When the virtual machine has multiple network cards, obtain the network card Internet Protocol address of each network card; perform region matching on the Internet Protocol address of each network card based on the region matching rule and the subnet mask to obtain the matching result of each network card; when the matching results of all network cards are successful, determine the target region based on the network card regions corresponding to the matching results of all network cards.
[0059] If a virtual machine has multiple network cards (NICs), the initialization script can obtain the VM IP address and subnet mask corresponding to each NIC and calculate the network address for each NIC based on the VM IP address and subnet mask. For each NIC, the script determines whether the network address of the current NIC belongs to the base subnet specified in the region matching rule. If so, the current NIC is considered a successful match. If not, a range match is performed on the current NIC. If the range match is considered a successful match, the current NIC is considered a successful match. If the range match is considered a failed match, the current NIC is considered a failed match. Only when all NICs are successfully matched is the target region determined based on the matching results of all NICs. If at least one NIC fails to match, a safe exit is triggered and a prompt message indicating that the region could not be matched is displayed.
[0060] Furthermore, when the matching results of all network cards are successful, the network card area to which each network card belongs is determined, and whether the network card areas of all network cards belong to the same area is determined. If the network card areas of all network cards belong to the same area, the network card area is determined as the target area. If the network card areas of at least two network cards are different, the safe exit mechanism is triggered, and a prompt message that the area cannot be matched is output.
[0061] For example, the virtual machine has three network cards, namely: primary interface: IP address 172.16.8.45, subnet mask 255.255.0.0; secondary interface: IP address 172.26.1.10, subnet mask 255.255.0.0; tertiary interface: IP address 172.15.245, subnet mask 255.255.0.0. The basic subnets defined in the area matching rules include 172.16.0.0 / 16 and 172.26.0.0 / 16. The network address of the primary interface is calculated to be 172.16.0.0, which belongs to 172.16.0.0 / 16. The primary interface is matched successfully, and the target area of the primary interface is the government extranet area. The network address of the secondary interface is 172.26.0.0, which belongs to 172.26.0.0 / 16. The secondary interface is matched successfully and matches the government extranet area. The network address of the third interface is 172.15.0.0, which does not belong to 172.16.0.0 / 16 or 172.26.0.0 / 16. A range match is performed on the third interface, and its IP address is determined to be within the range of 172.15.240.0 to 172.15.249.0 (defined in the area matching rules). The third interface is then determined to be successfully matched and matched to the Internet area. Further, the network card areas of each network card of the virtual machine are determined as follows: primary interface: government extranet area; secondary interface: government extranet area; third interface: Internet area. The network card area of the third interface is different from the network card areas of the primary and secondary interfaces. The initialization script triggers the safe exit mechanism, suspends the virtual machine configuration, and outputs a prompt message that the area cannot be matched.
[0062] Initialization scripts can dynamically retrieve virtual machine network configuration information, enabling the virtual machine to automatically adapt to different network environments and enhancing virtual machine configuration flexibility. Through a rigorous matching and verification mechanism, the virtual machine can correctly identify its network zone, ensuring the correctness of the virtual machine's network configuration and improving the reliability of the virtual machine configuration. By dynamically acquiring network configuration information, a flexible matching mechanism, and a rigorous verification process, virtual machines can automatically complete configuration in complex network environments without manual intervention, significantly improving deployment efficiency and operational convenience.
[0063] Step 104: Determine a target configuration file corresponding to the target area based on a predetermined configuration template library, configure a virtual machine according to the target configuration file, and run the configured virtual machine.
[0064] Among them, the configuration template library stores the configuration templates of each area, and each configuration template includes information such as the network configuration, service configuration and security policy of the corresponding area. After determining the target area of the virtual machine, the configuration template corresponding to the target area is determined in the configuration template library and determined as the target configuration file. The information in the target configuration file is applied to the virtual machine to automatically configure the virtual machine. In this solution, optionally, after running the configured virtual machine, it also includes: deleting the initialization script and temporary files generated during the configuration of the virtual machine; setting the virtual machine to a prohibited initialization state based on a pre-set disabling instruction.
[0065] Specifically, initialization scripts and temporary files are used to automatically configure network and other system parameters when a virtual machine is first started. If the initialization scripts and temporary files are not cleared, the virtual machine may repeatedly execute the initialization script on subsequent startups, resulting in unnecessary repeated configuration. The initialization script includes an automatic cleanup section, so after completing the configuration of the virtual machine, the initialization script can delete itself and temporary files. To further ensure that the virtual machine does not automatically run the initialization service on subsequent startups, a pre-configured automation tool can be used to execute a disable instruction to set the virtual machine to a disabled initialization state, thereby ensuring that the initialization service does not automatically run on subsequent startups, preventing configuration conflicts and errors, and improving stability and reliability.
[0066] The technical solution of this embodiment receives a virtual machine creation instruction sent by a user; the virtual machine creation instruction includes network information, including Dynamic Host Configuration Protocol (DHCP); creates and starts a virtual machine based on the virtual machine creation instruction, and obtains network configuration information through the virtual machine according to the DHCP protocol; determines the target region of the virtual machine based on the network configuration information and predetermined region matching rules; determines and runs a target configuration file corresponding to the target region based on a predetermined configuration template library, configures the virtual machine according to the target configuration file, and runs the configured virtual machine. The technical solution of this embodiment can automatically identify the target region of the virtual machine based on the network configuration information. Based on the target region, the corresponding configuration template is automatically loaded to ensure that the virtual machine's network configuration, service configuration, and security policy meet regional requirements, thereby improving the efficiency of automatic virtual machine configuration. Furthermore, by using the configuration template, when the virtual machine's configuration information changes, it only needs to update the template for the change to take effect in the newly started virtual machine, thereby improving the efficiency of version updates. In other words, in the method of this embodiment of the present invention, the user only needs to send a virtual machine creation instruction containing network information, eliminating the need for manual virtual machine configuration. Automated virtual machine configuration reduces human error, improves operation and maintenance efficiency, and reduces operation and maintenance costs.
[0067] Figure 2This is a schematic diagram of the structure of a virtual machine configuration device provided by an embodiment of the present invention, which is suitable for executing the virtual machine configuration method provided by an embodiment of the present invention. Figure 2 As shown, the device may specifically include:
[0068] The data receiving module 201 is configured to receive a virtual machine creation instruction sent by a user; the virtual machine creation instruction includes network information, and the network information includes a dynamic host configuration protocol;
[0069] An information acquisition module 202 is configured to create and start the virtual machine based on the virtual machine creation instruction, and acquire network configuration information based on the virtual machine and the dynamic host configuration protocol;
[0070] A region determination module 203 is configured to determine a target region where the virtual machine is located based on the network configuration information and a predetermined region matching rule;
[0071] The automatic configuration module 204 is configured to determine a target configuration file corresponding to the target area based on a predetermined configuration template library, configure the virtual machine according to the target configuration file, and run the configured virtual machine.
[0072] Optionally, the virtual machine creation instruction further includes image information; the information acquisition module 202 is specifically configured to: in response to the virtual machine creation instruction, acquire device resources of each physical host, and determine a target physical host based on the device resources;
[0073] Determine an image corresponding to the image information from an image repository, and copy the image corresponding to the image information to the target physical host;
[0074] The network interface of the virtual machine is determined based on the network information, and the virtual machine is created and started on the target physical host according to the network interface.
[0075] Optionally, the information acquisition module 202 is further configured to: send a network configuration request to a dynamic host configuration protocol server according to the dynamic host configuration protocol through the virtual machine;
[0076] Receive network configuration information returned by the dynamic host configuration protocol server based on the network configuration request.
[0077] Optionally, the region determination module 203 is specifically configured to: parse the network configuration information through the initialization script in the image to obtain key configuration information of the virtual machine; the key configuration information includes the Internet Protocol address, subnet mask and gateway of the virtual machine;
[0078] determining the number of network cards of the virtual machine, when the number of network cards of the virtual machine is one, performing basic subnet matching on the internet protocol address of the virtual machine based on the area matching rule and the subnet mask to obtain a basic subnet matching result;
[0079] if the basic subnet matching result is matching success, determining the target area according to the basic subnet corresponding to the basic subnet matching result.
[0080] Optionally, the area determining module 203 is further configured to: if the basic subnet matching result is matching failure, performing matching on the internet protocol address of the virtual machine and each predetermined range to obtain a range matching result.
[0081] if the range matching result is matching success, determining the target area according to the predetermined range corresponding to the range matching result.
[0082] Optionally, the area determining module 203 is further configured to: when the number of network cards of the virtual machine is multiple, obtaining the network card internet protocol address of each network card.
[0083] performing area matching on each network card internet protocol address based on the area matching rule and the subnet mask to obtain a matching result of each network card.
[0084] when the matching result of all network cards is matching success, determining the target area according to the network card area corresponding to the matching result of all network cards.
[0085] Optionally, the automatic configuration module 204 is specifically configured to: delete the initialization script and temporary files through the initialization script in the mirror information; and set the virtual machine to the initialization prohibited state based on the pre-set disable instruction.
[0086] The virtual machine configuration device provided in the embodiment of the application can execute the virtual machine configuration method provided in any embodiment of the application, and has the corresponding function modules and beneficial effects of the execution method. The contents not described in detail in the embodiment can be referred to the description in any method embodiment of the application.
[0087] The embodiment of the application further provides a computer program product.
[0088] Various embodiments of the systems and techniques described herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system-on-chip systems (SOCs), programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer program products, which can include one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0089] Figure 3 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention, referring to Figure 3 , Figure 3 The electronic device 12 shown is only an example and should not limit the functions and scope of use of the embodiments of the present application. Figure 3 As shown, electronic device 12 is implemented as a general-purpose computing device. Components of electronic device 12 may include, but are not limited to, one or more processors or processing units 16, system memory 28, and a bus 18 that connects various system components (including system memory 28 and processing unit 16).
[0090] Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, or a local bus using any of a variety of bus architectures. Examples of these architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MAC) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.
[0091] The electronic device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the electronic device 12, including volatile and non-volatile media, removable and non-removable media.
[0092] The system memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. The electronic device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 34 may be configured to read and write non-removable, non-volatile magnetic media ( Figure 3 Not shown, usually called a "hard drive"). Although Figure 3 Although not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), as well as an optical drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to bus 18 via one or more data media interfaces. System memory 28 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of various embodiments of the present application.
[0093] A program / utility 40 having a set (at least one) of program modules 46 may be stored, for example, in system memory 28. Such program modules 46 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data, each of which, or some combination thereof, may include an implementation of a network environment. Program modules 46 generally implement the functions and / or methods of the embodiments described herein.
[0094] The electronic device 12 may also communicate with one or more external devices 14 (e.g., keyboards, pointing devices, displays 24, etc.), and may also communicate with one or more devices that enable a user to interact with the electronic device 12, and / or any device that enables the electronic device 12 to communicate with one or more other computing devices (e.g., a network card, a modem, etc.). Such communication may be performed via an input / output (I / O) interface 22. Furthermore, the electronic device 12 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 20. As shown, the network adapter 20 communicates with the other modules of the electronic device 12 via the bus 18. It should be understood that although Figure 3 Not shown, other hardware and / or software modules may be used in conjunction with the electronic device 12, including but not limited to microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0095] The processing unit 16 executes various functional applications and data processing by running the program stored in the system memory 28, for example, implementing a virtual machine configuration method provided by an embodiment of the present invention: receiving a virtual machine creation instruction sent by a user; the virtual machine creation instruction includes network information, and the network information includes a dynamic host configuration protocol; creating and starting the virtual machine based on the virtual machine creation instruction, and obtaining network configuration information through the virtual machine according to the dynamic host configuration protocol; determining the target area where the virtual machine is located based on the network configuration information and a predetermined area matching rule; determining and running a target configuration file corresponding to the target area based on a predetermined configuration template library, configuring the virtual machine according to the target configuration file, and running the configured virtual machine.
[0096] An embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a virtual machine configuration method as provided in all embodiments of the present invention: receiving a virtual machine creation instruction sent by a user; the virtual machine creation instruction includes network information, and the network information includes a dynamic host configuration protocol; creating and starting the virtual machine based on the virtual machine creation instruction, and obtaining network configuration information through the virtual machine according to the dynamic host configuration protocol; determining the target area where the virtual machine is located based on the network configuration information and a predetermined area matching rule; determining and running a target configuration file corresponding to the target area based on a predetermined configuration template library, configuring the virtual machine according to the target configuration file, and running the configured virtual machine. The computer-readable medium may be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium may be, for example, but not limited to, an electronic device, apparatus, or device of electrical, magnetic, optical, electromagnetic, infrared, or semiconductor type, or any combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: an electrical connection having one or more conductors, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In this document, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction-executing electronic device, apparatus, or device.
[0097] A computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transfer a program for use by or in conjunction with an instruction-executing electronic device, apparatus, or device.
[0098] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0099] Computer program code for performing the operations of the present invention may be written in one or more programming languages, or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0100] Note that the above are only preferred embodiments of the present invention and the technical principles employed. Those skilled in the art will appreciate that the present invention is not limited to the specific embodiments herein, and that various obvious changes, readjustments, and substitutions are possible for those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments and may include many other equivalent embodiments without departing from the scope of the present invention. The scope of the present invention is determined by the scope of the appended claims.
Claims
1. A virtual machine configuration method, characterized in that: The method comprises: Receive a virtual machine creation instruction sent by a user; the virtual machine creation instruction includes network information, and the network information includes a dynamic host configuration protocol; Creating and starting a virtual machine based on the virtual machine creation instruction, and acquiring network configuration information based on the virtual machine and the dynamic host configuration protocol; Determining the target area where the virtual machine is located based on the network configuration information and a predetermined area matching rule; including: parsing the network configuration information through an initialization script in the image to obtain key configuration information of the virtual machine; the key configuration information includes the Internet Protocol address, subnet mask and gateway of the virtual machine; determining the number of network cards of the virtual machine, and when the number of network cards of the virtual machine is one, performing basic subnet matching on the Internet Protocol address of the virtual machine based on the area matching rule and the subnet mask to obtain a basic subnet matching result; if the basic subnet matching result is a successful match, determining the target area based on the basic subnet corresponding to the basic subnet matching result; The region matching rule includes predetermined ranges; the method further includes: if the basic subnet matching result is a match failure, matching the Internet Protocol address of the virtual machine with each predetermined range to obtain a range matching result; if the range matching result is a match success, determining the target region based on the predetermined range corresponding to the range matching result; The method further includes: when the virtual machine has multiple network cards, obtaining a network card Internet Protocol address of each network card; performing region matching on the Internet Protocol addresses of each network card based on the region matching rule and the subnet mask to obtain a matching result for each network card; and when the matching results of all network cards are successful, determining the target region based on the network card regions corresponding to the matching results of all network cards; A target configuration file corresponding to the target area is determined based on a predetermined configuration template library, the virtual machine is configured according to the target configuration file, and the configured virtual machine is run.
2. The method according to claim 1, characterized in that The virtual machine creation instruction further includes image information; and creating and starting the virtual machine based on the virtual machine creation instruction includes: In response to the virtual machine creation instruction, obtaining device resources of each physical host, and determining a target physical host according to the device resources; Determine an image corresponding to the image information from an image repository, and copy the image corresponding to the image information to the target physical host; The network interface of the virtual machine is determined based on the network information, and the virtual machine is created and started on the target physical host according to the network interface.
3. The method according to claim 1, characterized in that Acquiring network configuration information based on the virtual machine and the dynamic host configuration protocol includes: Sending a network configuration request to a dynamic host configuration protocol server according to the dynamic host configuration protocol through the virtual machine; Receive network configuration information returned by the dynamic host configuration protocol server based on the network configuration request.
4. The method according to claim 1, wherein The configured virtual machine includes a temporary file, and the method further includes: Deleting the initialization script and temporary files generated during the configuration of the virtual machine; The virtual machine is set to an initialization prohibited state based on a preset prohibition instruction.
5. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the computer program implements a virtual machine configuration method according to any one of claims 1 to 4.
6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the virtual machine configuration method according to any one of claims 1 to 4 is implemented.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the computer program implements a virtual machine configuration method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Method and device for deploying VNF in NFV system based on Openstack
CN109889377A
Network configuration method, device and equipment and readable storage medium
CN111880901A