本文整理匯總了Python中charmhelpers.core.host.service方法的典型用法代碼示例。如果您正苦於以下問題:Python host.service方法的具體用法?Python host.service怎麽用?Python host.service使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類charmhelpers.core.host
的用法示例。
在下文中一共展示了host.service方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: write
# 需要導入模塊: from charmhelpers.core import host [as 別名]
# 或者: from charmhelpers.core.host import service [as 別名]
def write(self, nagios_context, hostname, nagios_servicegroups):
nrpe_check_file = self._get_check_filename()
with open(nrpe_check_file, 'w') as nrpe_check_config:
nrpe_check_config.write("# check {}\n".format(self.shortname))
if nagios_servicegroups:
nrpe_check_config.write(
"# The following header was added automatically by juju\n")
nrpe_check_config.write(
"# Modifying it will affect nagios monitoring and alerting\n")
nrpe_check_config.write(
"# servicegroups: {}\n".format(nagios_servicegroups))
nrpe_check_config.write("command[{}]={}\n".format(
self.command, self.check_cmd))
if not os.path.exists(NRPE.nagios_exportdir):
log('Not writing service config as {} is not accessible'.format(
NRPE.nagios_exportdir))
else:
self.write_service_config(nagios_context, hostname,
nagios_servicegroups)
示例2: test_pauses_a_running_upstart_service
# 需要導入模塊: from charmhelpers.core import host [as 別名]
# 或者: from charmhelpers.core.host import service [as 別名]
def test_pauses_a_running_upstart_service(self, service, systemd,
service_running):
"""Pause on a running service will call service stop."""
service_name = 'foo-service'
service.side_effect = [True]
systemd.return_value = False
service_running.return_value = True
tempdir = mkdtemp(prefix="test_pauses_an_upstart_service")
conf_path = os.path.join(tempdir, "{}.conf".format(service_name))
# Just needs to exist
with open(conf_path, "w") as fh:
fh.write("")
self.addCleanup(rmtree, tempdir)
self.assertTrue(host.service_pause(service_name, init_dir=tempdir))
service.assert_called_with('stop', service_name)
override_path = os.path.join(
tempdir, "{}.override".format(service_name))
with open(override_path, "r") as fh:
override_contents = fh.read()
self.assertEqual("manual\n", override_contents)
示例3: test_pauses_a_stopped_upstart_service
# 需要導入模塊: from charmhelpers.core import host [as 別名]
# 或者: from charmhelpers.core.host import service [as 別名]
def test_pauses_a_stopped_upstart_service(self, service, systemd,
service_running):
"""Pause on a stopped service will not call service stop."""
service_name = 'foo-service'
service.side_effect = [True]
systemd.return_value = False
service_running.return_value = False
tempdir = mkdtemp(prefix="test_pauses_an_upstart_service")
conf_path = os.path.join(tempdir, "{}.conf".format(service_name))
# Just needs to exist
with open(conf_path, "w") as fh:
fh.write("")
self.addCleanup(rmtree, tempdir)
self.assertTrue(host.service_pause(service_name, init_dir=tempdir))
# Stop isn't called because service is already stopped
self.assertRaises(
AssertionError, service.assert_called_with, 'stop', service_name)
override_path = os.path.join(
tempdir, "{}.override".format(service_name))
with open(override_path, "r") as fh:
override_contents = fh.read()
self.assertEqual("manual\n", override_contents)
示例4: test_pauses_a_stopped_sysv_service
# 需要導入模塊: from charmhelpers.core import host [as 別名]
# 或者: from charmhelpers.core.host import service [as 別名]
def test_pauses_a_stopped_sysv_service(self, service, check_call,
systemd, service_running):
"""Pause does not call service stop on a stopped sysv service."""
service_name = 'foo-service'
service.side_effect = [True]
systemd.return_value = False
service_running.return_value = False
tempdir = mkdtemp(prefix="test_pauses_a_sysv_service")
sysv_path = os.path.join(tempdir, service_name)
# Just needs to exist
with open(sysv_path, "w") as fh:
fh.write("")
self.addCleanup(rmtree, tempdir)
self.assertTrue(host.service_pause(
service_name, init_dir=tempdir, initd_dir=tempdir))
# Stop isn't called because service is already stopped
self.assertRaises(
AssertionError, service.assert_called_with, 'stop', service_name)
check_call.assert_called_with(["update-rc.d", service_name, "disable"])
示例5: __init__
# 需要導入模塊: from charmhelpers.core import host [as 別名]
# 或者: from charmhelpers.core.host import service [as 別名]
def __init__(self, shortname, description, check_cmd):
super(Check, self).__init__()
# XXX: could be better to calculate this from the service name
if not re.match(self.shortname_re, shortname):
raise CheckException("shortname must match {}".format(
Check.shortname_re))
self.shortname = shortname
self.command = "check_{}".format(shortname)
# Note: a set of invalid characters is defined by the
# Nagios server config
# The default is: illegal_object_name_chars=`~!$%^&*"|'<>?,()=
self.description = description
self.check_cmd = self._locate_cmd(check_cmd)
示例6: add_haproxy_checks
# 需要導入模塊: from charmhelpers.core import host [as 別名]
# 或者: from charmhelpers.core.host import service [as 別名]
def add_haproxy_checks(nrpe, unit_name):
"""
Add checks for each service in list
:param NRPE nrpe: NRPE object to add check to
:param str unit_name: Unit name to use in check description
"""
nrpe.add_check(
shortname='haproxy_servers',
description='Check HAProxy {%s}' % unit_name,
check_cmd='check_haproxy.sh')
nrpe.add_check(
shortname='haproxy_queue',
description='Check HAProxy queue depth {%s}' % unit_name,
check_cmd='check_haproxy_queue_depth.sh')
示例7: service
# 需要導入模塊: from charmhelpers.core import host [as 別名]
# 或者: from charmhelpers.core.host import service [as 別名]
def service(subparser):
subparser.add_argument("action", help="The action to perform (start, stop, etc...)")
subparser.add_argument("service_name", help="Name of the service to control")
return host.service