OpenStack Neutron loadbalance Source Parsing (i)

Source: Internet
Author: User
Tags haproxy

Statement:

This blog welcome reprint, but please keep the original author information, and please specify the source!

Lin Kai

Team: Huawei Hangzhou OpenStack Team


In the OpenStack grizzly release, the Neutron (then called quantum) component introduced a new network service: LoadBalancer (LBaaS), the framework and fundamentals of LoadBalancer have some good articles on the web, Don't dwell on it here. This article will loadbalancer code flow and implementation of the preliminary analysis, there will be errors and not rigorous place, need to be corrected.


Recommend some basic knowledge of the article to everyone, read after the source will be more clear:
http://blog.csdn.net/quqi99/article/details/9898139
Http://www.cnblogs.com/feisky/p/3853734.html
http://www.ustack.com/blog/neutron_loadbalance/


The basic use steps of the Neutron LoadBalancer are:
1) the tenant creates a pool with an initial number of member of 0;
2) the tenant creates one or more member within the pool
3) tenants Create one or more Health Monitor
4) The Tenant associates the health monitors with the pool
5) tenants create VIP with pool

First, let's look at what the code does when we create these pool, member, HealthMonitor, and VIPs.



Figure 1 LoadBalance Overall process framework

Requests from the tenant to create a pool are first sent to Lbaas plugin for processing, so our parsing of the code begins here as well. In the/neutron/services/loadbalancer/plugin.py we can see the corresponding Create_pool and other methods:


# pool as the root object of the LB v1, is the starting point of the workflow Def create_pool (self, Context, pool): provider_name = self._get_provider_name (Context, pool[' pool ') # DB created Pool object p = Super (Loadbalancerplugin, self). Create_pool (context, pool) Self.serv Ice_type_manager.add_resource_association (context, constants. LoadBalancer, provider_name, p[' id ') #need to add provider name to Pool Dict, #because provider Was wasn't known to DB plugin at pool creation p[' provider '] = provider_name Driver = Self.drivers[provider_nam E] Try: # call the drive in the default provider to create the pool Driver.create_pool (context, p) except LoadBalancer. Noeligiblebackend: # That should catch cases if backend of any kind # are not available (agent, app Liance, etc) self.update_status (context, LDB. Pool, p[' ID '], constants. ERROR, "No eligible backend") RaisE LoadBalancer. Noeligiblebackend (pool_id=p[' id ')) return p




where Driver.create_pool (context, p) is the key method
Driver = Self.drivers[provider_name], the corresponding driver is called according to the provider settings in the configuration file.

In neutron.conf, you can see that the default setting is:

Service_provider=loadbalancer:haproxy:neutron.services.loadbalancer.drivers.haproxy.plugin_driver. Haproxyonhostplugindriver:default


so jump to the/neutron/services/loadbalancer/haproxy/plugin_driver.py:
Class Haproxyonhostplugindriver (Agent_driver_base. Agentdriverbase):    device_driver = Namespace_driver. Driver_name


There is no Create_pool method in this class, so go to his parent class agentdriverbase to see:
def create_pool (self, Context, pool):        # First assign Agent Agent Scheduler by Agent        = Self.pool_scheduler.schedule ( Self.plugin, context, pool,                                             self.device_driver)        if not agent:            raise Lbaas_agentscheduler. Noeligiblelbaasagent (pool_id=pool[' id ')        self.agent_rpc.create_pool (context, pool, agent[' host '),                                   Self.device_driver)




Here first through the Agent scheduler Distribution Agent, see the specific implementation method:
def schedule (self, plugin, context, pool, device_driver): # Assigns an active LoadBalancer agent to the pool if it does not have an enabled agent on it                With Context.session.begin (subtransactions=true): Lbaas_agent = Plugin.get_lbaas_agent_hosting_pool ( Context, pool[' id ')) if Lbaas_agent:LOG.debug (_ (' Pool% (pool_id) s has already been hos                           Ted ' by Lbaas agent% (agent_id) s '), {' pool_id ': pool[' id '], ' agent_id ': lbaas_agent[' id ']}) return # Gets the active agent Active_agen TS = plugin.get_lbaas_agents (context, active=true) if not Active_agents:LOG.warn (_ (' No active L Baas agents for Pool%s '), pool[' id ']) return # agent candidates based on Device_driver filtering candidate = Plugin.get_lbaas_agent_candidates (Device_driver, active_agents ) If not candIdates:LOG.warn (_ (' No Lbaas agent supporting device driver%s '), Device_driver) Return # randomly selects a suitable candidate agent chosen_agent = random.choice (candidates) # with pool Bind binding = poolloadbalanceragentbinding () binding.agent = Chosen_agent binding.pool_id                        = pool[' id '] context.session.add (binding) Log.debug (_ (' Pool% (pool_id) s is scheduled to ' ' Lbaas agent% (agent_id) s '), {' pool_id ': pool[' id '], ' agent_id ': C hosen_agent[' ID '}) return chosen_agent




We were just in the plugindriver of Haproxy, we know:
Device_driver = Namespace_driver. Driver_name


So the agent chosen according to Device_driver is the namespace_driver of Haproxy, and the request to create the pool is forwarded to Device_driver (Haproxynsdriver) through the agent, This process is not directly one step, where the agent sends an RPC asynchronous request, at which point Agent_manager receives the request
def create_pool (self, context, pool, driver_name):        if driver_name not in Self.device_drivers:            log.error (_ (' No Device driver on Agent:%s. '), driver_name)            self.plugin_rpc.update_status (' pool ', pool[' id '), constants. ERROR)            return        # get the corresponding driver (default to Haproxynsdriver according to settings)        Driver = Self.device_drivers[driver_name]        try :            driver.create_pool (pool)        except Exception:            self._handle_failed_driver_call (' Create ', ' pool ', pool[' Id '],                                            driver.get_name ())        else:            self.instance_mapping[pool[' id ']] = driver_name            # After updating the state in the database            self.plugin_rpc.update_status (' pool ', pool[' id '), constants. ACTIVE)




The Create_pool function in Haproxynsdriver is called here, and the corresponding method is found in the namespace_driver.py of Haproxy:
def create_pool (self, Pool):        # Anything to does here because a pool needs a VIP to be useful        # when no VIP is in the case, do not do the operation.        Pass




The creation process of Member,healthmonitor and VIP is similar, and can be analyzed by reference to this process.


At this point, the first part of Lbaas's code parsing is finished, and the next part of the content is expected.

OpenStack Neutron loadbalance Source Parsing (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.