本文整理汇总了Python中ovs.lib.helpers.toolbox.Toolbox.retry_client_run方法的典型用法代码示例。如果您正苦于以下问题:Python Toolbox.retry_client_run方法的具体用法?Python Toolbox.retry_client_run怎么用?Python Toolbox.retry_client_run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ovs.lib.helpers.toolbox.Toolbox
的用法示例。
在下文中一共展示了Toolbox.retry_client_run方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: configure_rabbitmq
# 需要导入模块: from ovs.lib.helpers.toolbox import Toolbox [as 别名]
# 或者: from ovs.lib.helpers.toolbox.Toolbox import retry_client_run [as 别名]
def configure_rabbitmq(client, logger):
"""
Configure RabbitMQ
:param client: Client on which to configure RabbitMQ
:type client: ovs.extensions.generic.sshclient.SSHClient
:param logger: Logger object used for logging
:type logger: ovs.log.log_handler.LogHandler
:return: None
"""
Toolbox.log(logger=logger, messages='Setting up RabbitMQ')
rabbitmq_port = Configuration.get('/ovs/framework/messagequeue|endpoints')[0].split(':')[1]
rabbitmq_login = Configuration.get('/ovs/framework/messagequeue|user')
rabbitmq_password = Configuration.get('/ovs/framework/messagequeue|password')
client.file_write('/etc/rabbitmq/rabbitmq.config', """[
{{rabbit, [{{tcp_listeners, [{0}]}},
{{default_user, <<"{1}">>}},
{{default_pass, <<"{2}">>}},
{{log_levels, [{{connection, warning}}]}},
{{vm_memory_high_watermark, 0.2}}]}}
].""".format(rabbitmq_port, rabbitmq_login, rabbitmq_password))
rabbitmq_running, same_process = ServiceManager.is_rabbitmq_running(client=client)
if rabbitmq_running is True:
# Example output of 'list_users' command
# Listing users ...
# guest [administrator]
# ovs []
# ... done.
users = [user.split('\t')[0] for user in client.run(['rabbitmqctl', 'list_users']).splitlines() if '\t' in user and '[' in user and ']' in user]
if 'ovs' in users:
Toolbox.log(logger=logger, messages='Already configured RabbitMQ')
return
Toolbox.change_service_state(client, 'rabbitmq-server', 'stop', logger)
client.run(['rabbitmq-server', '-detached'])
time.sleep(5)
# Sometimes/At random the rabbitmq server takes longer than 5 seconds to start,
# and the next command fails so the best solution is to retry several times
# Also retry the add_user/set_permissions, and validate the result
retry = 0
while retry < 10:
users = Toolbox.retry_client_run(client=client,
command=['rabbitmqctl', 'list_users'],
logger=logger).splitlines()
users = [usr.split('\t')[0] for usr in users if '\t' in usr and '[' in usr and ']' in usr]
logger.debug('Rabbitmq users {0}'.format(users))
if 'ovs' in users:
logger.debug('User ovs configured in rabbitmq')
break
logger.debug(Toolbox.retry_client_run(client=client,
command=['rabbitmqctl', 'add_user', rabbitmq_login, rabbitmq_password],
logger=logger))
logger.debug(Toolbox.retry_client_run(client=client,
command=['rabbitmqctl', 'set_permissions', rabbitmq_login, '.*', '.*', '.*'],
logger=logger))
retry += 1
time.sleep(1)
client.run(['rabbitmqctl', 'stop'])
time.sleep(5)