Esempio n. 1
0
    def create_pool(self, context, pool):
        provider_name = self._get_provider_name(context, pool['pool'])
        p = super(LoadBalancerPlugin, self).create_pool(context, pool)

        self.service_type_manager.add_resource_association(
            context, constants.LOADBALANCER, provider_name, p['id'])
        #need to add provider name to pool dict,
        #because provider was not known to db plugin at pool creation
        p['provider'] = provider_name
        driver = self.drivers[provider_name]
        try:
            driver.create_pool(context, p)
        except loadbalancer.NoEligibleBackend:
            # that should catch cases when backend of any kind
            # is not available (agent, appliance, etc)
            self.update_status(context, ldb.Pool, p['id'], constants.ERROR,
                               "No eligible backend")
            raise loadbalancer.NoEligibleBackend(pool_id=p['id'])
        return p
    def create_pool(self, context, pool):
        provider_name = self._get_provider_name(context, pool['pool'])
        p = super(LoadBalancerPlugin, self).create_pool(
            context,
            pool)  ## DB中创建pool对象,该行代码执行完后数据库即有记录,其中status=PENDING_CREATE

        self.service_type_manager.add_resource_association(
            context, constants.LOADBALANCER, provider_name, p['id'])
        #need to add provider name to pool dict,
        #because provider was not known to db plugin at pool creation
        p['provider'] = provider_name  #provider_name为string类型的'haproxy'
        driver = self.drivers[
            provider_name]  #service_provider=LOADBALANCER:Haproxy:neutron.services.loadbalancer.drivers.haproxy.plugin_driver.HaproxyOnHostPluginDriver:default
        try:
            driver.create_pool(
                context, p
            )  #neutron/services/loadbalancer/drivers/common/agent_driver_base.py line372 create_pool
        except loadbalancer.NoEligibleBackend:
            # that should catch cases when backend of any kind
            # is not available (agent, appliance, etc)
            self.update_status(context, ldb.Pool, p['id'], constants.ERROR,
                               "No eligible backend")  #更新数据库
            raise loadbalancer.NoEligibleBackend(pool_id=p['id'])
        return p