Method and device for configuring virtual machine networkTechnical Field
The present application relates to the field of virtual machines, and more particularly, to a method and apparatus for configuring a virtual machine network.
Background
In terms of network management of a virtual machine, generally, an IP address of the virtual machine is obtained by using a DHCP (Dynamic host configuration Protocol) and recorded in a Neutron database. The IP obtaining mode of the virtual machine obtains the metadata of the IP address of the virtual machine from the Neutron server through a cloud-init tool, and the metadata is injected into the virtual machine operating system when the virtual machine is initially created and started. However, this method only works when the virtual machine is first created, and after the virtual machine has been operated, if a network card is dynamically added to the virtual machine, the virtual machine cannot normally acquire a new address, and the virtual machine cannot automatically set a static route and a default route when the virtual machine has multiple network cards, which may cause route confusion. Therefore, the virtual machine needs to be reset after logging in, and the processing mode is not suitable for large-scale cloud environment.
Disclosure of Invention
In order to solve the above technical problem, the present application provides a method and an apparatus for configuring a virtual machine network, which can set and update a network route of a virtual machine without logging in the virtual machine to modify routing information after the virtual machine runs, and use another network card to route data.
In order to achieve the object of the present invention, an embodiment of the present invention provides a method for configuring a virtual machine network, where the method includes:
when a computing node network agent in a computing node receives a network change request sent by a Neutron server, the computing node network agent updates flow table information of a virtual switch Openvswitch of the computing node according to a static routing table stored in the Neutron server so as to ensure that a virtual machine in the computing node correctly sends a data packet to the virtual switch;
and updating a routing table inside the virtual machine by a cloud host network agent of the virtual machine in the computing node according to the routing information acquired from the Neutron server, so that the routing information inside the virtual machine is matched with the flow table information of the Openvswitch, and the virtual machine sends the data packet to a specified gateway through a network card selected according to the routing information.
Further, in an optional embodiment, the network change request is a request for switching one network card of the multiple network cards of the virtual machine to another network card, or a request for switching the network card of the virtual machine to a network card added for the virtual machine.
Further, in an optional embodiment, if the network change request is a request to switch one of the network cards of the virtual machine to another network card, the network change request includes a request to set the IP address, the mac address, and the default routing information of the network card of the virtual machine to the IP address, the mac address, and the corresponding routing information of the switched network card, respectively.
Further, in an optional embodiment, if the network change request is a request to switch the network card of the virtual machine to the network card added to the virtual machine, the network change request includes a request to set the IP address and mac address of the network card of the virtual machine and the default routing information of the virtual machine to the IP address and mac address of the added network card and the corresponding routing information.
Further, in an optional embodiment, a plurality of static routing tables are maintained in the Neutron server before the step of updating, by the compute node network agent, the flow table information of the virtual switch Openvswitch of the compute node according to the static routing tables maintained in the Neutron server; each static routing table sets a routing rule for a corresponding virtual machine network, so that one virtual machine accesses one of the multiple networks through one network card of the virtual machine.
To achieve the object of the present invention, an embodiment of the present invention provides an apparatus for configuring a virtual machine network, the apparatus including a memory and a processor,
the memory is for storing computer readable instructions;
the processor is configured to execute the computer-readable instructions to perform operations comprising:
when a computing node network agent in a computing node receives a network change request sent by a Neutron server, the computing node network agent updates flow table information of a virtual switch Openvswitch of the computing node according to a static routing table stored in the Neutron server so as to ensure that a virtual machine in the computing node correctly sends a data packet to the virtual switch;
and updating a routing table inside the virtual machine by a cloud host network agent of the virtual machine in the computing node according to the routing information acquired from the Neutron server, so that the routing information inside the virtual machine is matched with the flow table information of the Openvswitch, and the virtual machine sends the data packet to a specified gateway through a network card selected according to the routing information.
Further, in an optional embodiment, the network change request is a request for switching one network card of the multiple network cards of the virtual machine to another network card, or a request for switching the network card of the virtual machine to a network card added for the virtual machine.
Further, in an optional embodiment, if the network change request is a request to switch one of the network cards of the virtual machine to another network card, the network change request includes a request to set the IP address, the mac address, and the default routing information of the network card of the virtual machine to the IP address, the mac address, and the corresponding routing information of the switched network card, respectively.
Further, in an optional embodiment, if the network change request is a request to switch the network card of the virtual machine to the network card added to the virtual machine, the network change request includes a request to set the IP address and mac address of the network card of the virtual machine and the default routing information of the virtual machine to the IP address and mac address of the added network card and the corresponding routing information.
Further, in an optional embodiment, a plurality of static routing tables are maintained in the Neutron server before the step of updating, by the compute node network agent, the flow table information of the virtual switch Openvswitch of the compute node according to the static routing tables maintained in the Neutron server; each static routing table sets a routing rule for a corresponding virtual machine network, so that one virtual machine accesses one of the multiple networks through one network card of the virtual machine.
The method and the device have the advantages that after the network change request is received by the network agent of the computing node, the flow table information of the virtual switch of the computing node is updated according to the static routing table stored in the Neutron server, and the routing table in the virtual machine is updated by the network agent of the cloud host of the virtual machine according to the routing information acquired from the Neutron server, so that after the virtual machine runs, the network routing of the virtual machine can be set and updated, other network cards can be used for routing data, the virtual machine does not need to be logged in to modify the routing information, and the management efficiency of the virtual machine network of the OpenStack platform is improved. Meanwhile, the network routing information can be updated without logging in a virtual machine, and the safety of the cloud host is improved.
Additional features and advantages of the invention will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. The objectives and other advantages of the invention will be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.
Drawings
The accompanying drawings are included to provide a further understanding of the invention and are incorporated in and constitute a part of this specification, illustrate embodiments of the invention and together with the example serve to explain the principles of the invention and not to limit the invention.
Fig. 1 is a flowchart of a method for configuring a virtual machine network according to an embodiment of the present invention;
fig. 2 is a block diagram of an apparatus for configuring a virtual machine network according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, embodiments of the present invention will be described in detail below with reference to the accompanying drawings. It should be noted that the embodiments and features of the embodiments in the present application may be arbitrarily combined with each other without conflict.
The steps illustrated in the flow charts of the figures may be performed in a computer system such as a set of computer-executable instructions. Also, while a logical order is shown in the flow diagrams, in some cases, the steps shown or described may be performed in an order different than here.
Openstack is used as an open-source cloud computing management platform, and can very conveniently manage various virtualization platform resources, and in terms of network management of virtual machines, generally, IP addresses of the virtual machines are acquired in a DHCP manner and recorded in a Neutron database. The IP obtaining mode of the virtual machine obtains the metadata of the IP address of the virtual machine from the Neutron server through the cloud-init, and the metadata is injected into the virtual machine operating system when the virtual machine is initially created and started. However, this method only works when the virtual machine is first created, and after the virtual machine has been operated, if a network card is dynamically added to the virtual machine, the virtual machine cannot normally acquire a new address, and the virtual machine cannot automatically set a static route and a default route when the virtual machine has multiple network cards, which may cause route confusion. Therefore, the virtual machine needs to be reset after logging in, and the processing mode is not suitable for large-scale cloud environment.
In order to solve the above problem, in one aspect, an embodiment of the present invention provides a method for configuring a virtual machine network, as shown in fig. 1, the method includes steps S101 to S103.
Step S101, when a computing node network agent in a computing node receives a network change request sent by a Neutron server, the computing node network agent updates flow table information of a virtual switch Openvswitch of the computing node according to a static routing table stored in the Neutron server so as to ensure that a virtual machine in the computing node correctly sends a data packet to the virtual switch.
Step S103, updating a routing table inside the virtual machine by a cloud host network agent of the virtual machine in the computing node according to the routing information acquired from the Neutron server, so that the routing information inside the virtual machine is matched with the flow table information of the Openvswitch, and the virtual machine sends the data packet to a specified gateway through a network card selected according to the routing information.
The method and the device have the advantages that after the network change request is received by the network agent of the computing node, the flow table information of the virtual switch of the computing node is updated according to the static routing table stored in the Neutron server, and the routing table in the virtual machine is updated by the network agent of the cloud host of the virtual machine according to the routing information acquired from the Neutron server, so that after the virtual machine runs, the network routing of the virtual machine can be set and updated, other network cards can be used for routing data, the virtual machine does not need to be logged in to modify the routing information, and the management efficiency of the virtual machine network of the OpenStack platform is improved. Meanwhile, the network routing information can be updated without logging in a virtual machine, and the safety of the cloud host is improved.
Further, in an optional embodiment, the network change request is a request for switching one network card of the multiple network cards of the virtual machine to another network card, or a request for switching the network card of the virtual machine to a network card added for the virtual machine.
Based on the foregoing optional embodiments, further, in an optional embodiment, if the network change request is a request to switch one network card of the multiple network cards of the virtual machine to another network card, the network change request includes a request to set an IP address and a mac address of the network card of the virtual machine and default routing information of the virtual machine as an IP address and a mac address of the switched network card and corresponding routing information, respectively.
Based on the foregoing optional embodiments, further, in an optional embodiment, if the network change request is a request to switch the network card of the virtual machine to the network card added to the virtual machine, the network change request includes a request to set the IP address and mac address of the network card of the virtual machine and the default routing information of the virtual machine as the IP address and mac address of the network card added and the corresponding routing information.
Further, in an optional embodiment, a plurality of static routing tables are maintained in the Neutron server before the step of updating, by the compute node network agent, the flow table information of the virtual switch Openvswitch of the compute node according to the static routing tables maintained in the Neutron server; each static routing table sets a routing rule for a corresponding virtual machine network, so that one virtual machine accesses one of the multiple networks through one network card of the virtual machine.
In order to solve the above technical problem, an embodiment of the present invention provides an apparatus for configuring a virtual machine network, which includes amemory 10 and aprocessor 20, as shown in fig. 2.
Amemory 10 for storing computer readable instructions;
aprocessor 20 for executing computer readable instructions to perform the following operations:
when a computing node network agent in a computing node receives a network change request sent by a Neutron server, the computing node network agent updates flow table information of a virtual switch Openvswitch of the computing node according to a static routing table stored in the Neutron server so as to ensure that a virtual machine in the computing node correctly sends a data packet to the virtual switch;
and updating a routing table inside the virtual machine by a cloud host network agent of the virtual machine in the computing node according to the routing information acquired from the Neutron server, so that the routing information inside the virtual machine is matched with the flow table information of the Openvswitch, and the virtual machine sends the data packet to a specified gateway through a network card selected according to the routing information.
The method and the device have the advantages that after the network change request is received by the network agent of the computing node, the flow table information of the virtual switch of the computing node is updated according to the static routing table stored in the Neutron server, and the routing table in the virtual machine is updated by the network agent of the cloud host of the virtual machine according to the routing information acquired from the Neutron server, so that after the virtual machine runs, the network routing of the virtual machine can be set and updated, other network cards can be used for routing data, the virtual machine does not need to be logged in to modify the routing information, and the management efficiency of the virtual machine network of the OpenStack platform is improved. Meanwhile, the network routing information can be updated without logging in a virtual machine, and the safety of the cloud host is improved.
Further, in an optional embodiment, the network change request is a request for switching one network card of the multiple network cards of the virtual machine to another network card, or a request for switching the network card of the virtual machine to a network card added for the virtual machine.
Based on the foregoing optional embodiments, further, in an optional embodiment, if the network change request is a request to switch one network card of the multiple network cards of the virtual machine to another network card, the network change request includes a request to set an IP address and a mac address of the network card of the virtual machine and default routing information of the virtual machine as an IP address and a mac address of the switched network card and corresponding routing information, respectively.
Based on the foregoing optional embodiments, further, in an optional embodiment, if the network change request is a request to switch the network card of the virtual machine to the network card added to the virtual machine, the network change request includes a request to set the IP address and mac address of the network card of the virtual machine and the default routing information of the virtual machine as the IP address and mac address of the network card added and the corresponding routing information.
Further, in an optional embodiment, a plurality of static routing tables are maintained in the Neutron server before the step of updating, by the compute node network agent, the flow table information of the virtual switch Openvswitch of the compute node according to the static routing tables maintained in the Neutron server; each static routing table sets a routing rule for a corresponding virtual machine network, so that one virtual machine accesses one of the multiple networks through one network card of the virtual machine.
Although the embodiments of the present invention have been described above, the above description is only for the convenience of understanding the present invention, and is not intended to limit the present invention. It will be understood by those skilled in the art that various changes in form and details may be made therein without departing from the spirit and scope of the invention as defined by the appended claims.