本文整理汇总了Python中ovs.extensions.services.service.ServiceManager.is_rabbitmq_running方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceManager.is_rabbitmq_running方法的具体用法?Python ServiceManager.is_rabbitmq_running怎么用?Python ServiceManager.is_rabbitmq_running使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ovs.extensions.services.service.ServiceManager
的用法示例。
在下文中一共展示了ServiceManager.is_rabbitmq_running方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_rabbitmq_and_enable_ha_mode
# 需要导入模块: from ovs.extensions.services.service import ServiceManager [as 别名]
# 或者: from ovs.extensions.services.service.ServiceManager import is_rabbitmq_running [as 别名]
def check_rabbitmq_and_enable_ha_mode(client, logger):
"""
Verify RabbitMQ is running properly and enable HA mode
:param client: Client on which to check RabbitMQ
:type client: ovs.extensions.generic.sshclient.SSHClient
:param logger: Logger object used for logging
:type logger: ovs.log.log_handler.LogHandler
:return: None
"""
if not ServiceManager.has_service('rabbitmq-server', client):
raise RuntimeError('Service rabbitmq-server has not been added on node {0}'.format(client.ip))
rabbitmq_running, same_process = ServiceManager.is_rabbitmq_running(client=client)
if rabbitmq_running is False or same_process is False:
Toolbox.change_service_state(client, 'rabbitmq-server', 'restart', logger)
time.sleep(5)
client.run(['rabbitmqctl', 'set_policy', 'ha-all', '^(volumerouter|ovs_.*)$', '{"ha-mode":"all"}'])
示例2: configure_rabbitmq
# 需要导入模块: from ovs.extensions.services.service import ServiceManager [as 别名]
# 或者: from ovs.extensions.services.service.ServiceManager import is_rabbitmq_running [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)