本文整理汇总了Python中zato.admin.web.views.get_lb_client函数的典型用法代码示例。如果您正苦于以下问题:Python get_lb_client函数的具体用法?Python get_lb_client怎么用?Python get_lb_client使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_lb_client函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remote_command
def remote_command(req, cluster_id):
""" Execute a HAProxy command.
"""
cluster = req.zato.odb.query(Cluster).filter_by(id=cluster_id).one()
client = get_lb_client(cluster)
haproxy_alive = _haproxy_alive(client)
cluster.stats_uri, cluster.stats_port = _haproxy_stat_config(client=client)
# We need to know the HAProxy version before we can build up the select box
# on the form.
commands = haproxy_stats[("1", "3")]
version_info = tuple(client.haproxy_version_info())
if version_info >= ("1", "4"):
commands.update(haproxy_stats[("1", "4")])
if req.method == "POST":
result = client.execute_command(req.POST["command"], req.POST["timeout"], req.POST.get("extra", ""))
if not result.strip():
result = "(empty result)"
initial={"result":result}
for k, v in req.POST.items():
if k != "result":
initial[k] = v
form = RemoteCommandForm(commands, initial)
else:
form = RemoteCommandForm(commands)
return_data = {"form":form, "cluster":cluster, "haproxy_alive":haproxy_alive}
return TemplateResponse(req, 'zato/load_balancer/remote_command.html', return_data)
示例2: servers_add_remove_lb
def servers_add_remove_lb(req, action, server_id):
""" Adds or removes a server from the load balancer's configuration.
"""
server = req.zato.odb.query(Server).filter_by(id=server_id).one()
up_mod_date = server.up_mod_date.isoformat() if server.up_mod_date else ""
client = get_lb_client(req.zato.cluster)
client.add_remove_server(action, server.name)
if action == "add":
success_msg = "added to"
fetch_lb_data = True
else:
success_msg = "removed from"
fetch_lb_data = False
return _common_edit_message(
client,
"Server [{{}}] {} the load balancer".format(success_msg),
server.id,
server.name,
server.host,
server.up_status,
up_mod_date,
server.cluster_id,
req.zato.user_profile,
fetch_lb_data,
)
示例3: index
def index(req):
initial = {}
initial['odb_type'] = sqlalchemy_django_engine[DATABASE_ENGINE.replace('django.db.backends.', '')]
initial['odb_host'] = DATABASE_HOST
initial['odb_port'] = DATABASE_PORT
initial['odb_user'] = DATABASE_USER
initial['odb_db_name'] = DATABASE_NAME
delete_form = DeleteClusterForm(prefix='delete')
items = req.zato.odb.query(Cluster).order_by('name').all()
for item in items:
client = get_lb_client(item)
try:
lb_config = client.get_config()
item.lb_config = lb_config
# Assign the flags indicating whether servers are DOWN or in the MAINT mode.
set_servers_state(item, client)
except Exception, e:
msg = 'Could not invoke agent, client:[{client!r}], e:[{e}]'.format(client=client,
e=format_exc(e))
logger.error(msg)
item.lb_config = None
示例4: manage
def manage(req, cluster_id):
""" GUI for managing HAProxy configuration.
"""
cluster = req.odb.query(Cluster).filter_by(id=cluster_id).one()
client = get_lb_client(cluster)
lb_start_time = datetime.fromtimestamp(client.get_uptime_info())
lb_config = client.get_config()
lb_work_config = client.get_work_config()
lb_work_config['verify_fields'] = ', '.join(['%s=%s' % (k,v) for (k, v) in sorted(lb_work_config['verify_fields'].items())])
form_data = {
'global_log_host': lb_config['global_']['log']['host'],
'global_log_port': lb_config['global_']['log']['port'],
'global_log_level': lb_config['global_']['log']['level'],
'global_log_facility': lb_config['global_']['log']['facility'],
'timeout_connect': lb_config['defaults']['timeout_connect'],
'timeout_client': lb_config['defaults']['timeout_client'],
'timeout_server': lb_config['defaults']['timeout_server'],
'http_plain_bind_address':lb_config['frontend']['front_http_plain']['bind']['address'],
'http_plain_bind_port':lb_config['frontend']['front_http_plain']['bind']['port'],
'http_plain_log_http_requests':lb_config['frontend']['front_http_plain']['log_http_requests'],
'http_plain_maxconn':lb_config['frontend']['front_http_plain']['maxconn'],
'http_plain_monitor_uri':lb_config['frontend']['front_http_plain']['monitor_uri'],
}
backends = {}
for backend_type in lb_config['backend']:
for name in lb_config['backend'][backend_type]:
# Is it a server?
if 'address' in lb_config['backend'][backend_type][name]:
if not name in backends:
backends[name] = {}
backends[name][backend_type] = {}
backends[name][backend_type]['address'] = lb_config['backend'][backend_type][name]['address']
backends[name][backend_type]['port'] = lb_config['backend'][backend_type][name]['port']
backends[name][backend_type]['extra'] = lb_config['backend'][backend_type][name]['extra']
backends = OrderedDict(sorted(backends.items(), key=lambda t: t[0]))
form = ManageLoadBalancerForm(initial=form_data)
haproxy_alive = _haproxy_alive(client)
cluster.stats_uri, cluster.stats_port = _haproxy_stat_config(lb_config=lb_config)
servers_state = client.get_servers_state()
return_data = {'cluster':cluster, 'lb_start_time':lb_start_time,
'lb_config':lb_config, 'lb_work_config':lb_work_config,
'form':form, 'backends':backends, 'haproxy_alive':haproxy_alive,
'servers_state':servers_state}
if logger.isEnabledFor(TRACE1):
logger.log(TRACE1, 'Returning render_to_response [%s]' % return_data)
return render_to_response('zato/load_balancer/manage.html', return_data,
context_instance=RequestContext(req))
示例5: __call__
def __call__(self, req, *args, **kwargs):
response = req.zato.client.invoke('zato.server.get-by-id', {'id':req.zato.id})
server = req.zato.odb.query(Server).filter_by(id=req.zato.id).one()
client = get_lb_client(req.zato.cluster) # Checks whether the server is known by LB
if client.get_server_data_dict(server.name):
client.add_remove_server('remove', response.data.name)
return super(ServerDelete, self).__call__(req, *args, **kwargs)
示例6: validate_save_source_code
def validate_save_source_code(req, cluster_id):
""" A common handler for both validating and saving a HAProxy config using
the raw HAProxy config file's view.
"""
cluster = req.zato.odb.query(Cluster).filter_by(id=cluster_id).one()
save = _get_validate_save_flag(cluster_id, req.POST)
# Invoke the LB agent
client = get_lb_client(cluster)
return _client_validate_save(req, client.validate_save_source_code, req.POST["source_code"], save)
示例7: __call__
def __call__(self, req, *args, **kwargs):
zato_message, _ = invoke_admin_service(req.zato.cluster, "zato:cluster.server.get-by-id", {"id": req.zato.id})
server = req.zato.odb.query(Server).filter_by(id=req.zato.id).one()
client = get_lb_client(req.zato.cluster) # Checks whether the server is known by LB
if client.get_server_data_dict(server.name):
client.add_remove_server("remove", zato_message.response.item.name.text)
return super(ServerDelete, self).__call__(req, *args, **kwargs)
示例8: get_servers_state
def get_servers_state(req, cluster_id):
cluster = req.zato.odb.query(Cluster).filter_by(id=cluster_id).one()
client = get_lb_client(cluster)
# Assign the flags indicating whether servers are DOWN or in the MAINT mode.
try:
set_servers_state(cluster, client)
except Exception, e:
msg = "Failed to invoke the load-balancer's agent and set the state of servers, e:[{e}]".format(e=format_exc(e))
logger.error(msg)
return HttpResponseServerError(msg)
示例9: servers
def servers(req):
""" A view for server management.
"""
items = req.zato.odb.query(Server).order_by("name").all()
try:
client = get_lb_client(req.zato.get("cluster"))
server_data_dict = client.get_server_data_dict()
bck_http_plain = client.get_config()["backend"]["bck_http_plain"]
lb_client_invoked = True
except Exception, e:
lb_client_invoked = False
示例10: servers
def servers(req):
""" A view for server management.
"""
items = req.zato.odb.query(Server).order_by('name').all()
try:
client = get_lb_client(req.zato.get('cluster'))
server_data_dict = client.get_server_data_dict()
bck_http_plain = client.get_config()['backend']['bck_http_plain']
lb_client_invoked = True
except Exception, e:
logger.error(format_exc(e))
lb_client_invoked = False
示例11: validate_save
def validate_save(req, cluster_id):
""" A common handler for both validating and saving a HAProxy config using
a pretty GUI form.
"""
save = _get_validate_save_flag(cluster_id, req.POST)
cluster = req.zato.odb.query(Cluster).filter_by(id=cluster_id).one()
client = get_lb_client(cluster)
lb_config = Config()
lb_config.global_["log"] = {}
lb_config.frontend["front_http_plain"] = {}
lb_config.frontend["front_http_plain"]["bind"] = {}
lb_config.global_["log"]["host"] = req.POST["global_log_host"]
lb_config.global_["log"]["port"] = req.POST["global_log_port"]
lb_config.global_["log"]["level"] = req.POST["global_log_level"]
lb_config.global_["log"]["facility"] = req.POST["global_log_facility"]
lb_config.defaults["timeout_connect"] = req.POST["timeout_connect"]
lb_config.defaults["timeout_client"] = req.POST["timeout_client"]
lb_config.defaults["timeout_server"] = req.POST["timeout_server"]
lb_config.frontend["front_http_plain"]["bind"]["address"] = req.POST["http_plain_bind_address"]
lb_config.frontend["front_http_plain"]["bind"]["port"] = req.POST["http_plain_bind_port"]
lb_config.frontend["front_http_plain"]["log_http_requests"] = req.POST["http_plain_log_http_requests"]
lb_config.frontend["front_http_plain"]["maxconn"] = req.POST["http_plain_maxconn"]
lb_config.frontend["front_http_plain"]["monitor_uri"] = req.POST["http_plain_monitor_uri"]
for key, value in req.POST.items():
if key.startswith("bck_http"):
for token in("address", "port", "extra"):
splitted = key.split(token)
if splitted[0] == key:
continue # We don't have the token in that key.
backend_type, backend_name = splitted
# Get rid of underscores left over from the .split above.
backend_type = backend_type[:-1]
backend_name = backend_name[1:]
lb_config.backend.setdefault(backend_type, {})
lb_config.backend[backend_type].setdefault(backend_name, {})
lb_config.backend[backend_type][backend_name][token] = value
# Invoke the LB agent
_client_validate_save(req, client.validate_save, lb_config, save)
return redirect("lb-manage", cluster_id=cluster_id)
示例12: manage_source_code
def manage_source_code(req, cluster_id):
""" Source code view for managing HAProxy configuration.
"""
cluster = req.zato.odb.query(Cluster).filter_by(id=cluster_id).one()
client = get_lb_client(cluster)
cluster.stats_uri, cluster.stats_port = _haproxy_stat_config(client=client)
haproxy_alive = _haproxy_alive(client)
source_code = client.get_config_source_code()
form = ManageLoadBalancerSourceCodeForm(initial={"source_code":source_code})
return_data = {"form": form, "haproxy_alive":haproxy_alive, "cluster":cluster}
return TemplateResponse(req, 'zato/load_balancer/manage_source_code.html', return_data)
示例13: get_addresses
def get_addresses(req, cluster_id):
""" Return JSON-formatted addresses known to HAProxy.
"""
cluster = req.zato.odb.query(Cluster).filter_by(id=cluster_id).one()
client = get_lb_client(cluster)
addresses = {}
addresses["cluster"] = {"lb_host": cluster.lb_host, "lb_agent_port":cluster.lb_agent_port}
try:
lb_config = client.get_config()
except Exception, e:
msg = "Could not get load balancer's config, client:[{client!r}], e:[{e}]".format(client=client,
e=format_exc(e))
logger.error(msg)
lb_config = None
示例14: _create_edit
def _create_edit(req, verb, item, form_class, prefix=''):
join = '-' if prefix else ''
try:
for s in whitespace:
if s in req.POST[prefix + join + 'name']:
return HttpResponseServerError('Cluster name must not contain whitespace.')
description = req.POST[prefix + join + 'description'].strip()
description = description if description else None
item.name = req.POST[prefix + join + 'name'].strip()
item.description = description
item.odb_type = req.POST[prefix + join + 'odb_type'].strip()
item.odb_host = req.POST[prefix + join + 'odb_host'].strip()
item.odb_port = req.POST[prefix + join + 'odb_port'].strip()
item.odb_user = req.POST[prefix + join + 'odb_user'].strip()
item.odb_db_name = req.POST[prefix + join + 'odb_db_name'].strip()
item.odb_schema = req.POST[prefix + join + 'odb_schema'].strip()
item.lb_host = req.POST[prefix + join + 'lb_host'].strip()
item.lb_port = req.POST[prefix + join + 'lb_port'].strip()
item.lb_agent_port = req.POST[prefix + join + 'lb_agent_port'].strip()
item.broker_host = req.POST[prefix + join + 'broker_host'].strip()
item.broker_start_port = req.POST[prefix + join + 'broker_start_port'].strip()
item.broker_token = req.POST[prefix + join + 'broker_token'].strip()
try:
req.odb.add(item)
req.odb.commit()
try:
item.lb_config = get_lb_client(item).get_config()
except Exception, e:
item.lb_config = None
msg = "Exception caught while fetching the load balancer's config, e=[{0}]".format(format_exc(e))
logger.error(msg)
return _edit_create_response(item, verb)
except Exception, e:
msg = 'Exception caught, e=[{0}]'.format(format_exc(e))
logger.error(msg)
return HttpResponseServerError(msg)
示例15: _create_edit
def _create_edit(req, verb, item, form_class, prefix=""):
join = "-" if prefix else ""
try:
for s in whitespace:
if s in req.POST[prefix + join + "name"]:
return HttpResponseServerError("Cluster name must not contain whitespace.")
description = req.POST[prefix + join + "description"].strip()
description = description if description else None
item.name = req.POST[prefix + join + "name"].strip()
item.description = description
item.odb_type = req.POST[prefix + join + "odb_type"].strip()
item.odb_host = req.POST[prefix + join + "odb_host"].strip()
item.odb_port = req.POST[prefix + join + "odb_port"].strip()
item.odb_user = req.POST[prefix + join + "odb_user"].strip()
item.odb_db_name = req.POST[prefix + join + "odb_db_name"].strip()
item.odb_schema = req.POST[prefix + join + "odb_schema"].strip()
item.lb_host = req.POST[prefix + join + "lb_host"].strip()
item.lb_port = req.POST[prefix + join + "lb_port"].strip()
item.lb_agent_port = req.POST[prefix + join + "lb_agent_port"].strip()
item.broker_host = req.POST[prefix + join + "broker_host"].strip()
item.broker_start_port = req.POST[prefix + join + "broker_start_port"].strip()
item.broker_token = req.POST[prefix + join + "broker_token"].strip()
try:
req.zato.odb.add(item)
req.zato.odb.commit()
try:
item.lb_config = get_lb_client(item).get_config()
except Exception, e:
item.lb_config = None
msg = "Exception caught while fetching the load balancer's config, e:[{0}]".format(format_exc(e))
logger.error(msg)
return _edit_create_response(item, verb)
except Exception, e:
msg = "Exception caught, e:[{0}]".format(format_exc(e))
logger.error(msg)
return HttpResponseServerError(msg)