コード例 #1
0
ファイル: restart.py プロジェクト: Woi/yadtshell
def restart(protocol=None, uris=None, parallel=None, **kwargs):
    logger.debug("uris: %s" % uris)
    logger.debug("parallel: %s" % parallel)
    logger.debug("kwargs: %s" % kwargs)

    components = restore_current_state()
    service_uris = expand_hosts(uris)
    service_uris = glob_hosts(components, service_uris)

    logging.debug("service uris: %s" % service_uris)

    stop_plan = metalogic(STOP, uris, plan_post_handler=identity)

    service_states = {}
    for action in stop_plan.actions:
        service_states[action.uri] = components[action.uri].state
    logging.debug("current states: %s" % service_states)

    start_uris = [uri for uri, state in service_states.iteritems()
                  if state == UP] + uris
    start_uris = set(start_uris)
    logging.info("restarting %s" % ", ".join(start_uris))
    start_plan = metalogic(START, start_uris, plan_post_handler=identity)

    plan = ActionPlan('restart', [stop_plan, start_plan], nr_workers=1)

    for line in plan.dump(include_preconditions=True).splitlines():
        logging.info(line)

    plan = apply_instructions(plan, parallel)
    dump_action_plan('restart', plan)
    return 'restart'
コード例 #2
0
ファイル: restart.py プロジェクト: transacid/yadtshell
def restart(protocol=None, uris=None, parallel=None, **kwargs):
    logger.debug("uris: %s" % uris)
    logger.debug("parallel: %s" % parallel)
    logger.debug("kwargs: %s" % kwargs)

    components = restore_current_state()
    service_uris = expand_hosts(uris)
    service_uris = glob_hosts(components, service_uris)

    logging.debug("service uris: %s" % service_uris)

    stop_plan = metalogic(STOP, uris, plan_post_handler=identity)

    service_states = {}
    for action in stop_plan.actions:
        service_states[action.uri] = components[action.uri].state
    logging.debug("current states: %s" % service_states)

    start_uris = [
        uri for uri, state in service_states.iteritems() if state == UP
    ] + uris
    start_uris = set(start_uris)
    logging.info("restarting %s" % ", ".join(start_uris))
    start_plan = metalogic(START, start_uris, plan_post_handler=identity)

    plan = ActionPlan('restart', [stop_plan, start_plan], nr_workers=1)

    for line in plan.dump(include_preconditions=True).splitlines():
        logging.info(line)

    plan = apply_instructions(plan, parallel)
    dump_action_plan('restart', plan)
    return 'restart'
コード例 #3
0
def reboot(protocol=None, uris=None, parallel=None, **kwargs):
    for uri in uris:
        if not uri.startswith("host://"):
            message = "Cannot reboot %s" % uri
            logger.error(message)
            raise ValueError(message)

    components = restore_current_state()
    host_uris = expand_hosts(uris)
    host_uris = glob_hosts(components, host_uris)

    hosts_to_reboot = uris
    stop_plan = create_plan_to_stop_all_services_on(hosts_to_reboot)

    all_stopped_services = set()
    for action in stop_plan.actions:
        all_stopped_services.add(action.uri)

    start_plan = create_plan_to_start_services_after_rebooting(all_stopped_services,
                                                               hosts_to_reboot,
                                                               components)

    reboot_actions = set([create_reboot_action_for(components[host_uri]) for host_uri in hosts_to_reboot])

    all_actions = set(start_plan.actions) | set(
        stop_plan.actions) | reboot_actions
    all_plan = ActionPlan('all', all_actions)
    all_plan = chop_minimal_related_chunks(all_plan)

    reboot_chunks = set()
    for chunk in all_plan.actions:
        all_chunk_cmds = set(a.cmd for a in chunk.actions)
        if yadtshell.settings.UPDATE in all_chunk_cmds:
            reboot_chunks.add(chunk)
            continue

    prestart_chunks = set()
    for possible_prestart_chunk in all_plan.actions:
        if possible_prestart_chunk in reboot_chunks:
            continue
        if possible_prestart_chunk.is_not_empty:
            prestart_chunks.add(possible_prestart_chunk)

    plan = ActionPlan(
        'update', [ActionPlan('prestart', prestart_chunks),
                   ActionPlan('stoprebootstart', reboot_chunks)
                   ], nr_workers=1)
    plan = apply_instructions(plan, parallel)
    dump_action_plan('reboot', plan)

    return 'reboot'