Method for automatically distributing subnet IP addresses by Openstack cloud host
Patent Information
- Application Number
- CN202411893804.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-20
- Publication Date
- 2025-04-08
AI Technical Summary
虽然openstack云主机ip地址的分配提供了手动指定ip地址(静态ip)以及指定虚拟网络由DHCP服务自动分配(动态ip)两种方式,但是指定ip地址的方法可能出现指定的ip地址已经被占用的问题,而自动分配的方法又无法指定子网
本发明采用以上技术方案,具有如下技术效果:1)简化网络管理,自动分配IP地址可以大幅简化网络管理工作。管理员不需要手动为每台虚拟机分配特定的IP地址,这种方式降低了手动分配IP地址时出错的风险,例如重复分配或分配无效的IP。2)避免IP地址冲突,通过自动分配,可确保每台虚拟机获得唯一的IP地址,有效避免IP地址冲突问题。3)快速部署,自动分配IP地址可以加快虚拟机的部署过程。用户只需要指定子网其他网络配置则由系统自动配置处理。4)支持多环境管理,在多租户环境中,每个租户可能使用不同的子网,或根据业务需求区分不用的子网,本发明能够在不同的子网中自动分配独立的IP地址,而不需要用户自己管理IP地址。这确保了每个用户的IP地址池是独立的,并防止用户之间出现IP冲突。
Smart Images

Figure CN119788645A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of Internet, and in particular to a method for automatically allocating subnet IP addresses to an Openstack cloud host. Background Art
[0002] OpenStack is an open source cloud computing platform for building and managing public and private clouds. It provides a set of collaborative services that enable users to manage and automate computing, storage, and network resources through a unified interface. As business scenarios become increasingly complex, cloud host IP addresses often need to be distinguished from different network segments. Administrators need to assign IP addresses of different network segments to cloud hosts based on different businesses. Although the allocation of openstack cloud host IP addresses provides two methods: manually specifying IP addresses (static IP) and specifying virtual networks to be automatically allocated by DHCP services (dynamic IP), the method of specifying IP addresses may cause the specified IP address to be occupied, and the automatic allocation method cannot specify the subnet. Obviously, the two methods provided by openstack are no longer sufficient to meet the increasingly complex needs.
[0003] During the process of creating a virtual machine, the IP address of the virtual machine can only be automatically allocated by specifying a specific network, or by manually specifying the IP address under a specific subnet by specifying a network. It cannot be automatically allocated by specifying a subnet, which lacks flexibility. Summary of the invention
[0004] The purpose of the present invention is to provide a method for automatically allocating subnet IP addresses for Openstack cloud hosts, which can improve the flexibility of cloud host IP address allocation. Users can divide different subnets according to different business needs to achieve automatic allocation of IP addresses of designated subnets for cloud hosts.
[0005] The technical solution adopted by the present invention is: The method for automatically allocating subnet IP addresses to the Openstack cloud host includes the following steps: Step 1: Receive a request to create a cloud host and obtain the virtual network ID and subnet ID in the request parameters; Step 2: Query the subnet ID number under the corresponding virtual network according to the virtual network ID number, and determine whether the subnet ID number in the request parameter is under the current virtual network; if so, execute step 3; otherwise, end; Step 3: Query the IP address pool under the corresponding subnet according to the subnet ID number; Step 4: Get the available unoccupied IP set of the subnet according to the IP address pool; Step 5: Determine whether the obtained subnet unoccupied IP address set is an empty set; if so, end; otherwise, execute step 6; Step 6: Select an IP address from the unoccupied IP set of the subnet, call the create cloud host interface, and specify the cloud host's IP as the selected IP address.
[0006] Furthermore, step 4 specifically includes the following steps: Step 401: call netaddr to obtain the range set of the IP address pool; Step 402: query all ports according to the ID number of the virtual network to obtain a port set; Step 403: Circulate the port set, filter out the ports of the current subnet according to the subnet ID number, and obtain the IP set that has been occupied by the current subnet; Step 403: Calculate the difference between the range set of the IP address pool and the set of IP addresses that are currently occupied in the subnet by using the set difference method to obtain the set of IP addresses that are not occupied in the subnet.
[0007] Furthermore, in step 6, a random strategy is adopted to obtain an IP address; The present invention adopts the above technical solution and has the following technical effects: 1) Simplify network management. Automatic allocation of IP addresses can greatly simplify network management work. The administrator does not need to manually allocate a specific IP address for each virtual machine. This method reduces the risk of errors when manually allocating IP addresses, such as repeated allocation or allocation of invalid IPs. 2) Avoid IP address conflicts. Through automatic allocation, it can be ensured that each virtual machine obtains a unique IP address, effectively avoiding the problem of IP address conflicts. 3) Quick deployment. Automatic allocation of IP addresses can speed up the deployment process of virtual machines. Users only need to specify the subnet and other network configurations will be automatically configured and processed by the system. 4) Support multi-environment management. In a multi-tenant environment, each tenant may use a different subnet, or distinguish between unused subnets according to business needs. The present invention can automatically allocate independent IP addresses in different subnets without the need for users to manage IP addresses themselves. This ensures that the IP address pool of each user is independent and prevents IP conflicts between users. BRIEF DESCRIPTION OF THE DRAWINGS
[0008] The present invention is further described in detail below with reference to the accompanying drawings and specific embodiments; Figure 1 A schematic diagram of a method for automatically allocating subnet IP addresses to an Openstack cloud host of the present invention; Figure 2 A flowchart for obtaining a set of available unassigned IP addresses. DETAILED DESCRIPTION
[0009] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, 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.
[0010] Openstack can allocate and manage IP addresses through specific network components. Neutron provides two ways to allocate IP addresses to cloud hosts: dynamic IP and static IP. However, both solutions have their pros and cons. Dynamic IP cannot specify a subnet, and static IP cannot determine whether the IP is occupied or whether the IP address is valid.
[0011] like Figure 1 As shown in 2, the present invention discloses a method for automatically allocating subnet IP addresses to an Openstack cloud host, which includes the following steps: Step 1: Receive the request to create a cloud host and obtain the virtual network ID number networks_uuid and subnet ID number networks_subsent_id in the request parameters Step 2: Query the subnet ID number under the virtual network according to networks_uuid, and determine whether the networks_subsent_id in the request parameter is under the current virtual network. If so, jump to step 3 Step 3: Query the IP address pool under the subnet based on networks_subsent_id Step 4: Get the available unassigned IP address set according to the IP address pool. Step 4 is as follows: Step 401: Call netaddr to obtain the range set ip_set of the IP address pool Step 402: Query all ports according to networks_uuid to obtain the port set port_list Step 403: loop port_list, filter out the ports of the current subnet according to networks_subsent_id, and obtain the ip set ip_bound_set that has been occupied by the current subnet Step 403: Calculate the difference between ip_set and ip_bound_set by using the set difference method to obtain the unoccupied ip set ip_unbound_set of the subnet Step 5: Determine whether the obtained ip_unbound_set is an empty set. If it is not an empty set, jump to step 6 Step 6: Use a random strategy to obtain an IP address net_ip from ip_unbound_set, call the create cloud host interface, and specify the IP address of the cloud host as net_ip.
[0012] The specific application environment of the present invention is as follows: (1) Multi-tenant isolation network environment: In a multi-tenant environment, different tenants (users or projects) use their own independent virtual networks and subnet resources. It is necessary to ensure that the IP addresses between tenants do not conflict, and each tenant can dynamically create a cloud host according to its own needs. This solution can ensure that tenants obtain independent, conflict-free IP addresses in their respective subnets by automatically querying the IP address pool of the subnet and network, supporting multi-tenant isolation and reducing human intervention. (2) Temporary batch processing or task computing: An enterprise needs to perform batch processing tasks, such as big data analysis or temporary scientific computing tasks, and temporarily start a large number of cloud hosts to complete specific tasks. This solution can automatically allocate IP addresses to each temporary cloud host without the need for manual management by the administrator. After the task is completed, the IP address is automatically released, which is convenient for subsequent task deployment and resource recovery. (3) Large-scale automated deployment of cloud hosts: An enterprise or cloud service provider needs to quickly deploy a large number of cloud hosts in a short period of time. For example, in the case of peak e-commerce promotion activities or sudden traffic growth, a large number of virtual machines need to be temporarily started to handle traffic. This solution can automatically allocate an unoccupied IP address in an independent subnet to each cloud host, ensuring that the cloud host can be quickly put online and avoiding IP address conflicts, thereby improving deployment efficiency.
[0013] The present invention adopts the above technical solution and has the following technical effects: 1) Simplify network management. Automatic allocation of IP addresses can greatly simplify network management work. The administrator does not need to manually allocate a specific IP address for each virtual machine. This method reduces the risk of errors when manually allocating IP addresses, such as repeated allocation or allocation of invalid IPs. 2) Avoid IP address conflicts. Through automatic allocation, it can be ensured that each virtual machine obtains a unique IP address, effectively avoiding the problem of IP address conflicts. 3) Quick deployment. Automatic allocation of IP addresses can speed up the deployment process of virtual machines. Users only need to specify the subnet and other network configurations will be automatically configured and processed by the system. 4) Support multi-environment management. In a multi-tenant environment, each tenant may use a different subnet, or distinguish between unused subnets according to business needs. The present invention can automatically allocate independent IP addresses in different subnets without the need for users to manage IP addresses themselves. This ensures that the IP address pool of each user is independent and prevents IP conflicts between users.
[0014] Obviously, the described embodiments are part of the embodiments of the present application, rather than all of the embodiments. In the absence of conflict, the embodiments in the present application and the features in the embodiments can be combined with each other. The components of the embodiments of the present application generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the detailed description of the embodiments of the present application is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians of the art without making creative work are within the scope of protection of the present application.
Claims
1. The method for automatically allocating subnet IP addresses for Openstack cloud hosts is characterized by: It includes the following steps: Step 1: Receive a request to create a cloud host and obtain the virtual network ID and subnet ID in the request parameters; Step 2: Query the subnet ID number under the corresponding virtual network according to the virtual network ID number, and determine whether the subnet ID number in the request parameter is under the current virtual network; If yes, go to step 3; otherwise, end; Step 3: Query the IP address pool under the corresponding subnet according to the subnet ID number; Step 4: Get the available unoccupied IP set of the subnet according to the IP address pool; Step 5: Determine whether the obtained subnet unoccupied IP set is an empty set; If yes, then end; Otherwise, go to step 6; Step 6: Select an IP address from the unoccupied IP set of the subnet, call the create cloud host interface, and specify the cloud host's IP as the selected IP address.
2. The method for automatically allocating subnet IP addresses for an Openstack cloud host according to claim 1, characterized in that: Step 4 specifically includes the following steps: Step 401: call netaddr to obtain the range set of the IP address pool; Step 402: query all ports according to the ID number of the virtual network to obtain a port set; Step 403: Circulate the port set, filter out the ports of the current subnet according to the subnet ID number, and obtain the IP set that has been occupied by the current subnet; Step 403: Calculate the difference between the range set of the IP address pool and the set of IP addresses that are currently occupied in the subnet by using the set difference method to obtain the set of IP addresses that are not occupied in the subnet.
3. The method for automatically allocating subnet IP addresses for an Openstack cloud host according to claim 1, characterized in that: In step 6, a random strategy is adopted to obtain an IP address.