本文整理汇总了Python中paasta_tools.utils.paasta_print函数的典型用法代码示例。如果您正苦于以下问题:Python paasta_print函数的具体用法?Python paasta_print怎么用?Python paasta_print使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了paasta_print函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: main
def main():
args = parse_args()
jobs = chronos_tools.get_chronos_jobs_for_cluster(cluster=args.cluster, soa_dir=args.soa_dir)
# TODO use compose_job_id instead of constructing string once INTERNAL_SPACER deprecated
composed = ['%s%s%s' % (name, chronos_tools.INTERNAL_SPACER, job) for name, job in jobs]
paasta_print('\n'.join(composed))
sys.exit(0)
开发者ID:somic,项目名称:paasta,代码行数:7,代码来源:list_chronos_jobs.py
示例2: launch_jobs
def launch_jobs(context, num_jobs, state, service, job):
client = context.chronos_client
jobs = [{
'async': False,
'command': 'echo 1',
'epsilon': 'PT15M',
'name': compose_job_id(service, job),
'owner': 'paasta',
'disabled': True,
'schedule': 'R/2014-01-01T00:00:00Z/PT60M',
} for x in range(0, int(num_jobs))]
for job in jobs:
try:
paasta_print('attempting to create job %s' % job['name'])
client.add(job)
except Exception:
paasta_print('Error creating test job: %s' % json.dumps(job))
raise
# a 'configured' job is one which has had the appropriate
# yelp-soa configs into place.
# an 'unconfigured' job represents a job which may at one stage
# been a configured chronos job, but no longer has the
# corresponding configuration in place the target for.
# 'unconfigured' jobs are the target for cleanup_chronos_jobs
if state == "configured":
context.configured_job_names = [job['name'] for job in jobs]
elif state == "unconfigured":
context.unconfigured_job_names = [job['name'] for job in jobs]
开发者ID:somic,项目名称:paasta,代码行数:29,代码来源:cleanup_chronos_job_steps.py
示例3: validate_schema
def validate_schema(file_path, file_type):
"""Check if the specified config file has a valid schema
:param file_path: path to file to validate
:param file_type: what schema type should we validate against
"""
schema = get_schema(file_type)
if (schema is None):
paasta_print('%s: %s' % (SCHEMA_NOT_FOUND, file_path))
return
validator = Draft4Validator(schema, format_checker=FormatChecker())
basename = os.path.basename(file_path)
extension = os.path.splitext(basename)[1]
try:
config_file = get_file_contents(file_path)
except IOError:
paasta_print('%s: %s' % (FAILED_READING_FILE, file_path))
return False
if extension == '.yaml':
config_file_object = yaml.load(config_file)
elif extension == '.json':
config_file_object = json.loads(config_file)
else:
config_file_object = config_file
try:
validator.validate(config_file_object)
except ValidationError:
paasta_print('%s: %s' % (SCHEMA_INVALID, file_path))
errors = validator.iter_errors(config_file_object)
paasta_print(' Validation Message: %s' % exceptions.best_match(errors).message)
else:
paasta_print('%s: %s' % (SCHEMA_VALID, basename))
return True
开发者ID:somic,项目名称:paasta,代码行数:34,代码来源:validate.py
示例4: app_has_tasks
def app_has_tasks(client, app_id, expected_tasks, exact_matches_only=False):
"""A predicate function indicating whether an app has launched *at least* expected_tasks
tasks.
Raises a marathon.NotFoundError when no app with matching id is found.
:param client: the marathon client
:param app_id: the app_id to which the tasks should belong. The leading / that marathon appends to
app_ids is added here.
:param expected_tasks: the number of tasks to check for
:param exact_matches_only: a boolean indicating whether we require exactly expected_tasks to be running
:returns: a boolean indicating whether there are atleast expected_tasks tasks with
an app id matching app_id
"""
app_id = "/%s" % app_id
try:
tasks = client.list_tasks(app_id=app_id)
except NotFoundError:
paasta_print("no app with id %s found" % app_id)
raise
paasta_print("app %s has %d of %d expected tasks" % (app_id, len(tasks), expected_tasks))
if exact_matches_only:
return len(tasks) == expected_tasks
else:
return len(tasks) >= expected_tasks
开发者ID:Yelp,项目名称:paasta,代码行数:25,代码来源:marathon_tools.py
示例5: cmd
def cmd(command):
stream = False
timeout = 60
output = []
try:
process = Popen(shlex.split(command), stdout=PIPE, stderr=STDOUT, stdin=None)
process.name = command
# start the timer if we specified a timeout
if timeout:
proctimer = threading.Timer(timeout, _timeout, (process,))
proctimer.start()
for line in iter(process.stdout.readline, ''):
if stream:
paasta_print(line.rstrip('\n'))
output.append(line.rstrip('\n'))
# when finished, get the exit code
returncode = process.wait()
except OSError as e:
output.append(e.strerror.rstrip('\n'))
returncode = e.errno
except (KeyboardInterrupt, SystemExit):
# need to clean up the timing thread here
if timeout:
proctimer.cancel()
raise
else:
# Stop the timer
if timeout:
proctimer.cancel()
if returncode == -9:
output.append("Command '%s' timed out (longer than %ss)" % (command, timeout))
return returncode, '\n'.join(output)
开发者ID:somic,项目名称:paasta,代码行数:32,代码来源:graceful_container_drain.py
示例6: do_GET
def do_GET(self):
paasta_print("Got GET for %s" % self.path)
try:
FakeHTTPServer.paths.append(self.path)
self.send_response(self.status_code)
except Exception as e:
paasta_print(e)
开发者ID:somic,项目名称:paasta,代码行数:7,代码来源:http_drain_method_steps.py
示例7: perform_http_healthcheck
def perform_http_healthcheck(url, timeout):
"""Returns true if healthcheck on url succeeds, false otherwise
:param url: the healthcheck url
:param timeout: timeout in seconds
:returns: True if healthcheck succeeds within number of seconds specified by timeout, false otherwise
"""
try:
with Timeout(seconds=timeout):
try:
res = requests.get(url)
except requests.ConnectionError:
return (False, "http request failed: connection failed")
except TimeoutError:
return (False, "http request timed out after %d seconds" % timeout)
if 'content-type' in res.headers and ',' in res.headers['content-type']:
paasta_print(PaastaColors.yellow(
"Multiple content-type headers detected in response."
" The Mesos healthcheck system will treat this as a failure!"))
return (False, "http request succeeded, code %d" % res.status_code)
# check if response code is valid per https://mesosphere.github.io/marathon/docs/health-checks.html
elif res.status_code >= 200 and res.status_code < 400:
return (True, "http request succeeded, code %d" % res.status_code)
elif res.status_code >= 400:
return (False, "http request failed, code %d" % res.status_code)
开发者ID:somic,项目名称:paasta,代码行数:26,代码来源:local_run.py
示例8: run_healthcheck_on_container
def run_healthcheck_on_container(
docker_client,
container_id,
healthcheck_mode,
healthcheck_data,
timeout
):
"""Performs healthcheck on a container
:param container_id: Docker container id
:param healthcheck_mode: one of 'http', 'tcp', or 'cmd'
:param healthcheck_data: a URL when healthcheck_mode is 'http' or 'tcp', a command if healthcheck_mode is 'cmd'
:param timeout: timeout in seconds for individual check
:returns: a tuple of (bool, output string)
"""
healthcheck_result = (False, "unknown")
if healthcheck_mode == 'cmd':
healthcheck_result = perform_cmd_healthcheck(docker_client, container_id, healthcheck_data, timeout)
elif healthcheck_mode == 'http':
healthcheck_result = perform_http_healthcheck(healthcheck_data, timeout)
elif healthcheck_mode == 'tcp':
healthcheck_result = perform_tcp_healthcheck(healthcheck_data, timeout)
else:
paasta_print(PaastaColors.yellow(
"Healthcheck mode '%s' is not currently supported!" % healthcheck_mode))
sys.exit(1)
return healthcheck_result
开发者ID:somic,项目名称:paasta,代码行数:27,代码来源:local_run.py
示例9: test_group_slaves_by_key_func
def test_group_slaves_by_key_func():
slaves = [
{
'id': 'somenametest-slave',
'hostname': 'test.somewhere.www',
'resources': {
'cpus': 75,
'disk': 250,
'mem': 100,
},
'attributes': {
'habitat': 'somenametest-habitat',
},
},
{
'id': 'somenametest-slave2',
'hostname': 'test2.somewhere.www',
'resources': {
'cpus': 500,
'disk': 200,
'mem': 750,
},
'attributes': {
'habitat': 'somenametest-habitat-2',
},
},
]
actual = metastatus_lib.group_slaves_by_key_func(
lambda x: x['attributes']['habitat'],
slaves
)
assert len(actual.items()) == 2
for k, v in actual.items():
paasta_print(k, v)
assert len(list(v)) == 1
开发者ID:Yelp,项目名称:paasta,代码行数:35,代码来源:test_metastatus_lib.py
示例10: start_chronos_job
def start_chronos_job(service, instance, job_id, client, cluster, job_config, complete_job_config, emergency=False):
"""
Calls the 'manual start' Chronos endpoint (https://mesos.github.io/chronos/docs/api.html#manually-starting-a-job),
running the job now regardless of its 'schedule'. The job's "schedule" is unmodified. If a job is disabled,
this function does not do anything.
"""
name = PaastaColors.cyan(job_id)
# The job should be run immediately as long as the job is not disabled via the 'disabled' key in soa-configs or has
# been previously stopped.
if complete_job_config['disabled']:
paasta_print(PaastaColors.red("You cannot emergency start a disabled job. Run `paasta start` first."))
else:
log_reason = PaastaColors.red("EmergencyStart") if emergency else "Brutal bounce"
_log(
service=service,
line="%s: Starting manual run of %s in Chronos" % (log_reason, name),
component="deploy",
level="event",
cluster=cluster,
instance=instance
)
client.update(complete_job_config)
client.run(job_id)
开发者ID:Yelp,项目名称:paasta,代码行数:25,代码来源:chronos_serviceinit.py
示例11: run_cleanup_marathon_job
def run_cleanup_marathon_job(context, flags, expected_return_code):
cmd = '../paasta_tools/cleanup_marathon_jobs.py --soa-dir %s %s' % (context.soa_dir, flags)
paasta_print('Running cmd %s' % (cmd))
exit_code, output = _run(cmd)
paasta_print(output)
assert exit_code == int(expected_return_code)
开发者ID:somic,项目名称:paasta,代码行数:7,代码来源:cleanup_marathon_job_steps.py
示例12: main
def main():
strings = []
for full_name, config in marathon_tools.get_all_namespaces():
if 'proxy_port' in config:
strings.append('%s:%s' % (full_name, config['proxy_port']))
strings = sorted(strings)
paasta_print("synapse_srv_namespaces=" + ','.join(strings))
sys.exit(0)
开发者ID:somic,项目名称:paasta,代码行数:8,代码来源:synapse_srv_namespaces_fact.py
示例13: git_repo_check
def git_repo_check(service):
git_url = get_git_url(service)
cmd = "git ls-remote %s" % git_url
returncode, _ = _run(cmd, timeout=5)
if returncode == 0:
paasta_print(PaastaCheckMessages.GIT_REPO_FOUND)
else:
paasta_print(PaastaCheckMessages.git_repo_missing(git_url))
开发者ID:somic,项目名称:paasta,代码行数:8,代码来源:check.py
示例14: print_log
def print_log(line, requested_levels, raw_mode=False):
"""Mostly a stub to ease testing. Eventually this may do some formatting or
something.
"""
if raw_mode:
paasta_print(line, end=" ") # suppress trailing newline since scribereader already attached one
else:
paasta_print(prettify_log_line(line, requested_levels))
开发者ID:somic,项目名称:paasta,代码行数:8,代码来源:logs.py
示例15: docker_check
def docker_check():
"""Check whether Dockerfile exists in service directory, and is valid.
Prints suitable message depending on outcome"""
docker_file_path = is_file_in_dir("Dockerfile", os.getcwd())
if docker_file_path:
paasta_print(PaastaCheckMessages.DOCKERFILE_FOUND)
else:
paasta_print(PaastaCheckMessages.DOCKERFILE_MISSING)
开发者ID:somic,项目名称:paasta,代码行数:8,代码来源:check.py
示例16: deploy_has_security_check
def deploy_has_security_check(service, soa_dir):
pipeline = get_pipeline_config(service, soa_dir)
steps = [step["step"] for step in pipeline]
if "security-check" in steps:
paasta_print(PaastaCheckMessages.DEPLOY_SECURITY_FOUND)
return True
else:
paasta_print(PaastaCheckMessages.DEPLOY_SECURITY_MISSING)
return False
开发者ID:somic,项目名称:paasta,代码行数:9,代码来源:check.py
示例17: deploy_check
def deploy_check(service_path):
"""Check whether deploy.yaml exists in service directory. Prints success or
error message.
:param service_path: path to a directory containing deploy.yaml"""
if is_file_in_dir("deploy.yaml", service_path):
paasta_print(PaastaCheckMessages.DEPLOY_YAML_FOUND)
else:
paasta_print(PaastaCheckMessages.DEPLOY_YAML_MISSING)
开发者ID:somic,项目名称:paasta,代码行数:9,代码来源:check.py
示例18: service_dir_check
def service_dir_check(service, soa_dir):
"""Check whether directory service exists in /nail/etc/services
:param service: string of service name we wish to inspect
"""
try:
validate_service_name(service, soa_dir)
paasta_print(PaastaCheckMessages.service_dir_found(service, soa_dir))
except NoSuchService:
paasta_print(PaastaCheckMessages.service_dir_missing(service, soa_dir))
开发者ID:somic,项目名称:paasta,代码行数:9,代码来源:check.py
示例19: check_exit_code
def check_exit_code(context, expected_exit_code):
try:
assert context.exit_code == expected_exit_code, \
"expected %d, got %d" % (expected_exit_code, context.exit_code)
except AssertionError:
# behave likes to back up by two lines and then print some stuff, which clobbers my output, so I stick some
# extra newlines on here.
paasta_print("Output of setup_chronos_job:\n" + context.output + "\n")
raise
开发者ID:somic,项目名称:paasta,代码行数:9,代码来源:setup_chronos_job_steps.py
示例20: write_paasta_config
def write_paasta_config(variables, template, destination):
paasta_print("Using cookiecutter template from %s" % template)
cookiecutter(
template=template,
extra_context=variables,
output_dir=destination,
overwrite_if_exists=True,
no_input=not sys.stdout.isatty(),
)
开发者ID:somic,项目名称:paasta,代码行数:9,代码来源:fsm.py
注:本文中的paasta_tools.utils.paasta_print函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论