Disclosure of Invention
Therefore, the present invention aims to provide a method, an apparatus, a device, and a medium for managing USB devices in a cluster, which can solve the problem that USB devices can only be mounted on a virtual machine on a host, and avoid the limitation that the virtual machine cannot migrate after the USB devices are mounted. The specific scheme is as follows:
In a first aspect, the present application discloses a method for managing USB devices in a cluster, including:
Acquiring equipment information of local available USB equipment, and distributing a port number for each available USB equipment;
acquiring a host IP, and obtaining a unique number corresponding to each available USB device based on the host IP and the port number;
And sharing the unique numbers corresponding to all the available USB devices to a cluster database through a network protocol, so that any host in the cluster mounts the USB device to be mounted to the target virtual machine according to the unique number of the USB device to be mounted and the ID of the target virtual machine.
Optionally, the obtaining device information of the locally available USB device includes:
Inquiring a local USB device list, and filtering virtual USB devices from the USB device list according to a target parameter field corresponding to each USB device to obtain device information of the available USB devices.
Optionally, the sharing the unique numbers corresponding to all the available USB devices to the cluster database through a network protocol includes:
and uploading the unique numbers corresponding to all the available USB devices and associated parameter information to the cluster database through a transmission control protocol, wherein the parameter information comprises a host name, a device manufacturer identifier and a device product identifier.
Optionally, the target virtual machine is a virtual machine created based on Libvirt, and the host mounts the USB device to be mounted to the target virtual machine according to the unique number of the USB device to be mounted and the ID of the target virtual machine, including:
the method comprises the steps of receiving a mounting request, wherein the mounting request comprises a unique number of the USB equipment to be mounted and an ID of the target virtual machine;
Generating redirection configuration information based on the unique number of the USB device to be mounted and the ID of the target virtual machine;
and based on the redirection configuration information, utilizing Libvirt services to mount the USB equipment to be mounted to the target virtual machine.
Optionally, after sharing the unique numbers corresponding to all the available USB devices to the cluster database through a network protocol, the method includes:
uploading the associated information containing the unique number corresponding to all the available USB devices in the cluster database to a cloud management platform;
and adding corresponding parameter information for each USB device through the cloud management platform, wherein the parameter information comprises a device use state and a device use authority.
Optionally, after adding corresponding parameter information to each USB device through the cloud management platform, the method further includes:
and monitoring the use state of the equipment in real time, and automatically updating the use permission of the equipment according to the type of the use state of the equipment.
Optionally, after the USB device to be mounted is mounted to the target virtual machine, the method further includes:
and updating the equipment use state of the USB equipment to be mounted through the cloud management platform, and adding corresponding mounting information, wherein the mounting information comprises attribute information of the target virtual machine.
In a second aspect, the present application discloses a device for managing USB devices in a cluster, including:
the device information acquisition module is used for acquiring device information of local available USB devices and distributing a port number for each available USB device;
the unique number determining module is used for acquiring a host IP and obtaining a unique number corresponding to each available USB device based on the host IP and the port number;
And the sharing module is used for sharing the unique numbers corresponding to all the available USB devices to a cluster database through a network protocol, so that any host in the cluster can mount the USB device to be mounted to the target virtual machine according to the unique number of the USB device to be mounted and the ID of the target virtual machine.
Optionally, the device information obtaining module includes:
And the filtering unit is used for inquiring the local USB device list, and filtering virtual USB devices from the USB device list according to the target parameter field corresponding to each USB device so as to obtain the device information of the available USB devices.
In a third aspect, the present application discloses an electronic device, comprising:
A memory for storing a computer program;
and the processor is used for executing the computer program to realize the method for managing the USB devices in the cluster.
In a fourth aspect, the present application discloses a computer readable storage medium for storing a computer program, where the computer program when executed by a processor implements the foregoing method for managing USB devices in a cluster.
The method comprises the steps of obtaining equipment information of local available USB equipment, distributing a port number for each available USB equipment, obtaining a host IP, obtaining a unique number corresponding to each available USB equipment based on the host IP and the port number, sharing the unique numbers corresponding to all the available USB equipment to a cluster database through a network protocol, so that any host in the cluster can mount the USB equipment to be mounted to a target virtual machine according to the unique number of the USB equipment to be mounted and the ID of the target virtual machine. Therefore, by allocating port numbers to each USB device and then using the host IP and the port numbers as unique numbers to identify one USB device, USB devices on any host in the cluster can be further shared out through a network protocol according to the unique numbers, virtual machines on any host in the cluster can be connected with required USB devices through the host IP and the port numbers, redirection of the USB devices is realized, the problem that the USB devices can only be mounted on the virtual machine on the host in the traditional USB direct scheme is solved, and meanwhile, the limitation that the virtual machines cannot migrate after the USB devices are mounted is avoided.
Detailed Description
In the prior art, if a user wants to copy files in a USB flash disk to a virtual machine, the user needs to plug the USB flash disk into a USB interface of a host where the virtual machine is located, and then mounts the USB flash disk to the virtual machine, so that the files in the USB flash disk can be read and written in the virtual machine. However, when the openstack cluster is large, the number of hosts and virtual machines increases, the virtual machines are distributed on different hosts, and this time, it is very troublesome to mount USB devices by using the conventional USB through scheme, because the hosts where the USB devices are located need to be changed back and forth or a large number of USB devices are prepared, and the virtual machines on which the USB devices are mounted cannot be migrated, which is complicated to use and has low efficiency. In order to overcome the technical problems, the application provides a management method of USB devices in a cluster, which can solve the problem that the USB devices can only be mounted on a virtual machine on a host machine, and simultaneously avoid the limitation that the virtual machine cannot migrate after the USB devices are mounted.
The embodiment of the application discloses a method for managing USB equipment in a cluster, which is applied to a host in the cluster, and can comprise the following steps as shown in FIG. 1:
Step S11, obtaining equipment information of local available USB equipment, and distributing a port number for each available USB equipment.
In this embodiment, first, device information of locally available USB devices, that is, available USB devices connected to a current physical host, is acquired, and a network port number is allocated to each available USB device.
In this embodiment, the obtaining the device information of the locally available USB device may include querying a local USB device list, and filtering virtual USB devices from the USB device list according to a target parameter field corresponding to each USB device to obtain the device information of the available USB device. That is, the computing service of each host in the cluster actively queries the USB list on the host at the time of starting, and filters out some unavailable virtual USB devices carried by the operating system, so as to obtain the device information of the available USB devices.
And step S12, acquiring a host IP, and obtaining a unique number corresponding to each available USB device based on the host IP and the port number.
In this embodiment, by obtaining the host IP and obtaining the unique number corresponding to each available USB device based on the host IP and the port number, therefore, one USB device is uniquely identified by the host IP and the network port number, and no longer is the conventional vendor ID and productor ID, which can effectively avoid the disadvantage that the cloud platform can only identify one USB device when different USB devices have the same vendor ID (manufacturer identification) or product ID (product identification).
And S13, sharing the unique numbers corresponding to all the available USB devices to a cluster database through a network protocol, so that any host in the cluster can mount the USB device to be mounted to the target virtual machine according to the unique number of the USB device to be mounted and the ID of the target virtual machine.
In this embodiment, for example, as shown in fig. 2, after determining the unique numbers of the available USB devices, the sharing service is started to share the unique numbers of the USB devices through the network protocol. In this embodiment, sharing the unique numbers corresponding to all the available USB devices to the cluster database through the network protocol may include uploading the unique numbers corresponding to all the available USB devices and associated parameter information to the cluster database through a transmission control protocol, where the parameter information includes a host name, a device manufacturer identifier, and a device product identifier. The unique number corresponding to the USB device and the associated parameter information are shared to the cluster database through a transmission control protocol (TCP, transmission Control Protocol) protocol, wherein the parameter information includes, but is not limited to, a host name of a host where the USB device is located, a manufacturer identifier (product ID) of the USB device, and a product identifier (vendor ID) of the USB device, and the data shared to the cluster database may include, but is not limited to, the unique number composed of the host IP and the port number, and the host name, the product ID, and the vendor ID. Each host in the cluster can share the available USB equipment of the host in the mode, so that when any host in the cluster needs data in a certain USB equipment, the USB equipment to be mounted is mounted to the target virtual machine according to the required unique number of the USB equipment to be mounted and the ID of the target virtual machine. Specifically, when the user wants to mount the USB device to be mounted on the virtual machine, the user may select the USB device and the target virtual machine to be mounted from the USB list of the virtual machine device management interface. Therefore, the problem that the USB equipment can only be mounted on the virtual machine on the host computer in the traditional USB through scheme is solved, and meanwhile, the limitation that the virtual machine cannot be migrated after the USB equipment is mounted is avoided. The embodiment is suitable for an OpenStack large-scale cluster scene, wherein OpenStack is an open-source cloud computing management platform project and is a combination of a series of software open-source projects.
In this embodiment, the target virtual machine is a virtual machine created based on Libvirt, and the host mounts the USB device to be mounted to the target virtual machine according to the unique number of the USB device to be mounted and the ID of the target virtual machine, which may include receiving a mounting request, where the mounting request includes the unique number of the USB device to be mounted and the ID of the target virtual machine, generating redirection configuration information based on the unique number of the USB device to be mounted and the ID of the target virtual machine, and mounting the USB device to be mounted to the target virtual machine by using Libvirt service based on the redirection configuration information. Specifically, the computing service of the host may splice redirdev xml files of the device, that is, configuration files, according to the virtual machine ID selected by the user and the host IP and port number corresponding to the USB device, and send the request to libvirt, libvirt, and mount the USB device to be mounted to the target virtual machine after receiving the request.
In this embodiment, after sharing unique numbers corresponding to all the available USB devices to a cluster database through a network protocol, uploading associated information corresponding to all the available USB devices and including the unique numbers to a cloud management platform, and adding corresponding parameter information to each USB device through the cloud management platform, where the parameter information includes a device use state and a device use permission.
It can be appreciated that all USB devices in the cluster can be managed by the cloud management platform, and bong can improve the security of device sharing by setting the use authority for the USB devices, such as setting that the USB devices can be used by those virtual machines. Specifically, the database can be queried through Api (Application Programming Interface, application program interface) service of the host to obtain all available USB device lists and USB related information in the cluster, including unique numbers composed of host IP and port numbers, host names, product IDs, vendor IDs, etc., and the unique numbers are uploaded to the cloud platform management interface, and the interface uniformly displays the available USB device lists in the cluster, and manages the device use states and device use rights. For example, as shown in fig. 3, an administrator logs in a virtual machine management platform, selects a cloud host from a cloud management platform list, selects a USB device to be mounted from a cloud host operation list, selects a corresponding host, selects a USB device to be mounted from a host USB list, and sets permission to implement sharing control, so that the USB device to be mounted is in a usable state.
In this embodiment, after the USB device to be mounted is mounted to the target virtual machine, updating, by the cloud management platform, a device usage state of the USB device to be mounted, and adding corresponding mounting information, where the mounting information includes attribute information of the target virtual machine. The state of the USB device to be mounted is set to be a use state, and relevant mounting information is added to the USB device to be mounted, wherein the mounting information comprises, but is not limited to, attribute information of a target virtual machine corresponding to the USB device to be mounted, such as a virtual machine ID, a memory and the like, so that information of the virtual machine associated with the USB device can be displayed.
In this embodiment, after adding the corresponding parameter information to each USB device through the cloud management platform, the method may further include monitoring the device usage status in real time, and automatically updating the device usage rights according to the type of the device usage status. When the use state of the equipment is monitored to be the use state, the equipment use permission of the corresponding equipment is automatically updated to be unusable, so that the abnormality caused by excessive equipment connection is avoided.
Therefore, in this embodiment, by allocating a port number to each USB device, and then using the host IP and the port number as the unique numbers to identify one USB device, further sharing the USB device on any host in the cluster according to the unique numbers through the network protocol, so that the virtual machine on any host in the cluster can connect the required USB device through the host IP and the port number, thereby implementing redirection of the USB device, uniformly managing all USB devices in the cluster, and avoiding the limitation that the virtual machine cannot migrate after mounting the USB device.
Correspondingly, the embodiment of the application also discloses a device for managing the USB equipment in the cluster, which is shown in fig. 4, and comprises the following steps:
the device information acquisition module 11 is configured to acquire device information of locally available USB devices, and allocate a port number to each of the available USB devices;
a unique number determining module 12, configured to obtain a host IP, and obtain a unique number corresponding to each of the available USB devices based on the host IP and the port number;
And the sharing module 13 is configured to share the unique numbers corresponding to all the available USB devices to a cluster database through a network protocol, so that any host in the cluster mounts the USB device to be mounted to the target virtual machine according to the unique number of the USB device to be mounted and the ID of the target virtual machine.
From the above, in this embodiment, by acquiring device information of local available USB devices and allocating a port number to each of the available USB devices, acquiring a host IP, obtaining a unique number corresponding to each of the available USB devices based on the host IP and the port number, sharing the unique numbers corresponding to all the available USB devices to a cluster database through a network protocol, so that any host in the cluster mounts the USB device to be mounted to the target virtual machine according to the unique number of the USB device to be mounted and the ID of the target virtual machine. Therefore, by allocating port numbers to each USB device and then using the host IP and the port numbers as unique numbers to identify one USB device, USB devices on any host in the cluster can be further shared out through a network protocol according to the unique numbers, virtual machines on any host in the cluster can be connected with required USB devices through the host IP and the port numbers, redirection of the USB devices is realized, the problem that the USB devices can only be mounted on the virtual machine on the host in the traditional USB direct scheme is solved, and meanwhile, the limitation that the virtual machines cannot migrate after the USB devices are mounted is avoided.
In some specific embodiments, the device information obtaining module may specifically include:
And the filtering unit is used for inquiring the local USB device list, and filtering virtual USB devices from the USB device list according to the target parameter field corresponding to each USB device so as to obtain the device information of the available USB devices.
In some specific embodiments, the sharing module 13 may specifically include:
And the information uploading unit is used for uploading the unique numbers corresponding to all the available USB devices and the associated parameter information to the cluster database through a transmission control protocol, wherein the parameter information comprises a host name, a device manufacturer identifier and a device product identifier.
In some embodiments, the USB device management apparatus within a cluster may specifically include:
the mounting request receiving unit is used for receiving a mounting request, wherein the mounting request comprises a unique number of the USB equipment to be mounted and an ID of the target virtual machine;
The redirection configuration information generation unit is used for generating redirection configuration information based on the unique number of the USB equipment to be mounted and the ID of the target virtual machine;
And the mounting unit is used for mounting the USB equipment to be mounted to the target virtual machine by utilizing Libvirt services based on the redirection configuration information.
In some embodiments, the USB device management apparatus within a cluster may specifically include:
The information uploading unit is used for uploading the associated information which contains the unique number and corresponds to all the available USB devices in the cluster database to a cloud management platform;
and the permission configuration unit is used for adding corresponding parameter information for each USB device through the cloud management platform, wherein the parameter information comprises a device use state and a device use permission.
In some embodiments, the USB device management apparatus within a cluster may specifically include:
The state monitoring unit is used for monitoring the use state of the equipment in real time and automatically updating the use permission of the equipment according to the type of the use state of the equipment.
In some embodiments, the USB device management apparatus within a cluster may specifically include:
The state updating unit is used for updating the equipment use state of the USB equipment to be mounted through the cloud management platform and adding corresponding mounting information, wherein the mounting information comprises attribute information of the target virtual machine.
Further, the embodiment of the application also discloses an electronic device, and referring to fig. 5, the content in the drawing should not be considered as any limitation on the application scope of the application.
Fig. 5 is a schematic structural diagram of an electronic device 20 according to an embodiment of the present application. The electronic device 20 may include, in particular, at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input-output interface 25, and a communication bus 26. The memory 22 is configured to store a computer program, where the computer program is loaded and executed by the processor 21 to implement relevant steps in the method for managing USB devices in a cluster disclosed in any of the foregoing embodiments.
In this embodiment, the power supply 23 is configured to provide working voltages for each hardware device on the electronic device 20, the communication interface 24 is capable of creating a data transmission channel with an external device for the electronic device 20, and the communication protocol to be followed is any communication protocol applicable to the technical solution of the present application, which is not specifically limited herein, and the input/output interface 25 is configured to obtain external input data or output data to the external device, and the specific interface type of the input/output interface may be selected according to the specific application needs and is not specifically limited herein.
The memory 22 may be a carrier for storing resources, such as a read-only memory, a random access memory, a magnetic disk, or an optical disk, and the resources stored thereon include an operating system 221, a computer program 222, and data 223 including device information, and the storage may be temporary storage or permanent storage.
The operating system 221 is used for managing and controlling various hardware devices on the electronic device 20 and the computer program 222, so as to implement the operation and processing of the processor 21 on the mass data 223 in the memory 22, which may be Windows Server, netware, unix, linux, etc. The computer program 222 may further include a computer program that can be used to perform other specific tasks in addition to the computer program that can be used to perform the method of managing USB devices within a cluster performed by the electronic device 20 as disclosed in any of the previous embodiments.
Further, the embodiment of the application also discloses a computer storage medium, wherein the computer storage medium stores computer executable instructions, and when the computer executable instructions are loaded and executed by a processor, the method steps of managing the USB devices in the cluster disclosed in any embodiment are realized.
In this specification, each embodiment is described in a progressive manner, and each embodiment is mainly described in a different point from other embodiments, so that the same or similar parts between the embodiments are referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant points refer to the description of the method section.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. The software modules may be disposed in Random Access Memory (RAM), memory, read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
Finally, it is further noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises an element.
The foregoing describes the method, apparatus, device and medium for managing USB devices in a cluster in detail, and specific examples are provided herein to illustrate the principles and embodiments of the present invention, and the above description of the embodiments is only for aiding in understanding of the method and core concept of the present invention, and meanwhile, to those skilled in the art, according to the concept of the present invention, there are variations in the specific embodiments and application ranges, so the disclosure should not be construed as limiting the invention.