本文整理汇总了Python中ovs.extensions.services.service.ServiceManager.get_service_status方法的典型用法代码示例。如果您正苦于以下问题:Python ServiceManager.get_service_status方法的具体用法?Python ServiceManager.get_service_status怎么用?Python ServiceManager.get_service_status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ovs.extensions.services.service.ServiceManager
的用法示例。
在下文中一共展示了ServiceManager.get_service_status方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: change_service_state
# 需要导入模块: from ovs.extensions.services.service import ServiceManager [as 别名]
# 或者: from ovs.extensions.services.service.ServiceManager import get_service_status [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
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)
示例2: stop
# 需要导入模块: from ovs.extensions.services.service import ServiceManager [as 别名]
# 或者: from ovs.extensions.services.service.ServiceManager import get_service_status [as 别名]
def stop(cluster_name, client):
"""
Stops an arakoon service
"""
if ServiceManager.has_service('arakoon-{0}'.format(cluster_name), client=client) is True and \
ServiceManager.get_service_status('arakoon-{0}'.format(cluster_name), client=client) is True:
ServiceManager.stop_service('arakoon-{0}'.format(cluster_name), client=client)
示例3: _setup_proxy
# 需要导入模块: from ovs.extensions.services.service import ServiceManager [as 别名]
# 或者: from ovs.extensions.services.service.ServiceManager import get_service_status [as 别名]
def _setup_proxy(initial_cluster, slave_client, cluster_name, force=False):
base_name = 'ovs-etcd-proxy'
target_name = 'ovs-etcd-{0}'.format(cluster_name)
if force is False and ServiceManager.has_service(target_name, slave_client) and \
ServiceManager.get_service_status(target_name, slave_client) is True:
logger.info('Service {0} already configured and running'.format(target_name))
return
EtcdInstaller.stop(cluster_name, slave_client)
data_dir = EtcdInstaller.DATA_DIR.format(EtcdInstaller.DB_DIR, cluster_name)
wal_dir = EtcdInstaller.WAL_DIR.format(EtcdInstaller.DB_DIR, cluster_name)
abs_paths = [data_dir, wal_dir]
slave_client.dir_delete(abs_paths)
slave_client.dir_create(data_dir)
slave_client.dir_chmod(data_dir, 0755, recursive=True)
slave_client.dir_chown(data_dir, 'ovs', 'ovs', recursive=True)
ServiceManager.add_service(base_name, slave_client,
params={'CLUSTER': cluster_name,
'DATA_DIR': data_dir,
'LOCAL_CLIENT_URL': EtcdInstaller.CLIENT_URL.format('127.0.0.1'),
'INITIAL_CLUSTER': initial_cluster},
target_name=target_name)
EtcdInstaller.start(cluster_name, slave_client)
EtcdInstaller.wait_for_cluster(cluster_name, slave_client)
示例4: install_plugins
# 需要导入模块: from ovs.extensions.services.service import ServiceManager [as 别名]
# 或者: from ovs.extensions.services.service.ServiceManager import get_service_status [as 别名]
def install_plugins():
"""
(Re)load plugins
"""
if ServiceManager.has_service('ovs-watcher-framework', SSHClient('127.0.0.1', username='root')):
# If the watcher is running, 'ovs setup' was executed and we need to restart everything to load
# the plugin. In the other case, the plugin will be loaded once 'ovs setup' is executed
from ovs.dal.lists.storagerouterlist import StorageRouterList
clients = []
try:
for storagerouter in StorageRouterList.get_storagerouters():
clients.append(SSHClient(storagerouter, username='root'))
except UnableToConnectException:
raise RuntimeError('Not all StorageRouters are reachable')
for client in clients:
for service_name in ['watcher-framework', 'memcached']:
ServiceManager.stop_service(service_name, client=client)
wait = 30
while wait > 0:
if ServiceManager.get_service_status(service_name, client=client) is False:
break
time.sleep(1)
wait -= 1
if wait == 0:
raise RuntimeError('Could not stop service: {0}'.format(service_name))
for client in clients:
for service_name in ['memcached', 'watcher-framework']:
ServiceManager.start_service(service_name, client=client)
wait = 30
while wait > 0:
if ServiceManager.get_service_status(service_name, client=client) is True:
break
time.sleep(1)
wait -= 1
if wait == 0:
raise RuntimeError('Could not start service: {0}'.format(service_name))
from ovs.dal.helpers import Migration
Migration.migrate()
from ovs.lib.helpers.toolbox import Toolbox
ip = System.get_my_storagerouter().ip
functions = Toolbox.fetch_hooks('plugin', 'postinstall')
for function in functions:
function(ip=ip)
示例5: get_service_status
# 需要导入模块: from ovs.extensions.services.service import ServiceManager [as 别名]
# 或者: from ovs.extensions.services.service.ServiceManager import get_service_status [as 别名]
def get_service_status(name, client):
"""
Check the status of the service
:param name: Name of the service
:param client: SSHClient object
:return: True if service is running
"""
return ServiceManager.get_service_status(name, client)
示例6: start
# 需要导入模块: from ovs.extensions.services.service import ServiceManager [as 别名]
# 或者: from ovs.extensions.services.service.ServiceManager import get_service_status [as 别名]
def start(cluster_name, client):
"""
Starts an etcd cluster
:param client: Client on which to start the service
:param cluster_name: The name of the cluster service to start
"""
if ServiceManager.has_service('etcd-{0}'.format(cluster_name), client=client) is True and \
ServiceManager.get_service_status('etcd-{0}'.format(cluster_name), client=client) is False:
ServiceManager.start_service('etcd-{0}'.format(cluster_name), client=client)
示例7: is_running
# 需要导入模块: from ovs.extensions.services.service import ServiceManager [as 别名]
# 或者: from ovs.extensions.services.service.ServiceManager import get_service_status [as 别名]
def is_running(cluster_name, client):
"""
Checks if arakoon service is running
:param client: Client on which to stop the service
:param cluster_name: The name of the cluster service to stop
"""
if ServiceManager.has_service('arakoon-{0}'.format(cluster_name), client=client):
return ServiceManager.get_service_status('arakoon-{0}'.format(cluster_name), client=client)
return False
示例8: stop
# 需要导入模块: from ovs.extensions.services.service import ServiceManager [as 别名]
# 或者: from ovs.extensions.services.service.ServiceManager import get_service_status [as 别名]
def stop(cluster_name, client):
"""
Stops an arakoon service
:param client: Client on which to stop the service
:param cluster_name: The name of the cluster service to stop
"""
if ServiceManager.has_service('arakoon-{0}'.format(cluster_name), client=client) is True and \
ServiceManager.get_service_status('arakoon-{0}'.format(cluster_name), client=client) is True:
ServiceManager.stop_service('arakoon-{0}'.format(cluster_name), client=client)
示例9: stop
# 需要导入模块: from ovs.extensions.services.service import ServiceManager [as 别名]
# 或者: from ovs.extensions.services.service.ServiceManager import get_service_status [as 别名]
def stop(cluster_name, client):
"""
Stops an arakoon service
"""
if (
ServiceManager.has_service("arakoon-{0}".format(cluster_name), client=client) is True
and ServiceManager.get_service_status("arakoon-{0}".format(cluster_name), client=client) is True
):
ServiceManager.stop_service("arakoon-{0}".format(cluster_name), client=client)
示例10: manage_running_tasks
# 需要导入模块: from ovs.extensions.services.service import ServiceManager [as 别名]
# 或者: from ovs.extensions.services.service.ServiceManager import get_service_status [as 别名]
def manage_running_tasks(tasklist, timesleep=10):
"""
Manage a list of running celery task
- discard PENDING tasks after a certain timeout
- validate RUNNING tasks are actually running
:param tasklist: Dictionary of tasks to wait {IP address: AsyncResult}
:type tasklist: dict
:param timesleep: leep between checks -
-for long running tasks it's better to sleep for a longer period of time to reduce number of ssh calls
:type timesleep: int
:return: results
:rtype: dict
"""
logger = LogHandler.get('lib', name='celery toolbox')
ssh_clients = {}
tasks_pending = {}
tasks_pending_timeout = 1800 # 30 minutes
results = {}
failed_nodes = []
while len(tasklist.keys()) > 0:
for ip, task in tasklist.items():
if task.state in ('SUCCESS', 'FAILURE'):
logger.info('Task {0} finished: {1}'.format(task.id, task.state))
results[ip] = task.get(propagate=False)
del tasklist[ip]
elif task.state == 'PENDING':
if task.id not in tasks_pending:
tasks_pending[task.id] = time.time()
else:
task_pending_since = tasks_pending[task.id]
if time.time() - task_pending_since > tasks_pending_timeout:
logger.warning('Task {0} is pending since {1} on node {2}. Task will be revoked'.format(task.id, datetime.datetime.fromtimestamp(task_pending_since), ip))
revoke(task.id)
del tasklist[ip]
del tasks_pending[task.id]
failed_nodes.append(ip)
elif task.state == 'STARTED':
if ip not in ssh_clients:
ssh_clients[ip] = SSHClient(ip, username='root')
client = ssh_clients[ip]
if ServiceManager.get_service_status('workers', client) is False:
logger.error('Service ovs-workers on node {0} appears halted while there is a task PENDING for it {1}. Task will be revoked.'.format(ip, task.id))
revoke(task.id)
del tasklist[ip]
failed_nodes.append(ip)
else:
ping_result = task.app.control.inspect().ping()
storage_router = StorageRouterList.get_by_ip(ip)
if "[email protected]{0}".format(storage_router.name) not in ping_result:
logger.error('Service ovs-workers on node {0} is not reachable via rabbitmq while there is a task STARTED for it {1}. Task will be revoked.'.format(ip, task.id))
revoke(task.id)
del tasklist[ip]
failed_nodes.append(ip)
if len(tasklist.keys()) > 0:
time.sleep(timesleep)
return results, failed_nodes
示例11: wait_for_service
# 需要导入模块: from ovs.extensions.services.service import ServiceManager [as 别名]
# 或者: from ovs.extensions.services.service.ServiceManager import get_service_status [as 别名]
def wait_for_service(client, name, status, logger):
"""
Wait for service to enter status
:param client: SSHClient to run commands
:param name: name of service
:param status: True - running/False - not running
:param logger: Logging object
"""
tries = 10
while tries > 0:
service_status, _ = ServiceManager.get_service_status(name, client)
if service_status == status:
break
logger.debug('... waiting for service {0}'.format(name))
tries -= 1
time.sleep(10 - tries)
service_status, output = ServiceManager.get_service_status(name, client)
if service_status != status:
raise RuntimeError('Service {0} does not have expected status: {1}'.format(name, output))
示例12: _is_cinder_running
# 需要导入模块: from ovs.extensions.services.service import ServiceManager [as 别名]
# 或者: from ovs.extensions.services.service.ServiceManager import get_service_status [as 别名]
def _is_cinder_running(self):
if self.is_devstack:
try:
return 'cinder-volume' in str(self.client.run('ps aux | grep cinder-volume | grep -v grep'))
except SystemExit:
return False
if self.is_openstack:
try:
cinder_service = OSManager.get_openstack_cinder_service_name()
return ServiceManager.get_service_status(cinder_service, self.client)
except SystemExit:
return False
return False
示例13: is_running
# 需要导入模块: from ovs.extensions.services.service import ServiceManager [as 别名]
# 或者: from ovs.extensions.services.service.ServiceManager import get_service_status [as 别名]
def is_running(cluster_name, client):
"""
Checks if arakoon service is running
:param cluster_name: The name of the cluster service to check
:type cluster_name: str
:param client: Client on which to check the service
:type client: SSHClient
:return: None
"""
service_name = ArakoonInstaller.get_service_name_for_cluster(cluster_name=cluster_name)
if ServiceManager.has_service(name=service_name, client=client):
return ServiceManager.get_service_status(name=service_name, client=client)[0]
return False
示例14: create_cluster
# 需要导入模块: from ovs.extensions.services.service import ServiceManager [as 别名]
# 或者: from ovs.extensions.services.service.ServiceManager import get_service_status [as 别名]
def create_cluster(cluster_name, ip, server_port=DEFAULT_SERVER_PORT, client_port=DEFAULT_CLIENT_PORT):
"""
Creates a cluster
:param cluster_name: Name of the cluster
:type cluster_name: str
:param ip: IP address of the first node of the new cluster
:type ip: str
:param server_port: Port to be used by server
:type server_port: int
:param client_port: Port to be used by client
:type client_port: int
:return: None
"""
EtcdInstaller._logger.debug('Creating cluster "{0}" on {1}'.format(cluster_name, ip))
client = SSHClient(ip, username='root')
target_name = 'ovs-etcd-{0}'.format(cluster_name)
if ServiceManager.has_service(target_name, client) and ServiceManager.get_service_status(target_name, client) is True:
EtcdInstaller._logger.info('Service {0} already configured and running'.format(target_name))
return
node_name = System.get_my_machine_id(client)
data_dir = EtcdInstaller.DATA_DIR.format(cluster_name)
wal_dir = EtcdInstaller.WAL_DIR.format(cluster_name)
abs_paths = [data_dir, wal_dir]
client.dir_delete(abs_paths)
client.dir_create(abs_paths)
client.dir_chmod(abs_paths, 0755, recursive=True)
client.dir_chown(abs_paths, 'ovs', 'ovs', recursive=True)
base_name = 'ovs-etcd'
ServiceManager.add_service(base_name, client,
params={'CLUSTER': cluster_name,
'NODE_ID': node_name,
'DATA_DIR': data_dir,
'WAL_DIR': wal_dir,
'SERVER_URL': EtcdInstaller.SERVER_URL.format(ip, server_port),
'CLIENT_URL': EtcdInstaller.CLIENT_URL.format(ip, client_port),
'LOCAL_CLIENT_URL': EtcdInstaller.CLIENT_URL.format('127.0.0.1', client_port),
'INITIAL_CLUSTER': '{0}={1}'.format(node_name, EtcdInstaller.SERVER_URL.format(ip, server_port)),
'INITIAL_STATE': 'new',
'INITIAL_PEERS': '-initial-advertise-peer-urls {0}'.format(EtcdInstaller.SERVER_URL.format(ip, server_port))},
target_name=target_name)
EtcdInstaller.start(cluster_name, client)
EtcdInstaller.wait_for_cluster(cluster_name, client, client_port=client_port)
EtcdInstaller._logger.debug('Creating cluster "{0}" on {1} completed'.format(cluster_name, ip))
示例15: is_running
# 需要导入模块: from ovs.extensions.services.service import ServiceManager [as 别名]
# 或者: from ovs.extensions.services.service.ServiceManager import get_service_status [as 别名]
def is_running(cluster_name, client):
"""
Checks if arakoon service is running
:param cluster_name: The name of the cluster service to check
:type cluster_name: str
:param client: Client on which to check the service
:type client: SSHClient
:return: None
"""
if ServiceManager.has_service('arakoon-{0}'.format(cluster_name), client=client):
return ServiceManager.get_service_status('arakoon-{0}'.format(cluster_name), client=client)[0]
return False