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'
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'
def create_plan_to_start_services_after_rebooting(services, rebooted_hosts, components): start_plan = metalogic( yadtshell.settings.START, services, plan_post_handler=identity) for start_action in start_plan.actions: if start_action.uri in services: for host_uri in get_all_adjacent_needed_hosts(start_action.uri, components): if host_uri in rebooted_hosts: start_action.preconditions.add(yadtshell.actions.TargetState( host_uri, 'state', 'rebooted')) return start_plan
def create_plan_to_stop_all_services_on(host_uris): return metalogic( yadtshell.settings.STOP, host_uris, plan_post_handler=identity)