Ejemplo n.º 1
0
def gen_dns_prefix():
    ctxt = context.get_admin_context(read_deleted="yes")
    all_load_balancers = db.load_balancer_get_all(ctxt)
    all_prefixs = map(lambda x: x['dns_prefix'], all_load_balancers)
    prefix = generate_uid(size=10)
    while prefix in all_prefixs:
        prefix = generate_uid(size=10)
    return prefix
Ejemplo n.º 2
0
def allocate_listen_port():
    filters = dict({'protocol': 'tcp'})
    ctxt = context.get_admin_context(read_deleted="yes")
    all_lbs = db.load_balancer_get_all(ctxt, filters=filters)

    active_load_balancers = filter(lambda x: not x['deleted'], all_lbs)
    deleted_load_balancers = filter(lambda x: x['deleted'], all_lbs)
    allocated_ports = map(lambda x: x['listen_port'], active_load_balancers)
    available_ports = filter(lambda x: x not in allocated_ports,
                             map(lambda y: y['listen_port'],
                                 deleted_load_balancers))

    if available_ports:
        return available_ports[0]
    elif allocated_ports:
        return max(allocated_ports) + 1
    else:
        return 11000
Ejemplo n.º 3
0
def checker_routine(*args, **kwargs):
    LOG.info('nozzle checker starting...')

    broadcast = kwargs['broadcast']
    states = [state.CREATING, state.UPDATING, state.DELETING]
    while True:
        eventlet.sleep(6)
        msg_type = 'lb'
        msg_uuid = utils.str_uuid()
        try:
            ctxt = context.get_admin_context()
            all_load_balancers = db.load_balancer_get_all(ctxt)
            transient_load_balancers = filter(lambda x: x.state in states,
                                              all_load_balancers)
            for load_balancer_ref in transient_load_balancers:
                try:
                    result = dict()
                    message = dict()
                    if load_balancer_ref.state == state.CREATING:
                        message['cmd'] = 'create_lb'
                        result = api.format_msg_to_worker(load_balancer_ref)
                    elif load_balancer_ref.state == state.UPDATING:
                        message['cmd'] = 'update_lb'
                        result = api.format_msg_to_worker(load_balancer_ref)
                    elif load_balancer_ref.state == state.DELETING:
                        message['cmd'] = 'delete_lb'
                        result['user_id'] = load_balancer_ref['user_id']
                        result['tenant_id'] = load_balancer_ref['project_id']
                        result['uuid'] = load_balancer_ref['uuid']
                        result['protocol'] = load_balancer_ref['protocol']
                    message['args'] = result
                    request_msg = jsonutils.dumps(message)
                    LOG.debug(">>>>>>> worker: %s" % request_msg)
                    broadcast.send_multipart([msg_type, msg_uuid, request_msg])
                except Exception as exp:
                    LOG.exception(str(exp))
                    continue
        except Exception as exp:
            LOG.exception(str(exp))
            continue
Ejemplo n.º 4
0
def worker_routine(*args, **kwargs):
    LOG.info('nozzle worker starting...')

    feedback = kwargs['feedback']
    poller = zmq.Poller()
    poller.register(feedback, zmq.POLLIN)

    while True:
        eventlet.sleep(0)
        socks = dict(poller.poll(100))
        if socks.get(feedback) == zmq.POLLIN:
            msg_type, msg_uuid, msg_json = feedback.recv_multipart()
            msg_body = jsonutils.loads(msg_json)
            LOG.debug("<<<<<<< worker: %s" % msg_body)
            # update load balancer's state
            try:
                args = msg_body
                ctxt = context.get_admin_context()
                api.update_load_balancer_state(ctxt, **args)
            except Exception as exp:
                LOG.exception(str(exp))
                continue
Ejemplo n.º 5
0
def get_all_load_balancers(filters=None):
    ctxt = context.get_admin_context()
    all_load_balancers = db.load_balancer_get_all(ctxt, filters=filters)
    return all_load_balancers
Ejemplo n.º 6
0
def get_all_domain_names():
    ctxt = context.get_admin_context()
    all_domains = db.load_balancer_domain_get_all(ctxt)
    all_http_servers = map(lambda x: x['name'], all_domains)
    return all_http_servers