本文整理汇总了Python中ovs.extensions.services.service.ServiceManager.is_enabled方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceManager.is_enabled方法的具体用法?Python ServiceManager.is_enabled怎么用?Python ServiceManager.is_enabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ovs.extensions.services.service.ServiceManager
的用法示例。
在下文中一共展示了ServiceManager.is_enabled方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: change_service_state
# 需要导入模块: from ovs.extensions.services.service import ServiceManager [as 别名]
# 或者: from ovs.extensions.services.service.ServiceManager import is_enabled [as 别名]
def change_service_state(client, name, state, logger=None):
"""
Starts/stops/restarts a service
:param client: SSHClient on which to connect and change service state
:param name: Name of the service
:param state: State to put the service in
:param logger: LogHandler Object
"""
action = None
# Enable service before changing the state
status = ServiceManager.is_enabled(name, client=client)
if status is False:
if logger is not None:
logger.debug(' {0:<15} - Enabling service {1}'.format(client.ip, name))
ServiceManager.enable_service(name, client=client)
status = ServiceManager.get_service_status(name, client=client)
if status is False and state in ['start', 'restart']:
if logger is not None:
logger.debug(' {0:<15} - Starting service {1}'.format(client.ip, name))
ServiceManager.start_service(name, client=client)
action = 'started'
elif status is True and state == 'stop':
if logger is not None:
logger.debug(' {0:<15} - Stopping service {1}'.format(client.ip, name))
ServiceManager.stop_service(name, client=client)
action = 'stopped'
elif status is True and state == 'restart':
if logger is not None:
logger.debug(' {0:<15} - Restarting service {1}'.format(client.ip, name))
ServiceManager.restart_service(name, client=client)
action = 'restarted'
if action is None:
print ' [{0}] {1} already {2}'.format(client.ip, name, 'running' if status is True else 'halted')
else:
logger.debug(' {0:<15} - Service {1} {2}'.format(client.ip, name, action))
print ' [{0}] {1} {2}'.format(client.ip, name, action)