Method and device for automatically configuring routing of virtual machines, electronic device and storage medium
By automatically configuring the default routes of virtual machines, the problem of manually deleting redundant default routes when there are multiple network interfaces on a virtual machine is solved, realizing the automation and persistence of default route configuration.
Patent Information
- Application Number
- CN202310165416.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-24
- Publication Date
- 2025-01-10
- Estimated Expiration
- 2043-02-24
AI Technical Summary
When a virtual machine has multiple network interfaces, it is necessary to manually delete redundant default routes, and the deletion of default routes is not persistent, which wastes a lot of human resources.
By obtaining the target network information of the virtual machine's network interface card, the system automatically disables or enables the current routes of multiple network interfaces according to the target network protocol, and determines the final automatic configuration result of the default route based on the configuration validity verification value of the default route.
It automates the configuration of default routes, eliminating the need for manual intervention and resolving the issue of manually deleting redundant default routes when there are multiple network interfaces on a virtual machine.
Smart Images

Figure CN116208476B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer network technology, and in particular to a method and device for automatically configuring routing for a virtual machine, an electronic device, and a storage medium. Background Art
[0002] When a virtual machine is bound to a network with DHCP (Dynamic Host Configuration Protocol) enabled, DHCP will automatically send down information such as IP, gateway, and default route. When a virtual machine is bound to multiple DHCP networks, multiple default routes will be generated for the virtual machine; at this time, the user needs to specify which route is used as the traffic outlet. If there are multiple routes, if the route to access the external network is not specified as the default route, the virtual machine will be unable to access the external network. At this time, the user needs to manually delete the redundant default routes so that the route to access the external network automatically becomes the default route to complete the access to the external network.
[0003] From the above, it can be seen that when there are multiple network interfaces on a virtual machine, it is necessary to manually delete redundant default routes to achieve accurate network communication; at the same time, if the virtual machine is shut down, after the virtual machine is restarted, the previously deleted default routes will be regenerated and need to be reset, resulting in the inability to persist the settings and wasting human resources.
[0004] Therefore, in the related art, when there are multiple network interfaces on a virtual machine, it is necessary to manually delete redundant default routes and the settings for deleting the default routes cannot be persisted, which wastes a lot of human resources. Summary of the invention
[0005] The present application provides a method and device for automatically configuring routing for a virtual machine, an electronic device and a storage medium, so as to at least solve the problem in the related art that when there are multiple network interfaces on a virtual machine, redundant default routes need to be manually deleted and the settings for deleting the default routes cannot be persisted, thus wasting a lot of human resources.
[0006] According to one aspect of an embodiment of the present application, a method for automatically configuring routing for a virtual machine is provided, the method comprising:
[0007] Obtain network information of the target network card in the virtual machine, wherein the route of the target network card is a preset default route;
[0008] Obtain the target network protocol corresponding to the interface of the target network card according to the network information;
[0009] Perform corresponding logic operations on the current routes of the multiple network cards according to the target network protocol, wherein the logic operation is to perform a closing or opening operation on the route configuration of the network card;
[0010] The automatic configuration result of the default route is determined according to the logical operation and the configuration validity verification value of the default route.
[0011] According to another aspect of an embodiment of the present application, a device for automatically setting a route for a virtual machine is also provided, the device comprising:
[0012] A first acquisition module is used to acquire network information of a target network card in a virtual machine, wherein the route of the target network card is a preset default route;
[0013] A second acquisition module is used to acquire a target network protocol corresponding to the interface of the target network card according to the network information;
[0014] An execution module, used for executing corresponding logic operations on the current routes of the multiple network cards according to the target network protocol, wherein the logic operation is to execute a closing or opening operation on the route configuration of the network card;
[0015] The first determination module is used to determine the automatic configuration result of the default route according to the logical operation and the configuration validity verification value of the default route.
[0016] Optionally, the execution module includes:
[0017] A closing operation unit, used for executing a closing operation on the routing configuration of the current routing of the network card when the network protocol of the interface of the network card is not the target network protocol;
[0018] The opening operation unit is used to perform an opening operation on the routing configuration of the current routing of the network card when the network protocol of the interface of the network card is the target network protocol.
[0019] Optionally, the first determining module includes:
[0020] The determination unit is used to determine that the default route is configured and send information that the route configuration is successful when the opened route configuration is the route configuration corresponding to the default route and the configuration validity check value of the default route indicates that the route configuration has taken effect.
[0021] Optionally, the device further comprises:
[0022] A verification module is used to verify whether the state of the running daemon process of the gateway or virtual machine in the network information of the target network card is abnormal before obtaining the target network protocol corresponding to the interface of the target network card according to the network information;
[0023] The third acquisition module is used to acquire the target network protocol if there is a gateway in the network information and the status of the running daemon process of the virtual machine is normal.
[0024] Optionally, the device further comprises:
[0025] The second determination module is used to verify whether there is an abnormal state of the running daemon process of the gateway or virtual machine in the network information of the target network card. If there is no abnormal state of the running daemon process of the gateway or virtual machine in the network information, it is determined that the default route is not configured and a message of route configuration failure is sent.
[0026] Optionally, the device further comprises:
[0027] A disconnection module, used to disconnect the network connection after performing corresponding logical operations on the current routes of the multiple network cards according to the target network protocol;
[0028] The restart module is used to restart the network connection so that the configuration properties after the logical operation takes effect.
[0029] Optionally, the device further comprises:
[0030] The third determination module is used to determine that the default route is not configured and send information that the route configuration fails when the configuration validity check value of the default route indicates that the route configuration is not effective.
[0031] According to another aspect of the embodiments of the present application, there is also provided an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; wherein the memory is used to store a computer program; and the processor is used to execute the method steps in any of the above embodiments by running the computer program stored in the memory.
[0032] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the method steps in any of the above embodiments when executed.
[0033] In an embodiment of the present application, by obtaining the default route target network card of the virtual machine, the current route configuration of multiple network cards is automatically closed or opened according to the target network protocol of the target network card, and at the same time, the final automatic configuration result of the default route is determined according to the configuration effectiveness verification value of the default route. The above operations can be completed on the cloud management platform without the intervention of operation and maintenance personnel, eliminating manpower, and realizing the automation of default route configuration, thereby solving the problem in the related technology that when there are multiple network interfaces on a virtual machine, redundant default routes need to be manually deleted and the setting of deleted default routes cannot be persisted, wasting a lot of human resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0035] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0036] Figure 1 It is a flowchart of an optional method for automatically configuring routing for a virtual machine according to an embodiment of the present application;
[0037] Figure 2 This is a service architecture diagram of an optional virtual machine automatic configuration routing according to an embodiment of the present application;
[0038] Figure 3 It is a schematic diagram of an optional scheduling process of automatic configuration routing of a virtual machine according to an embodiment of the present application;
[0039] Figure 4 It is a structural block diagram of an optional device for automatically configuring routing of a virtual machine according to an embodiment of the present application;
[0040] Figure 5 It is a structural block diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0041] In order to enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this application.
[0042] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0043] Currently, when the dynamic host configuration protocol is used to send information such as IP, gateway, and default route, if a virtual machine is bound to multiple DHCP networks, the virtual machine will generate multiple default routes. At this time, the user needs to specify which route is the default route for current forwarding or completing communication, and manually delete other redundant default routes to achieve accurate network communication. The above-mentioned prior art has the problem that when there are multiple network interfaces on the virtual machine, redundant default routes need to be manually deleted, and the setting of deleting the default route cannot be persisted, which wastes a lot of human resources.
[0044] In order to solve the above problems, the present application embodiment proposes a method for automatically configuring routing for a virtual machine, such as Figure 1 As shown, the method can be applied to the backend cloud platform side, and the method may include the following steps:
[0045] Step S101, obtaining network information of a target network card in a virtual machine, wherein the route of the target network card is a preset default route;
[0046] Step S102, obtaining a target network protocol corresponding to the interface of the target network card according to the network information;
[0047] Step S103, performing corresponding logic operations on the current routes of the multiple network cards according to the target network protocol, wherein the logic operation is to perform a closing or opening operation on the route configuration of the network card;
[0048] Step S104: determining the automatic configuration result of the default route according to the logic operation and the configuration validity check value of the default route.
[0049] Alternatively, if Figure 2 When a virtual machine with multiple network cards needs to set a default route, the user selects the network card that needs to be set as the default route in the virtual machine on the cloud platform and defines the network card as the target network card. At this time, the network information of the target network card is obtained to obtain the corresponding default route.
[0050] Then, it performs corresponding verification based on the network information, such as checking the qga (qemu guest agent, a daemon running on the virtual machine) status of the virtual machine. After confirming that it is correct, it obtains the target network protocol corresponding to the interface of the target network card; according to the target network protocol, the cloud platform executes the NetworkManager (network manager) to set the routing command through qga, and the NetworkManager performs corresponding logical operations on the current routes of multiple network cards, such as closing or opening the routing configuration of the network card.
[0051] Then, according to the above logic operation and the configuration effectiveness of the default route of the target network protocol of the virtual machine, it is determined whether the automatic configuration of the default route is successful, and the final configuration result is obtained.
[0052] In an embodiment of the present application, by obtaining the default route target network card of the virtual machine, the current route configuration of multiple network cards is automatically closed or opened according to the target network protocol of the target network card, and at the same time, the final automatic configuration result of the default route is determined according to the configuration effectiveness verification value of the default route. The above operations can be completed on the cloud management platform without the intervention of operation and maintenance personnel, eliminating manpower, and realizing the automation of default route configuration, thereby solving the problem in the related technology that when there are multiple network interfaces on a virtual machine, redundant default routes need to be manually deleted and the setting of deleted default routes cannot be persisted, wasting a lot of human resources.
[0053] As an optional embodiment, performing corresponding logical operations on current routes of multiple network cards according to the target network protocol includes:
[0054] When the network protocol of the interface of the network card is not the target network protocol, a closing operation is performed on the routing configuration of the current routing of the network card;
[0055] When the network protocol of the interface of the network card is the target network protocol, an opening operation is performed on the routing configuration of the current routing of the network card.
[0056] Optionally, in an embodiment of the present application, it is determined whether the network protocol of the interfaces of multiple network cards is the target network protocol, for example, the target network protocol is IPV4 or IPV6. When it is determined that the network protocol of the interface of the network card is not the target network protocol, NetworkManager can be used to perform a shutdown operation on the routing configuration of the current routing of the network card.
[0057] The specific operation is: turn off the default route of the routing network card of the non-target network protocol, and set the default route property of the network connection corresponding to these network cards in NetworkManager to true, which means turning off this property.
[0058] When it is determined that the network protocol of the interface of the network card is the target network protocol, the NetworkManager may be used to perform an open operation on the routing configuration of the current routing of the network card.
[0059] The specific operation is: open the default route of the routing network card of the target network protocol, and set the default route property of the network connection corresponding to these network cards in NetworkManager to false, indicating that this property is turned on.
[0060] In the embodiment of the present application, the logical operation is automatically completed based on the comparison between the network protocol of the interface of the network card and the target network protocol, without the intervention of operation and maintenance personnel.
[0061] As an optional embodiment, determining the automatic configuration result of the default route according to the logic operation and the configuration validity verification value of the default route includes:
[0062] When the opened route configuration is the route configuration corresponding to the default route and the configuration effectiveness check value of the default route indicates that the route configuration has taken effect, it is determined that the default route has completed configuration, and information on successful route configuration is sent.
[0063] Optionally, in the embodiment of the present application, in order to ensure that the default route configuration is effective, it is necessary to verify whether the virtual machine default route is the preset default route of the target network card. Specifically, if NetworkManager opens the route configuration corresponding to the target network protocol and receives a verification value indicating that the route configuration has taken effect, it is considered that the default route has been configured and a message indicating that the route configuration is successful is sent.
[0064] In the embodiment of the present application, a step is provided to verify whether the default route configuration is effective, to ensure that the configuration is successful.
[0065] As an optional embodiment, before acquiring the target network protocol corresponding to the interface of the target network card according to the network information, the method further includes:
[0066] Check whether there is a gateway in the network information of the target network card or whether the status of the running daemon process of the virtual machine is abnormal;
[0067] If a gateway exists in the network information and the status of the running daemon process of the virtual machine is normal, the target network protocol is obtained.
[0068] Optionally, after the user specifies the target network card to be set, the cloud platform verifies the target network card, such as whether the network has a gateway and whether the virtual machine qga status is normal. If the network has no gateway or the virtual machine qga is abnormal, the route cannot be set, and it is determined that the default route is not configured, and a message of route configuration failure is sent.
[0069] If the route cannot be set, there is no need to obtain the target network protocol of the interface. Therefore, in the embodiment of the present application, only if there is a gateway in the network information and the state of the qga of the virtual machine is not abnormal, the target network protocol is obtained.
[0070] In an embodiment of the present application, the network information of the target network card is detected before the default route configuration to ensure that the network can smoothly perform the route configuration.
[0071] As an optional embodiment, after performing corresponding logical operations on current routes of multiple network cards according to the target network protocol, the method further includes:
[0072] Disconnect from the network;
[0073] Restart the network connection so that the configuration properties after the logical operation takes effect.
[0074] Optionally, after using NetworkManager to change the default routing properties of a network connection, you need to disconnect the network connection and then restart the connection for the configuration properties to take effect. You can do this by executing the restart command: nmcli c up command.
[0075] As an optional embodiment, the method further includes:
[0076] When the configuration validity check value of the default route indicates that the route configuration is not effective, it is determined that the default route is not fully configured, and information about the route configuration failure is sent.
[0077] Optionally, in the embodiment of the present application, the verification standard for whether the configuration of the default route is effective is: input the command: ip route|grep default and ip-6route|grep default; if the current route is consistent with the specified default route, the route setting is successful, otherwise the route setting fails. According to the configuration result, a corresponding configuration effectiveness verification value is given, and if the default route is not configured, a message indicating that the route configuration has failed is sent.
[0078] In the embodiment of the present application, a step is provided to verify whether the default routing configuration is effective. After the configuration fails, a configuration failure message is sent to the user to ensure timely synchronization of information.
[0079] As an optional embodiment, Figure 3 As shown, the embodiment of the present application provides an optional virtual machine automatic configuration routing scheduling process diagram, including the following process:
[0080] start;
[0081] Specify the network card for setting the default route;
[0082] Verify whether the network has a gateway;
[0083] If yes, check the qga status; if no, setting the default route fails;
[0084] When checking the qga status, if no abnormality occurs, the current interface network protocol is determined; if an abnormality occurs, setting the default route fails;
[0085] When the interface network protocol is IPV4, NetworkManager turns off all non-specified IPV4 network card routing configurations; NetworkManager turns on all specified IPV4 network card routing configurations; and verifies the virtual machine IPV4 default routing;
[0086] When the interface network protocol is IPV6, NetworkManager turns off all non-specified IPV6 network card routing configurations; NetworkManager turns on all specified IPV6 network card routing configurations; verifies the virtual machine IPV6 default routing;
[0087] If the route is correct after verification, the route configuration is completed; if the route is wrong after verification, the user is prompted that the default route setting failed.
[0088] As an optional embodiment, the embodiment of the present application sets four application scenarios based on the various embodiments of the method for automatically configuring routing for a virtual machine described above:
[0089] Scenario a: When creating a virtual machine, if the user selects multiple network cards, then you need to specify one of the network cards to set the network as the default route.
[0090] 1) When creating a virtual machine, the user specifies the network and subnet configured to set the default route from the page.
[0091] 2) Check whether the subnet of the specified network has a gateway set up. If there is no gateway, the default route cannot be set.
[0092] 3) Create a network port for the virtual machine by specifying the network and subnet.
[0093] 4) Create a virtual machine. After the virtual machine is successfully created, bind the network card created in the previous step to the port on the virtual machine (which can be understood as plugging a network card into the computer).
[0094] 5) After configuring the default route virtual machine through NetworkManager and binding the network card, start executing Figure 3 The scheduling process of automatically configuring routing for virtual machines.
[0095] Scenario b: After the virtual machine has been used for a period of time, a new network card needs to be added to the virtual machine; after the new network card is added, the default route also needs to be reconfigured.
[0096] 1) Specify the network and subnet where the new network card is located from the page.
[0097] 2) Check whether the subnet of the specified network has a gateway set up. If there is no gateway, the default route cannot be set.
[0098] 3) Create a network card for the virtual machine through the specified network and subnet, and bind the network card to the virtual machine.
[0099] 4) After the virtual machine is bound to the network card, start executing Figure 3 The scheduling process of automatically configuring routing for virtual machines.
[0100] Scenario c: Change the default route: During the use of the virtual machine, you need to switch the default route to another network card.
[0101] 1) Check whether the subnet where the specified network card is located has a gateway set up. A network card without a gateway cannot be switched.
[0102] 2) Start execution Figure 3 The scheduling process of automatically configuring routing for virtual machines.
[0103] Scenario d: Uninstall the network card and set the route: When using the virtual machine, you need to uninstall a network card (meaning unplugging a network card from the computer). At this time, if the uninstalled network card is the network card where the default route is located, you need to reset the default route.
[0104] 1) Check whether the uninstalled network card is the network card where the default route is located.
[0105] 2) If yes, select a new network card from the remaining network cards, and the subnet where the network card is located must be configured with a network card; if not, there is no need to continue.
[0106] 3) Start execution Figure 3 The scheduling process of automatically configuring routing for virtual machines.
[0107] In the above application scenarios, when a virtual machine is bound to multiple network cards, there is no need to manually configure the default route, which simplifies the network configuration operation. If you need to change the route, you can select the network card switch on the page. There is no need to enter the system and set it through commands. Non-professional network personnel can operate it. After uninstalling a network card, the system will automatically select a configuration route from the remaining network cards without human intervention.
[0108] The above operations can be completed on the cloud management platform without the intervention of operation and maintenance personnel.
[0109] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0110] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM (Read-Only Memory) / RAM (Random Access Memory), a magnetic disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods of each embodiment of the present application.
[0111] According to another aspect of the embodiments of the present application, a device for automatically configuring routing for a virtual machine for implementing the above-mentioned method for automatically configuring routing for a virtual machine is also provided. Figure 4 is a structural block diagram of an optional device for automatically configuring routing for a virtual machine according to an embodiment of the present application, such as Figure 4 As shown, the device may include:
[0112] The first acquisition module 401 is used to acquire network information of a target network card in a virtual machine, wherein the route of the target network card is a preset default route;
[0113] The second acquisition module 402 is used to acquire the target network protocol corresponding to the interface of the target network card according to the network information;
[0114] An execution module 403 is used to perform corresponding logic operations on the current routes of the multiple network cards according to the target network protocol, wherein the logic operation is to perform a closing or opening operation on the route configuration of the network card;
[0115] The determination module 404 is used to determine the automatic configuration result of the default route according to the logical operation and the configuration validity verification value of the default route.
[0116] It should be noted that the first acquisition module 401 in this embodiment can be used to execute the above step S101, the second acquisition module 402 in this embodiment can be used to execute the above step S102, the execution module 403 in this embodiment can be used to execute the above step S103, and the determination module 404 in this embodiment can be used to execute the above step S104.
[0117] Through the above module, by obtaining the default route target network card of the virtual machine, according to the target network protocol of the target network card, the current route configuration of multiple network cards is automatically closed or opened, and at the same time, according to the configuration effectiveness verification value of the default route, the final automatic configuration result of the default route is determined. The above operations can be completed on the cloud management platform without the intervention of operation and maintenance personnel, eliminating manpower, and realizing the automation of default route configuration, thereby solving the problem in the related technology that when there are multiple network interfaces on a virtual machine, redundant default routes need to be manually deleted and the setting of deleting the default route cannot be persisted, wasting a lot of human resources.
[0118] As an optional embodiment, the execution module includes:
[0119] A closing operation unit, used for executing a closing operation on the routing configuration of the current routing of the network card when the network protocol of the interface of the network card is not the target network protocol;
[0120] The opening operation unit is used to perform an opening operation on the routing configuration of the current routing of the network card when the network protocol of the interface of the network card is the target network protocol.
[0121] As an optional embodiment, the first determining module includes:
[0122] The determination unit is used to determine that the default route is configured and send information that the route configuration is successful when the opened route configuration is the route configuration corresponding to the default route and the configuration validity check value of the default route indicates that the route configuration has taken effect.
[0123] As an optional embodiment, the device further includes:
[0124] A verification module is used to verify whether the state of the running daemon process of the gateway or virtual machine in the network information of the target network card is abnormal before obtaining the target network protocol corresponding to the interface of the target network card according to the network information;
[0125] The third acquisition module is used to acquire the target network protocol if there is a gateway in the network information and the status of the running daemon process of the virtual machine is normal.
[0126] As an optional embodiment, the device further includes:
[0127] The second determination module is used to verify whether there is an abnormal state of the running daemon process of the gateway or virtual machine in the network information of the target network card. If there is no abnormal state of the running daemon process of the gateway or virtual machine in the network information, it is determined that the default route is not configured and a message of route configuration failure is sent.
[0128] As an optional embodiment, the device further includes:
[0129] A disconnection module, used to disconnect the network connection after performing corresponding logical operations on the current routes of the multiple network cards according to the target network protocol;
[0130] The restart module is used to restart the network connection so that the configuration properties after the logical operation takes effect.
[0131] As an optional embodiment, the device further includes:
[0132] The third determination module is used to determine that the default route is not configured and send information that the route configuration fails when the configuration validity check value of the default route indicates that the route configuration is not effective.
[0133] According to another aspect of the embodiments of the present application, an electronic device for implementing the above-mentioned method for automatically configuring routing of a virtual machine is also provided. The electronic device may be a server, a terminal, or a combination thereof.
[0134] Figure 5 is a structural block diagram of an optional electronic device according to an embodiment of the present application, such as Figure 5 As shown, it includes a processor 501, a communication interface 502, a memory 503 and a communication bus 504, wherein the processor 501, the communication interface 502 and the memory 503 communicate with each other through the communication bus 504, wherein,
[0135] Memory 503, used for storing computer programs;
[0136] The processor 501 is used to execute the computer program stored in the memory 503 to implement the following steps:
[0137] Obtain network information of the target network card in the virtual machine, wherein the route of the target network card is a preset default route;
[0138] Obtain the target network protocol corresponding to the interface of the target network card according to the network information;
[0139] Perform corresponding logic operations on the current routes of the multiple network cards according to the target network protocol, wherein the logic operation is to perform a closing or opening operation on the route configuration of the network card;
[0140] The automatic configuration result of the default route is determined according to the logical operation and the configuration validity verification value of the default route.
[0141] Optionally, in this embodiment, the communication bus may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0142] The communication interface is used for communication between the above electronic device and other devices.
[0143] The memory may include RAM, or may include non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0144] As an example, Figure 5 As shown, the memory 503 may include, but is not limited to, the first acquisition module 401, the second acquisition module 402, the execution module 403, and the determination module 404 in the device for automatically configuring routing for the virtual machine. In addition, other module units in the device for automatically configuring routing for the virtual machine may also be included but are not limited to, which will not be described in detail in this example.
[0145] The above-mentioned processor can be a general-purpose processor, which can include but not be limited to: CPU (Central Processing Unit), NP (Network Processor), etc.; it can also be DSP (Digital Signal Processing), ASIC (Application Specific Integrated Circuit), FPGA (Field-Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0146] In addition, the electronic device mentioned above further comprises: a display for displaying the result of the automatic configuration of the routing of the virtual machine.
[0147] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment will not be described in detail here.
[0148] It can be understood by those skilled in the art that Figure 5The structure shown is for illustration only. The device for implementing the above-mentioned method of automatically configuring routing for a virtual machine may be a terminal device, which may be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile Internet device (Mobile Internet Devices, MID), a PAD, and other terminal devices. Figure 5 It does not limit the structure of the above electronic device. For example, the terminal device may also include Figure 5 More or fewer components (such as network interfaces, display devices, etc.) shown in, or having Figure 5 Different configurations shown.
[0149] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a computer-readable storage medium, which can include: a flash drive, ROM, RAM, a magnetic disk or an optical disk, etc.
[0150] According to another aspect of the embodiment of the present application, a storage medium is also provided. Optionally, in this embodiment, the storage medium can be used to execute the program code of the method for automatically configuring routing of a virtual machine.
[0151] Optionally, in this embodiment, the storage medium may be located on at least one network device among a plurality of network devices in the network shown in the above embodiment.
[0152] Optionally, in this embodiment, the storage medium is configured to store program codes for executing the following steps:
[0153] Obtain network information of the target network card in the virtual machine, wherein the route of the target network card is a preset default route;
[0154] Obtain the target network protocol corresponding to the interface of the target network card according to the network information;
[0155] Perform corresponding logic operations on the current routes of the multiple network cards according to the target network protocol, wherein the logic operation is to perform a closing or opening operation on the route configuration of the network card;
[0156] The automatic configuration result of the default route is determined according to the logical operation and the configuration validity verification value of the default route.
[0157] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, which will not be described in detail in this embodiment.
[0158] Optionally, in this embodiment, the storage medium may include, but is not limited to, various media that can store program codes, such as a USB flash drive, a ROM, a RAM, a mobile hard disk, a magnetic disk, or an optical disk.
[0159] According to another aspect of the embodiments of the present application, a computer program product or a computer program is also provided, which includes computer instructions, and the computer instructions are stored in a computer-readable storage medium; a processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method steps of automatically configuring routing of a virtual machine in any of the above embodiments.
[0160] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0161] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling one or more computer devices (which can be personal computers, servers or network devices, etc.) to execute all or part of the steps of the method for automatically configuring routing for virtual machines in various embodiments of the present application.
[0162] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0163] In the several embodiments provided in the present application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are only schematic, for example, the division of units is only a logical function division, and there may be other division methods in actual implementation, for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0164] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution provided in this embodiment.
[0165] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0166] The above are only preferred implementations of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A method for automatically configuring routing for a virtual machine, characterized in that: The method comprises: Obtain network information of the target network card in the virtual machine, wherein the route of the target network card is a preset default route; Obtain the target network protocol corresponding to the interface of the target network card according to the network information; Performing corresponding logical operations on the current routes of the multiple network cards according to the target network protocol, wherein the logical operation is to close or open the route configuration of the network card; performing corresponding logical operations on the current routes of the multiple network cards according to the target network protocol, including: when the network protocol of the interface of the network card is not the target network protocol, performing a closing operation on the route configuration of the current route of the network card; when the network protocol of the interface of the network card is the target network protocol, performing an opening operation on the route configuration of the current route of the network card; The automatic configuration result of the default route is determined according to the logical operation and the configuration validity verification value of the default route.
2. The method according to claim 1, characterized in that According to the logical operation and the configuration validation value of the default route, the automatic configuration result of the default route is determined, including: When the opened route configuration is the route configuration corresponding to the default route and the configuration effectiveness check value of the default route indicates that the route configuration has taken effect, it is determined that the default route has completed configuration, and information on successful route configuration is sent.
3. The method according to claim 1, characterized in that Before acquiring the target network protocol corresponding to the interface of the target network card according to the network information, the method further includes: Check whether there is a gateway in the network information of the target network card or whether the status of the running daemon process of the virtual machine is abnormal; If a gateway exists in the network information and the status of the running daemon process of the virtual machine is normal, the target network protocol is obtained.
4. The method according to claim 3, characterized in that After checking whether there is a gateway in the network information of the target network card or whether the state of the running daemon process of the virtual machine is abnormal, the method further includes: If there is no gateway in the network information or the state of the running daemon process of the virtual machine is abnormal, it is determined that the default route is not configured, and a message of route configuration failure is sent.
5. The method according to claim 1, characterized in that After performing corresponding logical operations on the current routes of the multiple network cards according to the target network protocol, the method further includes: Disconnect from the network; Restart the network connection so that the configuration properties after the logical operation takes effect.
6. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: When the configuration validity check value of the default route indicates that the route configuration is not effective, it is determined that the default route is not fully configured, and information about the route configuration failure is sent.
7. A device for automatically setting routing for a virtual machine, characterized in that: The device comprises: A first acquisition module is used to acquire network information of a target network card in a virtual machine, wherein the route of the target network card is a preset default route; A second acquisition module is used to acquire a target network protocol corresponding to the interface of the target network card according to the network information; An execution module is used to perform corresponding logical operations on the current routes of the multiple network cards according to the target network protocol, wherein the logical operation is to perform a closing or opening operation on the route configuration of the network card; performing corresponding logical operations on the current routes of the multiple network cards according to the target network protocol, including: when the network protocol of the interface of the network card is not the target network protocol, performing a closing operation on the route configuration of the current route of the network card; when the network protocol of the interface of the network card is the target network protocol, performing an opening operation on the route configuration of the current route of the network card; The determination module is used to determine the automatic configuration result of the default route according to the logical operation and the configuration validity verification value of the default route.
8. An electronic device comprising a processor, a communication interface, a memory and a communication bus, wherein: The processor, the communication interface and the memory communicate with each other via a communication bus, which is characterized in that: Memory for storing computer programs; A processor, configured to execute the method steps of any one of claims 1 to 6 by running a computer program stored in a memory.
9. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, wherein when the computer program is executed by a processor, the method steps in any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Multi-dialing method in edge computing scene, terminal and computer readable storage medium
CN111464403A
Implementation method, device and system of virtual machine network double stacks
CN111586196A