Virtual machine cloning method and device, equipment and medium

By distinguishing storage cloning and parameter cloning modes, creating resources asynchronously and managing network addresses dynamically, the waste of storage resources and network address conflicts caused by full cloning in KubeVirt components is solved, and the virtual machine cloning efficiency and network configuration efficiency are improved.

CN120540787APending Publication Date: 2025-08-26INSPUR ENTERPRISE CLOUD TECHNOLOGY (SHANDONG) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510745300.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-05
Publication Date
2025-08-26

AI Technical Summary

Technical Problem

The VirtualMachineClone CRD of KubeVirt component only supports full cloning mode, resulting in wasted storage resources and does not support dynamic address pool management. Relying on manual intervention leads to increased cloning time.

Method used

By judging cloning business needs, distinguishing storage cloning mode and parameter cloning mode, creating target dependency resources asynchronously and calculating network addresses, monitoring cloning status to realize network configuration, supporting disk storage cloning and configuration parameter cloning, and dynamically managing network addresses.

Benefits of technology

It avoids waste of storage resources under full cloning, improves cloning efficiency, reduces manual intervention, solves network address conflict problems, and improves network configuration efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120540787A_ABST
    Figure CN120540787A_ABST
Patent Text Reader

Abstract

The invention discloses a virtual machine cloning method, device and equipment and a medium, and is applied to the field of computers, and the method comprises the following steps: judging whether disk data of an original virtual machine instance needs to be reused or not based on a cloning service demand; if reuse is needed and a disk of the original virtual machine instance supports a storage clone function, closing the original virtual machine instance, and triggering a storage clone process of the disk through virtual machine clone resources to generate a target virtual machine; if the virtual machine instance does not need to be reused, analyzing the configuration parameters of the original virtual machine instance, and creating a new virtual machine instance based on the configuration parameters; asynchronously creating a target dependent resource, and asynchronously calculating a target network address; and monitoring the cloning state of the target virtual machine, and implementing corresponding network configuration based on the target network address after monitoring that cloning is completed or a new virtual machine instance is created. According to the invention, waste of storage resources in a scene that only parameters need to be configured in traditional full-quantity cloning is avoided, and the problem of network address conflict caused by static configuration is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a virtual machine cloning method, device, equipment and medium. Background Art

[0002] Kubernetes and KubeVirt (the Kubernetes virtualization component) form a powerful platform that supports modern containerized applications while also being compatible with traditional virtual machines (VMs). Its virtual machine cloning feature significantly improves the efficiency and flexibility of IT (Information Technology) operations and maintenance, providing significant convenience for both individual users and enterprise applications, helping to reduce costs and risks. However, the KubeVirt component's VirtualMachineClone Custom Resource Definition (CRD) has the following limitations: (1) It only supports full cloning mode, which wastes storage resources when cloning only requires retaining configuration parameters; (2) It does not support dynamic address pool management, requiring manual intervention and adjustments, which increases cloning time. Summary of the Invention

[0003] In view of this, the purpose of the present invention is to provide a virtual machine cloning method, apparatus, device, and medium. This application avoids the waste of storage resources in traditional full cloning scenarios where only parameter configuration is required, and solves the network address conflict problem caused by static configuration. The specific solution is as follows:

[0004] In a first aspect, the present application discloses a virtual machine cloning method, comprising:

[0005] Determine whether to reuse the disk data of the original virtual machine instance based on the cloning business needs;

[0006] If the disk data of the original virtual machine instance needs to be reused and the disk of the original virtual machine instance supports the storage cloning function, the original virtual machine instance is shut down, and the storage cloning process of the disk is triggered through the virtual machine clone resource to generate the target virtual machine;

[0007] If the disk data of the original virtual machine instance does not need to be reused, parsing the configuration parameters of the original virtual machine instance and creating a new virtual machine instance based on the configuration parameters;

[0008] Asynchronously create target dependent resources and asynchronously calculate the target network address;

[0009] The cloning status of the target virtual machine is monitored, and corresponding network configuration is implemented based on the target network address after monitoring that the cloning is completed or after the new virtual machine instance is created.

[0010] Optionally, the virtual machine cloning method further includes:

[0011] Extract the disk persistent volume claim name from the original virtual machine instance;

[0012] Get the field value of the storage configurator according to the disk persistent volume declaration name;

[0013] If the field value of the storage configurator includes an identification value indicating support for the storage cloning function, it is determined that the disk of the original virtual machine instance supports the storage cloning function.

[0014] Optionally, the asynchronous creation of target dependent resources includes:

[0015] Asynchronously create a network security group, key login credentials and migration scheduling policy; the network security group is used to define the inbound and outbound rules of the virtual machine, the key login credentials are used to store the access information of the virtual machine, and the migration scheduling policy is used to configure the migration rules of the virtual machine between computing nodes.

[0016] Optionally, the virtual machine cloning method further includes:

[0017] In the steps of triggering the storage cloning process of the disk, parsing the configuration parameters of the original virtual machine instance, asynchronously creating the target dependent resources, asynchronously calculating the target network address, or implementing the corresponding network configuration based on the target network address, if any step meets the preset failure condition, all created resources are rolled back.

[0018] Optionally, if any step meets the preset failure condition, all created resources are rolled back, including:

[0019] If any step fails and the number of re-executions of the step reaches a preset threshold, all created resources will be rolled back.

[0020] Optionally, the target network address includes an Internet Protocol address and a Media Access Control address.

[0021] Optionally, implementing corresponding network configuration based on the target network address after monitoring completion of cloning or after creating the new virtual machine instance includes:

[0022] After monitoring that the cloning is completed or after creating the new virtual machine instance, a label of the Internet Protocol address and an annotation of the media access control address are added to the target virtual machine or the new virtual machine instance.

[0023] In a second aspect, the present application discloses a virtual machine cloning device, comprising:

[0024] A judgment module is used to determine whether the disk data of the original virtual machine instance needs to be reused based on the cloning business requirements;

[0025] A first cloning module is configured to, if it is necessary to reuse the disk data of the original virtual machine instance and the disk of the original virtual machine instance supports a storage cloning function, shut down the original virtual machine instance and trigger a storage cloning process of the disk through a virtual machine clone resource to generate a target virtual machine;

[0026] A second cloning module is configured to parse configuration parameters of the original virtual machine instance and create a new virtual machine instance based on the configuration parameters if the disk data of the original virtual machine instance does not need to be reused;

[0027] Resource creation module, used to asynchronously create target dependent resources and asynchronously calculate the target network address;

[0028] The monitoring configuration module is used to monitor the cloning status of the target virtual machine and implement corresponding network configuration based on the target network address after monitoring the completion of cloning or after creating the new virtual machine instance.

[0029] In a third aspect, the present application discloses an electronic device, comprising:

[0030] Memory, used to store computer programs;

[0031] The processor is configured to execute the computer program to implement the aforementioned disclosed virtual machine cloning method.

[0032] In a fourth aspect, the present application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the aforementioned disclosed virtual machine cloning method is implemented.

[0033] It can be seen that the present application proposes a virtual machine cloning method, including: judging whether it is necessary to reuse the disk data of the original virtual machine instance based on the cloning business needs; if it is necessary to reuse the disk data of the original virtual machine instance and the disk of the original virtual machine instance supports the storage cloning function, then shutting down the original virtual machine instance and triggering the storage cloning process of the disk through the virtual machine cloning resource to generate a target virtual machine; if it is not necessary to reuse the disk data of the original virtual machine instance, then parsing the configuration parameters of the original virtual machine instance and creating a new virtual machine instance based on the configuration parameters; asynchronously creating target dependent resources and asynchronously calculating the target network address; monitoring the cloning status of the target virtual machine, and implementing the corresponding network configuration based on the target network address after monitoring that the cloning is completed or after creating the new virtual machine instance. In summary, it can be seen that the present application first judges whether to reuse the original virtual machine disk data based on the business needs. If it is necessary to reuse and the disk supports storage cloning, then shutting down the original virtual machine and triggering the disk storage cloning to generate the target virtual machine. If it is not necessary to reuse, then parsing the original virtual machine configuration parameters to create a new instance, while asynchronously creating dependent resources and dynamically calculating the network address; finally, after the cloning or creation is completed, adding network configuration to the virtual machine. Specifically, this application distinguishes between storage cloning mode and parameter cloning mode by determining whether to reuse the original virtual machine disk data, avoiding the waste of storage resources in traditional full cloning scenarios where only parameter configuration is required, thereby improving cloning efficiency. Furthermore, this application resolves the network address conflict issue caused by static configuration by asynchronously calculating the target network address and implementing the corresponding network configuration based on the target network address, reducing manual intervention and improving network configuration efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0035] Figure 1 This is a flow chart of a virtual machine cloning method disclosed in this application;

[0036] Figure 2 This is a flowchart of a specific virtual machine cloning method disclosed in this application;

[0037] Figure 3 This is a schematic diagram of the structure of a virtual machine cloning device disclosed in this application;

[0038] Figure 4 This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION

[0039] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.

[0040] Kubernetes and KubeVirt (the Kubernetes virtualization component) form a powerful platform that supports modern containerized applications while also being compatible with traditional virtual machines (VMs). Its virtual machine cloning feature significantly improves the efficiency and flexibility of IT (Information Technology) operations and maintenance, providing significant convenience for both individual users and enterprise applications, helping to reduce costs and risks. However, the KubeVirt component's VirtualMachineClone Custom Resource Definition (CRD) has the following limitations: (1) It only supports full cloning mode, which wastes storage resources when cloning only requires retaining configuration parameters; (2) It does not support dynamic address pool management, requiring manual intervention and adjustments, which increases cloning time.

[0041] To this end, an embodiment of the present application proposes a virtual machine cloning solution to avoid the waste of storage resources in traditional full cloning scenarios where only parameter configuration is required, and to solve the network address conflict problem caused by static configuration.

[0042] The present application discloses a method for cloning a virtual machine. Figure 1 As shown, the method includes:

[0043] Step S11: Determine whether the disk data of the original virtual machine instance needs to be reused based on the cloning service requirements.

[0044] In this embodiment, the need to reuse the disk data of the original virtual machine instance (VMI) is determined based on cloning business needs. For example, in a disaster recovery backup scenario, the production system needs to fully replicate the virtual machine's disk data to ensure data consistency between the disaster recovery node and the source node. In this case, the "disk data reuse" mode is determined, triggering the storage cloning process to preserve complete business data. In a test environment setup scenario, only the original virtual machine's CPU (Central Processing Unit), memory, network policy, and other configuration parameters need to be reused. In this case, the "disk data reuse" mode is determined, and a lightweight instance is created directly based on these parameters. In this way, by dynamically distinguishing between storage cloning mode (which relies on disk storage cloning and is suitable for data-sensitive scenarios) and parameter cloning mode (which only inherits configuration parameters and is suitable for rapid deployment scenarios), it can avoid the waste of storage resources in traditional full cloning scenarios where only configuration parameters are required, thereby improving cloning efficiency.

[0045] Step S12: If the disk data of the original virtual machine instance needs to be reused and the disk of the original virtual machine instance supports the storage cloning function, the original virtual machine instance is shut down, and the storage cloning process of the disk is triggered through the virtual machine clone resource to generate the target virtual machine.

[0046] In this embodiment, if the disk data of the original virtual machine instance needs to be reused and the disk of the original virtual machine instance supports the storage cloning function, the original virtual machine instance is shut down, and the storage cloning process of the disk is triggered through the virtual machine clone resource to generate the target virtual machine.

[0047] Specifically, the disk persistent volume claim name is extracted from the original virtual machine instance, and the field value of the storage provisioner is obtained based on the disk persistent volume claim name. If the field value of the storage provisioner contains an identifier indicating support for storage cloning, the disks of the original virtual machine instance are determined to support storage cloning. In other words, the method for determining whether all disks of the original virtual machine instance support storage cloning is to extract the disk persistent volume claim (PVC) name from the original virtual machine instance, and based on this name, extract the storage class name (storage ClassName, such as "iec-storage-bi-7293190196844240896"), then query the configuration of the storage class to determine whether its "provisioner" field value (such as "driver.support.clone.io") contains an identifier indicating support for cloning. If so, the disks of the original virtual machine instance are determined to support storage cloning.

[0048] Furthermore, shutting down the original virtual machine instance is to avoid data inconsistency before and after cloning caused by cloning a running virtual machine, ensure the consistency and integrity of the disk data at the time of cloning, and prevent data conflicts caused by incomplete disk read and write operations or the inability of the virtual machine to start normally after cloning.

[0049] Furthermore, the VM clone resource triggers the disk storage cloning process to generate the target VM. This involves using the VM clone custom resource (CRD) or related API (Application Programming Interface) provided by KubeVirt to send a clone instruction to the storage system, which then performs a fast disk copy operation based on a storage driver that supports cloning (such as driver.support.clone.io, as identified by the provisioner field). This operation achieves efficient disk data reuse through storage-layer native cloning mechanisms (such as snapshot cloning and block device cloning), significantly reducing cloning time and computing resource consumption. The resulting target VM inherits the disk data of the original VM and runs as an independent instance in the Kubernetes cluster.

[0050] Step S13: If the disk data of the original virtual machine instance does not need to be reused, the configuration parameters of the original virtual machine instance are parsed, and a new virtual machine instance is created based on the configuration parameters.

[0051] In this embodiment, if the disk data of the original virtual machine instance does not need to be reused, the configuration parameters of the original virtual machine instance are parsed and a new virtual machine instance is created based on the configuration parameters. Configuration parameters include, for example, CPU, memory, disk, virtual machine image, network configuration, scheduling mode, login password / key, etc.

[0052] Step S14: asynchronously create target dependent resources and asynchronously calculate the target network address.

[0053] In this embodiment, target dependent resources are asynchronously created, including: asynchronously creating a network security group (kubeovn.io / v1.SecurityGroup), key login credentials (Kubernetes Secrets) and a migration scheduling policy (migrations.kubevirt.io. MigrationPolicy); the network security group is used to define the inbound and outbound rules of the virtual machine, the key login credentials are used to store the access information of the virtual machine, and the migration scheduling policy is used to configure the migration rules of the virtual machine between computing nodes.

[0054] The code implementation is as follows:

[0055] Security group bound to the cloned VM

[0056] apiVersion: kubeovn.io / v1

[0057] kind: SecurityGroup

[0058] metadata:

[0059] annotations: {…}

[0060] name: vm-yzkhr0mf

[0061] spec:

[0062] egressRules:

[0063] -ipVersion: ipv4

[0064] policy: allow

[0065] priority: 200

[0066] protocol: all

[0067] remoteAddress: 0.0.0.0 / 0

[0068] remoteType: address

[0069] ingressRules:

[0070] -ipVersion: ipv4

[0071] policy: allow

[0072] priority: 1

[0073] protocol: icmp

[0074] remoteAddress: 0.0.0.0 / 0

[0075] remoteType: address

[0076] -ipVersion: ipv4

[0077] policy: allow

[0078] portRangeMax: 65535

[0079] portRangeMin: 1

[0080] priority: 2

[0081] protocol: tcp

[0082] remoteAddress: 0.0.0.0 / 0

[0083] remoteType: address

[0084] -ipVersion: ipv4

[0085] policy: allow

[0086] portRangeMax: 65535

[0087] portRangeMin: 1

[0088] priority: 3

[0089] protocol: udp

[0090] remoteAddress: 0.0.0.0 / 0

[0091] remoteType: address

[0092] ---

[0093] #Secret resource for the storage login method bound to the cloned virtual machine

[0094] ---

[0095] apiVersion: v1

[0096] data:

[0097] root: bWxnWVFURjkzOTc2Mi4tKA==

[0098] kind: Secret

[0099] metadata:

[0100] name: vm-password-vm-yzkhr0mf

[0101] namespace: cnp-system

[0102] type: Opaque

[0103] ---

[0104] Migration policy resources bound to the cloned virtual machine

[0105] ---

[0106] apiVersion: migrations.kubevirt.io / v1alpha1

[0107] kind: MigrationPolicy

[0108] metadata:

[0109] name: vm-yzkhr0mf

[0110] spec:

[0111] selectors:

[0112] virtualMachineInstanceSelector:

[0113] kubevirt.io / vm: vm-yzkhr0mf.

[0114] The logic of the above code: By defining three types of resources, KubeOVN security group (SecurityGroup), Kubernetes Secret and KubeVirt migration policy (MigrationPolicy), the technical solution of asynchronously creating target dependent resources in step S14 is implemented. Specifically: Security group configuration: define a security group named vm-yzkhr0mf through kubeovn.io / v1API, configure inbound rules (ingressRules) to allow ICMP protocol, TCP / UDP full port access, and outbound rules (egressRules) to allow all IPv4 addresses to communicate, ensuring network connectivity and access control of cloned virtual machines, corresponding to the description of "Network Security Group is used to define inbound / outbound rules" in the previous article; key credential management: through v1 The API creates an Opaque Secret resource vm-password-vm-yzkhr0mf, which stores the virtual machine login password (for example, root:bWxnWVFURjkzOTc2Mi4tKA==) in Base64 encoding. This implements secure storage and reuse of access information, corresponding to the logic of "storing access information using key login credentials" mentioned earlier. Migration policy binding: Define the migration policy vm-yzkhr0mf through the migrations.kubevirt.io / v1alpha1 API, associate it with the target virtual machine instance through the label selector kubevirt.io / vm:vm-yzkhr0mf, and configure cross-node migration rules for the cloned virtual machine. This corresponds to the function of "configuring migration rules between computing nodes through the migration scheduling policy" mentioned earlier.

[0115] The target network address includes an Internet Protocol Address (IP address) and a Media Access Control Address (MAC address).

[0116] Step S15: monitoring the cloning status of the target virtual machine, and implementing corresponding network configuration based on the target network address after monitoring the completion of cloning or after creating the new virtual machine instance.

[0117] After detecting that the cloning is complete or after creating a new virtual machine instance, implement corresponding network configuration based on the target network address, including: after detecting that the cloning is complete or after creating a new virtual machine instance, add the Internet Protocol address label kubeovn.io / ip_address and the media access control address annotation kubeovn.io / mac_address to the target virtual machine or the new virtual machine instance.

[0118] The code implementation is as follows:

[0119] apiVersion: kubevirt.io / v1

[0120] kind: VirtualMachine

[0121] metadata:

[0122] annotations:

[0123] kubeovn.io / ip_address: 192.168.0.8 / / ip address label

[0124] kubeovn.io / mac_address: fa:16:72:5b:e3:80 / / mac address label

[0125] finalizers: {…}

[0126] labels: {…}

[0127] name: vm-yzkhr0mf

[0128] namespace: default

[0129] spec:

[0130] running: true

[0131] [[ID=Z8]]template:

[0132] metadata:

[0133] annotations:

[0134] kubeovn.io / ip_address: 192.168.0.8

[0135] kubeovn.io / mac_address: fa:16:72:5b:e3:80

[0136] creationTimestamp: null

[0137] labels: {…}

[0138] spec:

[0139] accessCredentials: []

[0140] Note: There seems to be a duplicate "template" related part in the original text. I've tried to keep it as is while making a minor adjustment in the translation numbering for clarity. If this is incorrect, please provide more context or clarify the issue.architecture: amd64

[0141] domain:

[0142] cpu: {…}

[0143] devices: {…}

[0144] machine: {…}

[0145] memory: {…}

[0146] resources: {…}

[0147] hostname: vm-yzkhr0mf

[0148] networks: {…}

[0149] nodeSelector: {…}

[0150] volumes: {…}.

[0151] The logic behind the above code is to inject the target network address (Internet Protocol address and Media Access Control address) into the VM configuration by adding the kubeovn.io / ip_address label and kubeovn.io / mac_address annotation to the VirtualMachine resource's metadata and template. Following the aforementioned description of "monitoring the target VM's cloning status and implementing the appropriate network configuration based on the target network address after cloning is complete or a new instance is created," the code uses a two-level annotation layer (the upper resource layer and the template layer) to ensure that the VM configuration and the actual running VM instance (VMI) inherit the same IP / MAC address labels. This resolves the network address conflicts caused by traditional static configuration, automates dynamic network configuration, reduces manual intervention, and improves network configuration efficiency.

[0152] In this embodiment, during the steps of triggering the disk storage cloning process, parsing the configuration parameters of the original virtual machine instance, asynchronously creating target dependent resources, asynchronously calculating the target network address, or implementing the corresponding network configuration based on the target network address, if any step meets a preset failure condition, all created resources are rolled back. Specifically, if any step meets the preset failure condition, all created resources are rolled back, including: if any step fails and the number of re-executions of the step reaches a preset threshold, all created resources are rolled back. Operational non-atomicity: The cloning process involves the coordinated creation of multiple resources and lacks a transactional guarantee mechanism, which can easily result in resource residue upon failure. Thus, by providing a failure rollback mechanism, the atomicity of the coordinated creation of multiple resources during the cloning process is ensured. If a step fails and the number of retries exceeds the limit, the system automatically rolls back all created resources (such as virtual machine instances, storage volumes, network security groups, etc.). This avoids resource residue issues caused by operational non-atomicity, ensures the consistency and cleanliness of cluster resource states, and reduces operational complexity and potential failure risks caused by the failure to create some resources.

[0153] See also Figure 2 As shown, the process first determines whether to preserve the data. If not, it enters the parameter parser, parsing parameters such as specifications, storage, network, and login configuration. If data preservation is desired, it then determines whether disk cloning is supported. If supported, it calculates the network address and creates a virtual machine clone (VM clone). It then clones the target VM, concurrently creating security groups, login keys, and migration policies. If cloning succeeds, it then performs a network configuration patch on the target VM. If cloning fails, it determines whether the retry threshold has been reached. If not, the creation / cloning operation is retried. If it has been reached, the creation / cloning operation is rolled back, deleting the created security groups, login keys, migration policies, and other resources. If the target VM is created directly without preserving data, the process terminates if the creation succeeds. If it fails, it also determines whether the retry threshold has been reached and handles the situation accordingly. This process, through distinct branching logic, enables orderly management of VM cloning and related resource creation, configuration, and rollback operations.

[0154] In summary, the present application constructs a three-tiered architecture system including a dual-mode cloning engine, an intelligent parameter parser, and a dynamic resource orchestrator. The dual-mode cloning engine can distinguish between storage cloning mode and parameter cloning mode based on cloning business requirements, triggering the storage cloning process when the original virtual machine instance disk data needs to be reused, and only parsing the configuration parameters to create a new instance when reuse is not required, thereby reducing unnecessary disk cloning time and improving virtual machine cloning efficiency and resource utilization; the intelligent parameter parser is used to parse the configuration parameters of the original virtual machine instance to provide support for the parameter cloning mode; the dynamic resource orchestrator introduces a transaction mechanism. When any step in the cloning process meets the preset failure condition and the number of re-executions reaches the preset threshold, all created resources are rolled back to avoid potential resource leakage problems when cloning fails. At the same time, by asynchronously calculating the target network address and adding corresponding network configuration tags and annotations to the virtual machine after cloning is completed, the network configuration is pre-processed to avoid manual intervention operations, significantly reducing the probability of network conflicts.

[0155] It can be seen that the present application proposes a virtual machine cloning method, including: judging whether it is necessary to reuse the disk data of the original virtual machine instance based on the cloning business needs; if it is necessary to reuse the disk data of the original virtual machine instance and the disk of the original virtual machine instance supports the storage cloning function, then shutting down the original virtual machine instance and triggering the storage cloning process of the disk through the virtual machine cloning resource to generate a target virtual machine; if it is not necessary to reuse the disk data of the original virtual machine instance, then parsing the configuration parameters of the original virtual machine instance and creating a new virtual machine instance based on the configuration parameters; asynchronously creating target dependent resources and asynchronously calculating the target network address; monitoring the cloning status of the target virtual machine, and implementing the corresponding network configuration based on the target network address after monitoring that the cloning is completed or after creating the new virtual machine instance. In summary, it can be seen that the present application first judges whether to reuse the original virtual machine disk data based on the business needs. If it is necessary to reuse and the disk supports storage cloning, then shutting down the original virtual machine and triggering the disk storage cloning to generate the target virtual machine. If it is not necessary to reuse, then parsing the original virtual machine configuration parameters to create a new instance, while asynchronously creating dependent resources and dynamically calculating the network address; finally, after the cloning or creation is completed, adding network configuration to the virtual machine. Specifically, this application distinguishes between storage cloning mode and parameter cloning mode by determining whether to reuse the original virtual machine disk data, avoiding the waste of storage resources in traditional full cloning scenarios where only parameter configuration is required, thereby improving cloning efficiency. Furthermore, this application resolves the network address conflict issue caused by static configuration by asynchronously calculating the target network address and implementing the corresponding network configuration based on the target network address, reducing manual intervention and improving network configuration efficiency.

[0156] Correspondingly, the embodiment of the present application also discloses a virtual machine cloning device, see Figure 3 As shown, the device includes:

[0157] A judgment module 11 is used to judge whether the disk data of the original virtual machine instance needs to be reused based on the cloning business requirements;

[0158] The first cloning module 12 is configured to, if it is necessary to reuse the disk data of the original virtual machine instance and the disk of the original virtual machine instance supports the storage cloning function, shut down the original virtual machine instance and trigger the storage cloning process of the disk through the virtual machine clone resource to generate a target virtual machine;

[0159] The second cloning module 13 is configured to parse the configuration parameters of the original virtual machine instance and create a new virtual machine instance based on the configuration parameters if the disk data of the original virtual machine instance does not need to be reused;

[0160] Resource creation module 14, used for asynchronously creating target dependent resources and asynchronously calculating target network addresses;

[0161] The monitoring configuration module 15 is used to monitor the cloning status of the target virtual machine, and implement corresponding network configuration based on the target network address after monitoring the completion of cloning or after creating the new virtual machine instance.

[0162] Among them, for more specific working processes of the above modules, please refer to the corresponding contents disclosed in the aforementioned embodiments, which will not be repeated here.

[0163] It can be seen that the present application proposes a virtual machine cloning method, including: judging whether it is necessary to reuse the disk data of the original virtual machine instance based on the cloning business needs; if it is necessary to reuse the disk data of the original virtual machine instance and the disk of the original virtual machine instance supports the storage cloning function, then shutting down the original virtual machine instance and triggering the storage cloning process of the disk through the virtual machine cloning resource to generate a target virtual machine; if it is not necessary to reuse the disk data of the original virtual machine instance, then parsing the configuration parameters of the original virtual machine instance and creating a new virtual machine instance based on the configuration parameters; asynchronously creating target dependent resources and asynchronously calculating the target network address; monitoring the cloning status of the target virtual machine, and implementing the corresponding network configuration based on the target network address after monitoring that the cloning is completed or after creating the new virtual machine instance. In summary, it can be seen that the present application first judges whether to reuse the original virtual machine disk data based on the business needs. If it is necessary to reuse and the disk supports storage cloning, then shutting down the original virtual machine and triggering the disk storage cloning to generate the target virtual machine. If it is not necessary to reuse, then parsing the original virtual machine configuration parameters to create a new instance, while asynchronously creating dependent resources and dynamically calculating the network address; finally, after the cloning or creation is completed, adding network configuration to the virtual machine. Specifically, this application distinguishes between storage cloning mode and parameter cloning mode by determining whether to reuse the original virtual machine disk data, avoiding the waste of storage resources in traditional full cloning scenarios where only parameter configuration is required, thereby improving cloning efficiency. Furthermore, this application resolves the network address conflict issue caused by static configuration by asynchronously calculating the target network address and implementing the corresponding network configuration based on the target network address, reducing manual intervention and improving network configuration efficiency.

[0164] Furthermore, an embodiment of the present application also provides an electronic device. Figure 4 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content in the diagram should not be considered as any limitation to the scope of application of the present application.

[0165] Figure 4 This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a display 23, an input / output interface 24, a communication interface 25, a power supply 26, and a communication bus 27. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps of the virtual machine cloning method disclosed in any of the aforementioned embodiments. Furthermore, the electronic device 20 in this embodiment may specifically be an electronic computer.

[0166] In this embodiment, the power supply 26 is used to provide operating voltage for each hardware device on the electronic device 20; the communication interface 25 can create a data transmission channel between the electronic device 20 and the external device. The communication protocol it follows is any communication protocol that can be applied to the technical solution of this application and is not specifically limited here; the input and output interface 24 is used to obtain external input data or output data to the outside world. Its specific interface type can be selected according to specific application needs and is not specifically limited here.

[0167] In addition, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, a magnetic disk, or an optical disk, etc. The resources stored thereon can include a computer program 221, which can be stored in a temporary or permanent manner. In addition to including a computer program capable of performing the virtual machine cloning method performed by the electronic device 20 as disclosed in any of the aforementioned embodiments, the computer program 221 can further include a computer program capable of performing other specific tasks.

[0168] Furthermore, an embodiment of the present application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the aforementioned virtual machine cloning method is implemented.

[0169] For the specific steps of this method, please refer to the corresponding contents disclosed in the aforementioned embodiments, which will not be repeated here.

[0170] The various embodiments in this application are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other. For the devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple, and the relevant parts can be referred to the method part.

[0171] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0172] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0173] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.

[0174] The above is a detailed introduction to the virtual machine cloning method, device, equipment, and storage medium provided by the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core ideas of the present application. At the same time, for those skilled in the art, based on the ideas of the present application, there may be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting the present application.

Claims

1. A virtual machine cloning method, characterized in that: include: Determine whether to reuse the disk data of the original virtual machine instance based on the cloning business needs; If the disk data of the original virtual machine instance needs to be reused and the disk of the original virtual machine instance supports the storage cloning function, the original virtual machine instance is shut down, and the storage cloning process of the disk is triggered through the virtual machine clone resource to generate the target virtual machine; If the disk data of the original virtual machine instance does not need to be reused, parsing the configuration parameters of the original virtual machine instance and creating a new virtual machine instance based on the configuration parameters; Asynchronously create target dependent resources and asynchronously calculate the target network address; The cloning status of the target virtual machine is monitored, and corresponding network configuration is implemented based on the target network address after monitoring that the cloning is completed or after the new virtual machine instance is created.

2. The virtual machine cloning method according to claim 1, characterized in that: Also includes: Extract the disk persistent volume claim name from the original virtual machine instance; Get the field value of the storage configurator according to the disk persistent volume declaration name; If the field value of the storage configurator includes an identification value indicating support for the storage cloning function, it is determined that the disk of the original virtual machine instance supports the storage cloning function.

3. The virtual machine cloning method according to claim 1, wherein: The asynchronous creation of target dependent resources includes: Asynchronously create a network security group, key login credentials and migration scheduling policy; the network security group is used to define the inbound and outbound rules of the virtual machine, the key login credentials are used to store the access information of the virtual machine, and the migration scheduling policy is used to configure the migration rules of the virtual machine between computing nodes.

4. The virtual machine cloning method according to claim 1, wherein: Also includes: In the steps of triggering the storage cloning process of the disk, parsing the configuration parameters of the original virtual machine instance, asynchronously creating the target dependent resources, asynchronously calculating the target network address, or implementing the corresponding network configuration based on the target network address, if any step meets the preset failure condition, all created resources are rolled back.

5. The virtual machine cloning method according to claim 4, characterized in that: If any step meets the preset failure condition, all created resources will be rolled back, including: If any step fails and the number of re-executions of the step reaches a preset threshold, all created resources will be rolled back.

6. The virtual machine cloning method according to any one of claims 1 to 5, characterized in that: The target network address includes an Internet Protocol address and a Media Access Control address.

7. The virtual machine cloning method according to claim 6, characterized in that: The implementing corresponding network configuration based on the target network address after monitoring completion of cloning or after creating the new virtual machine instance includes: After monitoring that the cloning is completed or after creating the new virtual machine instance, a label of the Internet Protocol address and an annotation of the media access control address are added to the target virtual machine or the new virtual machine instance.

8. A virtual machine cloning device, characterized in that: include: A judgment module is used to determine whether the disk data of the original virtual machine instance needs to be reused based on the cloning business requirements; A first cloning module is configured to, if it is necessary to reuse the disk data of the original virtual machine instance and the disk of the original virtual machine instance supports a storage cloning function, shut down the original virtual machine instance and trigger a storage cloning process of the disk through a virtual machine clone resource to generate a target virtual machine; A second cloning module is configured to parse configuration parameters of the original virtual machine instance and create a new virtual machine instance based on the configuration parameters if the disk data of the original virtual machine instance does not need to be reused; Resource creation module, used to asynchronously create target dependent resources and asynchronously calculate the target network address; The monitoring configuration module is used to monitor the cloning status of the target virtual machine, and implement corresponding network configuration based on the target network address after monitoring the completion of cloning or after creating the new virtual machine instance.

9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the virtual machine cloning method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that Used to store a computer program; wherein, when the computer program is executed by a processor, the virtual machine cloning method according to any one of claims 1 to 7 is implemented.