function restart_active_convergence_commands($papi_id, $package) { $package = (object) $package; // Get convergence commands to restart $active_commands = xmlrpc_get_active_convergence_commands($papi_id, $package->id); if ($active_commands) { // WTF, this dyngroup function needs pkgs and msc.... if (in_array('pkgs', $_SESSION['modulesList'])) { require_once 'modules/pkgs/includes/xmlrpc.php'; } else { new NotifyWidgetWarn(_T("Failed to load some pkgs module", "pkgs")); return False; } if (in_array('msc', $_SESSION['modulesList'])) { require_once 'modules/msc/includes/commands_xmlrpc.inc.php'; } else { new NotifyWidgetWarn(_T("Failed to load some msc module", "pkgs")); return False; } // We need ServerAPI for some convergence methods... $ServerAPI = getPApiDetail($papi_id); // ... but without 'uuid' unset($ServerAPI['uuid']); $cmd_type = 2; $active = 1; $ordered_proxies = array(); $mode = 'push'; function __get_command_start_date($cmd_id) { $command_details = command_detail($cmd_id); list($year, $month, $day, $hour, $minute, $second) = $command_details['start_date']; return sprintf("%s-%s-%s %s:%s:%s", $year, $month, $day, $hour, $minute, $second); } foreach ($active_commands as $command) { $gid = $command['gid']; $cmd_id = $command['cmd_id']; /* Stop command */ stop_command($cmd_id); /* Set end date of this command to now(), don't touch to start date */ $start_date = __get_command_start_date($cmd_id); extend_command($cmd_id, $start_date, date("Y-m-d H:i:s")); /* Create new command */ $deploy_group_id = xmlrpc_get_deploy_group_id($gid, $ServerAPI, $package->id); $params = xmlrpc_get_convergence_phases($gid, $ServerAPI, $package->id); $command_id = add_command_api($package->id, NULL, $params, $ServerAPI, $mode, $deploy_group_id, $ordered_proxies, $cmd_type); /* Update convergence DB */ $updated_datas = array('active' => $active, 'commandId' => intval($command_id), 'cmdPhases' => $params); xmlrpc_edit_convergence_datas($gid, $ServerAPI, $package->id, $updated_datas); } } }
$params["papi"] = $papi; $params["name"] = $hostname; $params["hostname"] = $hostname; $params["uuid"] = $uuid; $params["gid"] = $gid; $params["from"] = $from; $params["pid"] = $pid; $params["create_directory"] = 'on'; $params["next_connection_delay"] = web_def_delay(); $params["max_connection_attempt"] = web_def_attempts(); if ($_GET['editConvergence']) { $ServerAPI = new ServerAPI(); $ServerAPI->fromURI($papi); $cmd_id = xmlrpc_get_convergence_command_id($gid, $ServerAPI, $pid); $command_details = command_detail($cmd_id); $command_phases = xmlrpc_get_convergence_phases($gid, $ServerAPI, $pid); $params["ltitle"] = $command_details['title']; $params["maxbw"] = $command_details['maxbw'] / 1024; $params["copy_mode"] = $command_details['copy_mode']; $params["deployment_intervals"] = $command_details['deployment_intervals']; $params["parameters"] = $command_details['parameters']; $params["editConvergence"] = True; $params["active"] = xmlrpc_is_convergence_active($gid, $ServerAPI, $pid) ? 'on' : ''; // phases foreach (array('start_script', 'clean_on_success', 'do_reboot', 'do_wol', 'do_inventory', 'do_halt') as $key) { if ($command_phases) { // $command_phases is False with old convergence implementation (without phases stored in Convergence DB) if ($key == 'do_halt') { $params['issue_halt_to_done'] = in_array('done', $command_phases['issue_halt_to']) ? 'on' : ''; } else { $params[$key] = $command_phases[$key];