A method, device, equipment and medium for uploading a file to a virtual machine
Patent Information
- Application Number
- CN202311327078.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-13
- Publication Date
- 2026-09-22
- Estimated Expiration
- 2043-10-13
AI Technical Summary
目前来说,大多是通过给虚拟机配置网络后,通过视窗操作系统远程桌面或者xftp(一种文件传输工具)等来传输文件,这种方法的缺点是:文件传输的稳定性与网络的稳定性密切相关,如果网络不稳定则会影响文件传输,并且通过给虚拟机配置网络的方法存在一定的不安全性;另一种方法是提供一个共享文件夹,将相关文件通过网络协议上传到共享文件夹中,以供虚拟机内部访问和使用,但由于安全性问题,目前这种方式使用较少
[0036]可见,本申请提出一种将文件上传至虚拟机的方法,包括:获取虚拟化管理平台在接收到用户上传的目标文件后创建的虚拟磁盘;接收所述虚拟化管理平台发送的用于表明目标虚拟机的操作系统类型的目标参数,并根据所述目标参数对所述虚拟磁盘进行格式转换,得到目标虚拟磁盘;将所述目标虚拟磁盘虚拟为目标块设备,并将所述目标块设备挂载至与所述目标虚拟机对应的目标临时目录;在所述虚拟化管理平台将所述目标文件传输至所述目标临时目录后,将当前所述目标块设备挂载至所述目标虚拟机。综上可见,本申请中的虚拟化管理平台在接收到用户上传的目标文件后自动创建虚拟磁盘,然后,本申请根据目标虚拟机的操作系统类型对所述虚拟磁盘进行格式转换,以使转换后的目标虚拟机能够被相应的操作系统所识别,进一步的,本申请将目标虚拟机虚拟为目标块设备,并将所述目标块设备挂载至与所述目标虚拟机对应的目标目录,最后,在所述虚拟化管理平台将所述目标文件传输至所述目标临时目录后,将当前的目标块设备挂载至所述目标虚拟机,以实现将所述目标文件上传至所述目标虚拟机,可见,本申请无需提前为虚拟机配置好网络,也无需对虚拟机进行重启,提高了文件传输的稳定性和安全性,保证了用户业务连续不中断,减少了运维人员的运维压力。
Smart Images

Figure CN117376341B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method, apparatus, device, and medium for uploading files to a virtual machine. Background Technology
[0002] Virtualization refers to the process of using virtualization technology to transform a single physical server (physical machine) into multiple logical servers (virtual machines). This allows users to run multiple virtual machines simultaneously on a single physical machine, each running a different operating system without interfering with the others. This significantly improves work efficiency and saves computing resources. Examples of virtualization technologies include KVM (Kernel-based virtual machine) and VMware (Virtual Machine software).
[0003] Users often need to transfer files from their local computer to the virtual machine when using virtualization management platforms. Currently, this is mostly done by configuring a network for the virtual machine and then transferring files via Windows operating system remote desktop or XFTP (a file transfer tool). The drawbacks of this method are that the stability of file transfer is closely related to network stability; an unstable network will affect file transfer, and configuring a network for the virtual machine also introduces certain security risks. Another method is to provide a shared folder, uploading relevant files to the shared folder via network protocols for access and use within the virtual machine. However, due to security concerns, this method is less commonly used. Furthermore, traditional methods sometimes require shutting down and restarting the virtual machine, making online file transfer impossible.
[0004] Therefore, improving the stability and security of file transfer while enabling online transmission to ensure uninterrupted user services during file uploads to virtual machines is a pressing issue that needs to be addressed in this field. Summary of the Invention
[0005] In view of this, the purpose of this invention is to provide a method, apparatus, device, and medium for uploading files to a virtual machine, which can improve the stability and security of file transmission, and at the same time realize online transmission to ensure uninterrupted user services. The specific solution is as follows:
[0006] In a first aspect, this application discloses a method for uploading files to a virtual machine, including:
[0007] Obtain the virtual disk created by the virtualization management platform after receiving the target file uploaded by the user;
[0008] The system receives target parameters sent by the virtualization management platform, which indicate the operating system type of the target virtual machine, and performs format conversion on the virtual disk according to the target parameters to obtain the target virtual disk.
[0009] The target virtual disk is virtualized as a target block device, and the target block device is mounted to the target temporary directory corresponding to the target virtual machine;
[0010] After the virtualization management platform transfers the target file to the target temporary directory, the target block device is mounted to the target virtual machine.
[0011] Optionally, the step of obtaining the virtual disk created by the virtualization management platform after receiving the target file uploaded by the user includes:
[0012] After receiving the target file uploaded by the user, the virtualization management platform obtains the virtual disk created by calling the application programming interface and based on the target virtual machine disk management commands.
[0013] Optionally, the virtual disk may be formatted as either copy-on-write or raw.
[0014] Optionally, the target parameters include a first target parameter indicating that the operating system type of the target virtual machine is a Windows operating system and a second target parameter indicating that the operating system type of the target virtual machine is a Linux operating system.
[0015] Optionally, receiving the target parameters sent by the virtualization management platform to indicate the operating system type of the target virtual machine includes:
[0016] Receive the first target parameter sent by the virtualization management platform;
[0017] Accordingly, the step of converting the format of the virtual disk according to the target parameters to obtain the target virtual disk includes:
[0018] Based on the first target parameter, the virtual disk in the copy-on-write format is converted into the virtual disk in the new technology file system format to obtain the target virtual disk;
[0019] Alternatively, receiving the target parameters sent by the virtualization management platform to indicate the operating system type of the target virtual machine includes:
[0020] Receive the second target parameter sent by the virtualization management platform;
[0021] Accordingly, the step of converting the format of the virtual disk according to the target parameters to obtain the target virtual disk includes:
[0022] The virtual disk in the raw format is converted into the virtual disk in the fourth-generation extended file system format according to the second target parameter to obtain the target virtual disk.
[0023] Optionally, before mounting the target block device to the target temporary directory corresponding to the target virtual machine, the method further includes:
[0024] Obtain the target temporary directory created by the virtualization management platform based on the identity number of the target virtual machine.
[0025] Optionally, after the virtualization management platform transfers the target file to the target temporary directory, mounting the current target block device to the target virtual machine includes:
[0026] After the virtualization management platform transfers the target file to the target temporary directory, it calls the target virtualization management tool to mount the target block device to the target virtual machine.
[0027] Secondly, this application discloses an apparatus for uploading files to a virtual machine, comprising:
[0028] The virtual disk acquisition module is used to acquire the virtual disk created by the virtualization management platform after receiving the target file uploaded by the user;
[0029] The format conversion module is used to receive target parameters sent by the virtualization management platform, which indicate the operating system type of the target virtual machine, and to convert the format of the virtual disk according to the target parameters to obtain the target virtual disk;
[0030] The first mounting module is used to virtualize the target virtual disk as a target block device and mount the target block device to the target temporary directory corresponding to the target virtual machine;
[0031] The second mounting module is used to mount the target block device to the target virtual machine after the virtualization management platform transfers the target file to the target temporary directory.
[0032] Thirdly, this application discloses an electronic device, including:
[0033] Memory is used to store computer programs;
[0034] A processor is configured to execute the computer program to implement the aforementioned method for uploading files to a virtual machine.
[0035] Fourthly, this application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned method for uploading files to a virtual machine.
[0036] Therefore, this application proposes a method for uploading a file to a virtual machine, comprising: obtaining a virtual disk created by a virtualization management platform after receiving a target file uploaded by a user; receiving target parameters sent by the virtualization management platform to indicate the operating system type of the target virtual machine, and converting the format of the virtual disk according to the target parameters to obtain a target virtual disk; virtualizing the target virtual disk as a target block device, and mounting the target block device to a target temporary directory corresponding to the target virtual machine; and mounting the target block device to the target virtual machine after the virtualization management platform transfers the target file to the target temporary directory. In summary, the virtualization management platform in this application automatically creates a virtual disk after receiving the target file uploaded by the user. Then, this application converts the format of the virtual disk according to the operating system type of the target virtual machine so that the converted target virtual machine can be recognized by the corresponding operating system. Furthermore, this application virtualizes the target virtual machine as a target block device and mounts the target block device to the target directory corresponding to the target virtual machine. Finally, after the virtualization management platform transfers the target file to the target temporary directory, it mounts the current target block device to the target virtual machine to upload the target file to the target virtual machine. It can be seen that this application does not require pre-configuring the network for the virtual machine or restarting the virtual machine, which improves the stability and security of file transfer, ensures uninterrupted user services, and reduces the maintenance pressure on operation and maintenance personnel. Attached Figure Description
[0037] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0038] Figure 1 This application discloses a method for uploading files to a virtual machine.
[0039] Figure 2 This application discloses a specific method flowchart for uploading files to a virtual machine;
[0040] Figure 3 This is a flowchart illustrating another specific method for uploading files to a virtual machine as disclosed in this application;
[0041] Figure 4 This is a schematic diagram of a device structure for uploading files to a virtual machine, as disclosed in this application.
[0042] Figure 5 This is a structural diagram of an electronic device disclosed in this application. Detailed Implementation
[0043] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0044] There are two methods to transfer files from a local computer to a virtual machine. The first is to configure the virtual machine with a network and then transfer files via Windows Remote Desktop or XFTP. The drawback of this method is that the stability of file transfer is closely related to network stability; an unstable network will affect file transfer. Furthermore, configuring a network for the virtual machine introduces certain security risks. The second method is to provide a shared folder and upload relevant files to it via network protocols for access and use within the virtual machine. However, due to security concerns, this method is less commonly used. In addition, traditional methods sometimes require shutting down and restarting the virtual machine, making online file transfer impossible.
[0045] Furthermore, for the current mainstream hardware-assisted virtualization architecture, the CPU (Central Processing Unit / Processor) and memory devices are mainly simulated through the KVM kernel module, while IO (Input / Output) devices (such as network cards, disks, etc.) are simulated through QEMU (Quick EMUlator, virtual operating system emulator) technology. Based on this, QEMU-KVM technology (a server virtualization technology responsible for providing simulation of CPU, memory and various IO devices) has been formed, realizing server virtualization.
[0046] For each virtual machine, its physical manifestation is a QEMU-KVM process, and the virtual disks of the virtual machines can be managed through qemu-img (an open-source virtual machine disk management command that can manage the lifecycle of virtual disks). The upper-level virtualization management platform typically manages the underlying KVM virtual machines through an application programming interface (API), including operations related to virtual machine lifecycle management such as powering on / off, adding disks, and removing disks. Specifically, this is achieved through the virsh command (a virtualization management tool used to manage virtual machines and management programs in a virtualization environment). This is a user-space tool that runs entirely in command-line text mode, primarily used by administrators to automate virtualization deployment and management through scripts.
[0047] Based on the above principles, this application proposes a scheme for uploading files to a virtual machine, which can improve the stability and security of file transmission, and at the same time realize online transmission to ensure uninterrupted user services.
[0048] This application discloses a method for uploading files to a virtual machine; see [link to relevant documentation]. Figure 1 and Figure 2 As shown, the method includes:
[0049] Step S11: Obtain the virtual disk created by the virtualization management platform after receiving the target file uploaded by the user.
[0050] In this embodiment, the user logs into the virtualization management platform interface through a client, selects a file from their local computer, and uploads it to the corresponding window of the virtualization management platform. Specifically, after logging into the virtualization management platform interface, the user issues a file upload command. Upon receiving the file upload command, the virtualization management platform pops up an upload window, allowing the user to upload the target file to that window.
[0051] Furthermore, the virtualization management platform calls the Application Programming Interface (API) and creates a virtual disk at the underlying level based on the target virtual machine disk management command, namely the qemu-img command. The specific command is as follows:
[0052] qemu-img create-f qcow2 / raw disk_uuid 10G.
[0053] The virtual disk is formatted in two formats: copy-on-write (qcow2) and raw. The virtual disk is 10GB in size.
[0054] In this embodiment, the virtualization management platform obtains the virtual disk created by calling the application programming interface and based on the target virtual machine disk management command after receiving the target file uploaded by the user.
[0055] Step S12: Receive target parameters sent by the virtualization management platform to indicate the operating system type of the target virtual machine, and perform format conversion on the virtual disk according to the target parameters to obtain the target virtual disk.
[0056] In this embodiment, the virtualization management platform will synchronously transmit the operating system type of the target virtual machine as a target parameter to the underlying layer. The target parameter includes a first target parameter indicating that the operating system type of the target virtual machine is a Windows operating system and a second target parameter indicating that the operating system type of the target virtual machine is a Linux operating system.
[0057] In one specific implementation, the virtualization management platform sends the first target parameter; correspondingly, the step of converting the virtual disk format according to the target parameter to obtain the target virtual disk includes: converting the virtual disk under the copy-on-write format to the virtual disk under the new technology file system format (NTFS format) according to the first target parameter to obtain the target virtual disk. The specific command is: mkfs.ntfs disk_uuid.
[0058] In a second specific implementation, the second target parameter sent by the virtualization management platform is received; correspondingly, the step of converting the virtual disk format according to the target parameter to obtain the target virtual disk includes: converting the virtual disk in the raw format to the virtual disk in the fourth-generation extended file system format (ext4 file system) according to the second target parameter to obtain the target virtual disk. The specific command is: mkfs.ext4disk_uuid.
[0059] Step S13: Virtualize the target virtual disk as a target block device, and mount the target block device to the target temporary directory corresponding to the target virtual machine.
[0060] In the above embodiments, after formatting the virtual disk, a target virtual disk is obtained. In this embodiment, the target virtual disk is virtualized as a target block device so that it can be mounted on the target temporary directory in the form of a block device.
[0061] Step S14: After the virtualization management platform transfers the target file to the target temporary directory, the target block device is mounted to the target virtual machine.
[0062] It should be noted that the virtualization management platform first transfers the target file uploaded by the user to the temporary directory. Furthermore, in this embodiment, after the virtualization management platform transfers the target file to the target temporary directory, it mounts the target block device to the target virtual machine. In this way, the user can read the files inside the disk within the virtual machine.
[0063] Therefore, this application proposes a method for uploading a file to a virtual machine, comprising: obtaining a virtual disk created by a virtualization management platform after receiving a target file uploaded by a user; receiving target parameters sent by the virtualization management platform to indicate the operating system type of the target virtual machine, and converting the format of the virtual disk according to the target parameters to obtain a target virtual disk; virtualizing the target virtual disk as a target block device, and mounting the target block device to a target temporary directory corresponding to the target virtual machine; and mounting the target block device to the target virtual machine after the virtualization management platform transfers the target file to the target temporary directory. In summary, the virtualization management platform in this application automatically creates a virtual disk after receiving the target file uploaded by the user. Then, this application converts the format of the virtual disk according to the operating system type of the target virtual machine so that the converted target virtual machine can be recognized by the corresponding operating system. Furthermore, this application virtualizes the target virtual machine as a target block device and mounts the target block device to the target directory corresponding to the target virtual machine. Finally, after the virtualization management platform transfers the target file to the target temporary directory, it mounts the current target block device to the target virtual machine to upload the target file to the target virtual machine. It can be seen that this application does not require pre-configuring the network for the virtual machine or restarting the virtual machine, which improves the stability and security of file transfer, ensures uninterrupted user services, and reduces the maintenance pressure on operation and maintenance personnel.
[0064] This application discloses a specific method for uploading files to a virtual machine. Compared to the previous embodiment, this embodiment further explains and optimizes the technical solution. See also... Figure 3 As shown, it specifically includes:
[0065] Step S21: Obtain the virtual disk created by the virtualization management platform after receiving the target file uploaded by the user.
[0066] Step S22: Receive target parameters sent by the virtualization management platform to indicate the operating system type of the target virtual machine, and perform format conversion on the virtual disk according to the target parameters to obtain the target virtual disk.
[0067] For more detailed procedures regarding steps S21 and S22, please refer to the aforementioned disclosed embodiments, which will not be elaborated upon here.
[0068] Step S23: Obtain the target temporary directory created by the virtualization management platform based on the identity number of the target virtual machine.
[0069] In this embodiment, the virtualization management platform creates a target temporary directory at the underlying level based on the virtual machine's identity document (ID), such as / tmp / virtual machine id, i.e.: mkdir / tmp / virtual machine uuid.
[0070] Step S24: Virtualize the target virtual disk as a target block device, and mount the target block device to the target temporary directory corresponding to the target virtual machine.
[0071] Furthermore, the target virtual disk is virtualized into a target block device, and the target block device is mounted to the target temporary directory, i.e., mount -o loop disk_uuid / tmp / virtual machine id.
[0072] Step S25: After the virtualization management platform transfers the target file to the target temporary directory, the target block device is mounted to the target virtual machine by calling the target virtualization management tool.
[0073] In this embodiment, the virtualization management platform transfers the target file uploaded by the user to the / tmp / virtual machine id directory on the physical machine. Furthermore, this embodiment adds the current block device to the target virtual machine online by calling the target virtualization management tool (virsh attach-disk).
[0074] In this way, users can see the target virtual disk as a vdx or sdx drive letter when they open the virtual machine console, without needing to format it. Furthermore, for Linux operating systems, the target virtual disk needs to be mounted to the appropriate directory using the `mount` command (used to mount files outside the Linux operating system), allowing access to the target files previously uploaded by the user on the virtualization management platform. For example, `mount / dev / vdb / mnt` will locate the target file under ` / mnt`.
[0075] This application proposes an optimized method for uploading target files from a virtualization management platform to a target virtual machine. Users access the virtualization management platform and perform related operations. The platform automatically calls the application programming interface to create a temporary virtual disk at the underlying level. After formatting the disk according to the virtual machine's operating system type, it is mounted as a regular block device to a temporary directory. Files uploaded by the user on the virtualization management platform are transferred to this temporary directory. Finally, the target virtualization management tool mounts the virtual disk online to the virtual machine, allowing the user to see the files within the virtual disk within the operating system. Furthermore, the disk files can be automatically removed and deleted after use. Therefore, this method provides a convenient and quick way for users to upload files from their local computer to the virtual machine without needing to configure the network for the virtual machine beforehand. It can be used during the debugging phase immediately after operating system installation, and the process does not require a virtual machine restart, minimizing the need for extensive operations within the operating system, thus reducing the operational burden and costs for maintenance personnel.
[0076] As can be seen, this application proposes a method for uploading a file to a virtual machine, comprising: obtaining a virtual disk created by a virtualization management platform after receiving a target file uploaded by a user; receiving target parameters sent by the virtualization management platform to indicate the operating system type of the target virtual machine, and converting the format of the virtual disk according to the target parameters to obtain a target virtual disk; obtaining a target temporary directory created by the virtualization management platform according to the identity number of the target virtual machine; virtualizing the target virtual disk as a target block device, and mounting the target block device to the target temporary directory corresponding to the target virtual machine; after the virtualization management platform transfers the target file to the target temporary directory, mounting the current target block device to the target virtual machine by calling a target virtualization management tool. In summary, the virtualization management platform in this application automatically creates a virtual disk after receiving the target file uploaded by the user. Then, this application converts the format of the virtual disk according to the operating system type of the target virtual machine so that the converted target virtual machine can be recognized by the corresponding operating system. Furthermore, this application virtualizes the target virtual machine as a target block device and mounts the target block device to the target directory corresponding to the target virtual machine. Finally, after the virtualization management platform transfers the target file to the target temporary directory, it mounts the current target block device to the target virtual machine to upload the target file to the target virtual machine. It can be seen that this application does not require pre-configuring the network for the virtual machine or restarting the virtual machine, which improves the stability and security of file transfer, ensures uninterrupted user services, and reduces the maintenance pressure on operation and maintenance personnel.
[0077] Accordingly, this application also discloses a device for uploading files to a virtual machine, see [link to relevant documentation]. Figure 4 As shown, the device includes:
[0078] Virtual disk acquisition module 11 is used to acquire the virtual disk created by the virtualization management platform after receiving the target file uploaded by the user;
[0079] The format conversion module 12 is used to receive target parameters sent by the virtualization management platform to indicate the operating system type of the target virtual machine, and to convert the format of the virtual disk according to the target parameters to obtain the target virtual disk;
[0080] The first mounting module 13 is used to virtualize the target virtual disk as a target block device and mount the target block device to the target temporary directory corresponding to the target virtual machine;
[0081] The second mounting module 14 is used to mount the target block device to the target virtual machine after the virtualization management platform transmits the target file to the target temporary directory.
[0082] For more detailed information on the working process of each of the above modules, please refer to the relevant content disclosed in the foregoing embodiments, which will not be repeated here.
[0083] As can be seen, this application proposes an apparatus for uploading files to a virtual machine, comprising: a virtual disk acquisition module 11, used to acquire a virtual disk created by a virtualization management platform after receiving a target file uploaded by a user; a format conversion module 12, used to receive target parameters sent by the virtualization management platform indicating the operating system type of the target virtual machine, and to convert the format of the virtual disk according to the target parameters to obtain a target virtual disk; a first mounting module 13, used to virtualize the target virtual disk as a target block device and mount the target block device to a target temporary directory corresponding to the target virtual machine; and a second mounting module 14, used to mount the target block device to the target virtual machine after the virtualization management platform transmits the target file to the target temporary directory. In summary, the virtualization management platform in this application automatically creates a virtual disk after receiving the target file uploaded by the user. Then, this application converts the format of the virtual disk according to the operating system type of the target virtual machine so that the converted target virtual machine can be recognized by the corresponding operating system. Furthermore, this application virtualizes the target virtual machine as a target block device and mounts the target block device to the target directory corresponding to the target virtual machine. Finally, after the virtualization management platform transfers the target file to the target temporary directory, it mounts the current target block device to the target virtual machine to upload the target file to the target virtual machine. It can be seen that this application does not require pre-configuring the network for the virtual machine or restarting the virtual machine, which improves the stability and security of file transfer, ensures uninterrupted user services, and reduces the maintenance pressure on operation and maintenance personnel.
[0084] In some specific embodiments, the virtual disk acquisition module 11 may specifically include:
[0085] The virtual disk acquisition unit is used to acquire the virtual disk created by the virtualization management platform after receiving the target file uploaded by the user by calling the application interface and based on the target virtual machine disk management command.
[0086] In some specific embodiments, the virtual disk format includes copy-on-write format and raw format.
[0087] In some specific embodiments, the target parameters include a first target parameter indicating that the operating system type of the target virtual machine is a Windows operating system and a second target parameter indicating that the operating system type of the target virtual machine is a Linux operating system.
[0088] In some specific embodiments, the format conversion module 12 may specifically include:
[0089] The first target parameter receiving unit is used to receive the first target parameter sent by the virtualization management platform;
[0090] Accordingly, the format conversion module 12 may specifically include:
[0091] The first format conversion unit is used to convert the virtual disk in the copy-on-write format into the virtual disk in the new technology file system format according to the first target parameter, so as to obtain the target virtual disk.
[0092] In some specific embodiments, the format conversion module 12 may specifically include:
[0093] The second target parameter receiving unit is used to receive the second target parameter sent by the virtualization management platform;
[0094] Accordingly, the format conversion module 12 may specifically include:
[0095] The second format conversion unit is used to convert the virtual disk in the raw format into the virtual disk in the fourth-generation extended file system format according to the second target parameters, so as to obtain the target virtual disk.
[0096] In some specific embodiments, before the first mounting module 13, there may further be:
[0097] The target temporary directory acquisition unit is used to acquire the target temporary directory created by the virtualization management platform based on the identity number of the target virtual machine.
[0098] In some specific embodiments, the second mounting module 14 may specifically include:
[0099] The second mounting unit is used to mount the target block device to the target virtual machine by calling the target virtualization management tool after the virtualization management platform transfers the target file to the target temporary directory.
[0100] Furthermore, embodiments of this application also provide an electronic device. Figure 5 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content of the diagram should not be construed as limiting the scope of this application.
[0101] Figure 5This is a schematic diagram of the structure of an electronic device 20 provided in an embodiment of this application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a display screen 23, an input / output interface 24, a communication interface 25, a power supply 26, and a communication bus 27. The memory 22 stores a computer program, which is loaded and executed by the processor 21 to implement the following steps:
[0102] Obtain the virtual disk created by the virtualization management platform after receiving the target file uploaded by the user;
[0103] The system receives target parameters sent by the virtualization management platform, which indicate the operating system type of the target virtual machine, and performs format conversion on the virtual disk according to the target parameters to obtain the target virtual disk.
[0104] The target virtual disk is virtualized as a target block device, and the target block device is mounted to the target temporary directory corresponding to the target virtual machine;
[0105] After the virtualization management platform transfers the target file to the target temporary directory, the target block device is mounted to the target virtual machine.
[0106] In some specific embodiments, the processor executes a computer program stored in the memory, specifically implementing the following steps:
[0107] After receiving the target file uploaded by the user, the virtualization management platform obtains the virtual disk created by calling the application programming interface and based on the target virtual machine disk management commands.
[0108] In some specific embodiments, the processor executes a computer program stored in the memory, specifically implementing the following steps:
[0109] The virtual disk formats include copy-on-write format and raw format.
[0110] In some specific embodiments, the processor executes a computer program stored in the memory, specifically implementing the following steps:
[0111] The target parameters include a first target parameter indicating that the operating system type of the target virtual machine is a Windows operating system and a second target parameter indicating that the operating system type of the target virtual machine is a Linux operating system.
[0112] In some specific embodiments, the processor executes a computer program stored in the memory, specifically implementing the following steps:
[0113] Receive the first target parameter sent by the virtualization management platform;
[0114] Accordingly, the step of converting the format of the virtual disk according to the target parameters to obtain the target virtual disk includes:
[0115] Based on the first target parameter, the virtual disk in the copy-on-write format is converted into the virtual disk in the new technology file system format to obtain the target virtual disk;
[0116] Alternatively, receiving the target parameters sent by the virtualization management platform to indicate the operating system type of the target virtual machine includes:
[0117] Receive the second target parameter sent by the virtualization management platform;
[0118] Accordingly, the step of converting the format of the virtual disk according to the target parameters to obtain the target virtual disk includes:
[0119] The virtual disk in the raw format is converted into the virtual disk in the fourth-generation extended file system format according to the second target parameter to obtain the target virtual disk.
[0120] In some specific embodiments, the processor executes a computer program stored in the memory, specifically implementing the following steps:
[0121] Obtain the target temporary directory created by the virtualization management platform based on the identity number of the target virtual machine.
[0122] In some specific embodiments, the processor executes a computer program stored in the memory, specifically implementing the following steps:
[0123] After the virtualization management platform transfers the target file to the target temporary directory, it calls the target virtualization management tool to mount the target block device to the target virtual machine.
[0124] In addition, the electronic device 20 in this embodiment can specifically be an electronic computer.
[0125] 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 external devices, and the communication protocol it follows can be any communication protocol applicable to the technical solution of this application, and is not specifically limited here; the input / output interface 24 is used to acquire external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0126] Furthermore, the memory 22, as a carrier for resource storage, can be a read-only memory, random access memory, disk, or optical disk, etc. The resources stored thereon may include computer programs 221, and the storage method may be temporary storage or permanent storage. The computer programs 221 may include, in addition to computer programs capable of performing the method of uploading files to a virtual machine executed by the electronic device 20 as disclosed in any of the foregoing embodiments, computer programs capable of performing other specific tasks.
[0127] Furthermore, embodiments of this application also disclose a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, it implements the aforementioned method for uploading files to a virtual machine.
[0128] For the specific steps of this method, please refer to the relevant content disclosed in the foregoing embodiments, which will not be repeated here.
[0129] The various embodiments in this application are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. For the same or similar parts between the various embodiments, refer to each other. As for the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple, and relevant parts can be referred to in the method section.
[0130] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can 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.
[0131] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0132] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0133] The above provides a detailed description of a method, apparatus, device, and storage medium for uploading files to a virtual machine. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A method for uploading files to a virtual machine, characterized in that, include: Obtain the virtual disk created by the virtualization management platform after receiving the target file uploaded by the user; The system receives target parameters sent by the virtualization management platform, which indicate the operating system type of the target virtual machine, and performs format conversion on the virtual disk according to the target parameters to obtain the target virtual disk. The target virtual disk is virtualized as a target block device, and the target block device is mounted to the target temporary directory corresponding to the target virtual machine; After the virtualization management platform transfers the target file to the target temporary directory, the target block device is mounted to the target virtual machine. Before mounting the target block device to the target temporary directory corresponding to the target virtual machine, the method further includes: Obtain the target temporary directory created by the virtualization management platform based on the identity number of the target virtual machine; After the virtualization management platform transfers the target file to the target temporary directory, the step of mounting the current target block device to the target virtual machine includes: After the virtualization management platform transfers the target file to the target temporary directory, it calls the target virtualization management tool to mount the target block device to the target virtual machine.
2. The method for uploading files to a virtual machine according to claim 1, characterized in that, The virtual disk created by the virtualization management platform after receiving the target file uploaded by the user includes: After receiving the target file uploaded by the user, the virtualization management platform obtains the virtual disk created by calling the application programming interface and based on the target virtual machine disk management commands.
3. The method for uploading files to a virtual machine according to claim 2, characterized in that, The virtual disk formats include copy-on-write format and raw format.
4. The method for uploading files to a virtual machine according to claim 3, characterized in that, The target parameters include a first target parameter indicating that the operating system type of the target virtual machine is a Windows operating system and a second target parameter indicating that the operating system type of the target virtual machine is a Linux operating system.
5. The method for uploading files to a virtual machine according to claim 4, characterized in that, The receiving of target parameters from the virtualization management platform, indicating the operating system type of the target virtual machine, includes: Receive the first target parameter sent by the virtualization management platform; Accordingly, the step of converting the format of the virtual disk according to the target parameters to obtain the target virtual disk includes: Based on the first target parameter, the virtual disk in the copy-on-write format is converted into the virtual disk in the new technology file system format to obtain the target virtual disk; Alternatively, receiving the target parameters sent by the virtualization management platform to indicate the operating system type of the target virtual machine includes: Receive the second target parameter sent by the virtualization management platform; Accordingly, the step of converting the format of the virtual disk according to the target parameters to obtain the target virtual disk includes: The virtual disk in the raw format is converted into the virtual disk in the fourth-generation extended file system format according to the second target parameter to obtain the target virtual disk.
6. An apparatus for uploading files to a virtual machine, characterized in that, include: The virtual disk acquisition module is used to acquire the virtual disk created by the virtualization management platform after receiving the target file uploaded by the user; The format conversion module is used to receive target parameters sent by the virtualization management platform, which indicate the operating system type of the target virtual machine, and to convert the format of the virtual disk according to the target parameters to obtain the target virtual disk; The first mounting module is used to virtualize the target virtual disk as a target block device and mount the target block device to the target temporary directory corresponding to the target virtual machine; The second mounting module is used to mount the target block device to the target virtual machine after the virtualization management platform transfers the target file to the target temporary directory; Before mounting the target block device to the target temporary directory corresponding to the target virtual machine, the method further includes: Obtain the target temporary directory created by the virtualization management platform based on the identity number of the target virtual machine; After the virtualization management platform transfers the target file to the target temporary directory, the step of mounting the current target block device to the target virtual machine includes: After the virtualization management platform transfers the target file to the target temporary directory, it calls the target virtualization management tool to mount the target block device to the target virtual machine.
7. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the method of uploading a file to a virtual machine as described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, Used to store computer programs; wherein, when the computer programs are executed by a processor, they implement the method of uploading files to a virtual machine as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Concurrent backup method and a system of virtual machine files
CN109344001A