class BaseV2Controller(base.BaseController): loadbalancers = load_balancer.LoadBalancersController() listeners = listener.ListenersController() pools = pool.PoolsController() @wsme_pecan.wsexpose(wtypes.text) def get(self): return "v2.0"
def __init__(self): super(BaseV2Controller, self).__init__() self.loadbalancers = load_balancer.LoadBalancersController() self.listeners = listener.ListenersController() self.pools = pool.PoolsController() self.l7policies = l7policy.L7PolicyController() self.healthmonitors = health_monitor.HealthMonitorController() self.quotas = quotas.QuotasController()
def __init__(self): super().__init__() self.loadbalancers = load_balancer.LoadBalancersController() self.listeners = listener.ListenersController() self.pools = pool.PoolsController() self.l7policies = l7policy.L7PolicyController() self.healthmonitors = health_monitor.HealthMonitorController() self.quotas = quotas.QuotasController() self.providers = provider.ProviderController() self.flavors = flavors.FlavorsController() self.flavorprofiles = flavor_profiles.FlavorProfileController() self.availabilityzones = ( availability_zones.AvailabilityZonesController()) self.availabilityzoneprofiles = ( availability_zone_profiles.AvailabilityZoneProfileController())
def _graph_create(self, session, lock_session, db_lb, listeners, pools): # Track which pools must have a full specification pools_required = set() # Look through listeners and find any extra pools, and move them to the # top level so they are created first. for li in listeners: default_pool = li.get('default_pool') pool_name = ( default_pool.get('name') if default_pool else None) # All pools need to have a name so they can be referenced if default_pool and not pool_name: raise exceptions.ValidationException( detail='Pools must be named when creating a fully ' 'populated loadbalancer.') # If a pool has more than a name, assume it's a full specification # (but use >3 because it will also have "enabled" and "tls_enabled" # as default) if default_pool and len(default_pool) > 3: pools.append(default_pool) li['default_pool'] = {'name': pool_name} # Otherwise, it's a reference and we record it and move on elif default_pool: pools_required.add(pool_name) # We also need to check policy redirects for policy in li.get('l7policies'): redirect_pool = policy.get('redirect_pool') pool_name = ( redirect_pool.get('name') if redirect_pool else None) # All pools need to have a name so they can be referenced if redirect_pool and not pool_name: raise exceptions.ValidationException( detail='Pools must be named when creating a fully ' 'populated loadbalancer.') # If a pool has more than a name, assume it's a full spec # (but use >2 because it will also have "enabled" and # "tls_enabled" as default) if redirect_pool and len(redirect_pool) > 3: pool_name = redirect_pool['name'] policy['redirect_pool'] = {'name': pool_name} pools.append(redirect_pool) # Otherwise, it's a reference and we record it and move on elif redirect_pool: pools_required.add(pool_name) # Make sure all pool names are unique. pool_names = [p.get('name') for p in pools] if len(set(pool_names)) != len(pool_names): raise exceptions.ValidationException( detail="Pool names must be unique when creating a fully " "populated loadbalancer.") # Make sure every reference is present in our spec list for pool_ref in pools_required: if pool_ref not in pool_names: raise exceptions.ValidationException( detail="Pool '{name}' was referenced but no full " "definition was found.".format(name=pool_ref)) # Check quotas for pools. if pools and self.repositories.check_quota_met( session, lock_session, data_models.Pool, db_lb.project_id, count=len(pools)): raise exceptions.QuotaException(resource=data_models.Pool._name()) # Now create all of the pools ahead of the listeners. new_pools = [] pool_name_ids = {} for p in pools: # Check that pools have mandatory attributes, since we have to # bypass the normal validation layer to allow for name-only for attr in ('protocol', 'lb_algorithm'): if attr not in p: raise exceptions.ValidationException( detail="Pool definition for '{name}' missing required " "attribute: {attr}".format(name=p['name'], attr=attr)) p['load_balancer_id'] = db_lb.id p['project_id'] = db_lb.project_id new_pool = (pool.PoolsController()._graph_create( session, lock_session, p)) new_pools.append(new_pool) pool_name_ids[new_pool.name] = new_pool.id # Now check quotas for listeners if listeners and self.repositories.check_quota_met( session, lock_session, data_models.Listener, db_lb.project_id, count=len(listeners)): raise exceptions.QuotaException( resource=data_models.Listener._name()) # Now create all of the listeners new_lists = [] for li in listeners: default_pool = li.pop('default_pool', None) # If there's a default pool, replace it with the ID if default_pool: pool_name = default_pool['name'] pool_id = pool_name_ids.get(pool_name) if not pool_id: raise exceptions.SingleCreateDetailsMissing( type='Pool', name=pool_name) li['default_pool_id'] = pool_id li['load_balancer_id'] = db_lb.id li['project_id'] = db_lb.project_id new_lists.append(listener.ListenersController()._graph_create( lock_session, li, pool_name_ids=pool_name_ids)) return new_pools, new_lists