예제 #1
0
    def create_pool(self, context, pool):
        # This validation is because the new API version also has a resource
        # called pool and these attributes have to be optional in the old API
        # so they are not required attributes of the new.  Its complicated.
        if pool['pool']['lb_method'] == attrs.ATTR_NOT_SPECIFIED:
            raise loadbalancerv2.RequiredAttributeNotSpecified(
                attr_name='lb_method')
        if pool['pool']['subnet_id'] == attrs.ATTR_NOT_SPECIFIED:
            raise loadbalancerv2.RequiredAttributeNotSpecified(
                attr_name='subnet_id')

        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 lb_ext.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 lb_ext.NoEligibleBackend(pool_id=p['id'])
        return p
예제 #2
0
    def _create_port_for_load_balancer(self,
                                       context,
                                       lb_db,
                                       ip_address,
                                       network_id=None):
        if lb_db.vip_subnet_id:
            assign_subnet = False
            # resolve subnet and create port
            subnet = self._core_plugin.get_subnet(context, lb_db.vip_subnet_id)
            network_id = subnet['network_id']
            fixed_ip = {'subnet_id': subnet['id']}
            if ip_address and ip_address != n_const.ATTR_NOT_SPECIFIED:
                fixed_ip['ip_address'] = ip_address
            fixed_ips = [fixed_ip]
        elif network_id and network_id != n_const.ATTR_NOT_SPECIFIED:
            assign_subnet = True
            fixed_ips = n_const.ATTR_NOT_SPECIFIED
        else:
            attrs = _("vip_subnet_id or vip_network_id")
            raise loadbalancerv2.RequiredAttributeNotSpecified(attr_name=attrs)

        port_data = {
            'tenant_id': lb_db.tenant_id,
            'name': 'loadbalancer-' + lb_db.id,
            'network_id': network_id,
            'mac_address': n_const.ATTR_NOT_SPECIFIED,
            'admin_state_up': False,
            'device_id': lb_db.id,
            'device_owner': n_const.DEVICE_OWNER_LOADBALANCERV2,
            'fixed_ips': fixed_ips
        }

        port = self._core_plugin.create_port(context, {'port': port_data})
        lb_db.vip_port_id = port['id']

        if assign_subnet:
            fixed_ip = self._create_port_choose_fixed_ip(port['fixed_ips'])
            lb_db.vip_address = fixed_ip['ip_address']
            lb_db.vip_subnet_id = fixed_ip['subnet_id']
        else:
            for fixed_ip in port['fixed_ips']:
                if fixed_ip['subnet_id'] == lb_db.vip_subnet_id:
                    lb_db.vip_address = fixed_ip['ip_address']
                    break