Exemplo n.º 1
0
 public static function getActionState($bid)
 {
     $result = array();
     $shellAdapter = new ShellAdapter();
     $execRes = $shellAdapter->syncExec("sudo -u root /opt/webdir/bin/bx-process -a status -t " . $bid . " -o json");
     $data = $shellAdapter->getLastOutput();
     if ($execRes) {
         $arData = json_decode($data, true);
         if (isset($arData["params"][$bid])) {
             $result = $arData["params"][$bid];
         }
         if ($result["status"] == "finished") {
             Logger::addRecord(Logger::LOG_LEVEL_INFO, "SCALE_ACTION_CHECK_STATE", $bid, Loc::getMessage("SCALE_ACTIONSDATA_ACTION_FINISHED"));
         } elseif ($result["status"] == "error") {
             Logger::addRecord(Logger::LOG_LEVEL_ERROR, "SCALE_ACTION_CHECK_STATE", $bid, Loc::getMessage("SCALE_ACTIONSDATA_ACTION_ERROR"));
         }
         if (self::$logLevel >= Logger::LOG_LEVEL_DEBUG) {
             Logger::addRecord(Logger::LOG_LEVEL_DEBUG, "SCALE_ACTION_CHECK_STATE", $bid, $data);
         }
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Checks if some action is running
  * after page refresh, or then smb. else come to page
  * during the action running.
  * @return array - Action params
  */
 public static function checkRunningAction()
 {
     $result = array();
     $shellAdapter = new ShellAdapter();
     $execRes = $shellAdapter->syncExec("sudo -u root /opt/webdir/bin/bx-process -a list -o json");
     $data = $shellAdapter->getLastOutput();
     if ($execRes) {
         $arData = json_decode($data, true);
         $result = array();
         if (isset($arData["params"]) && is_array($arData["params"])) {
             foreach ($arData["params"] as $bid => $actionParams) {
                 if (strpos($bid, 'common_') === 0) {
                     // || strpos($bid, 'monitor_') === 0)
                     continue;
                 }
                 if ($actionParams["status"] == "running") {
                     $result = array($bid => $actionParams);
                     break;
                 }
             }
         }
     }
     return $result;
 }
Exemplo n.º 3
0
 protected static function getAnsibleSetup($hostname)
 {
     static $info = array();
     if (!isset($info[$hostname])) {
         $shellAdapter = new ShellAdapter();
         $execRes = $shellAdapter->syncExec("sudo -u root /usr/bin/ansible " . $hostname . " -m setup");
         $serversData = $shellAdapter->getLastOutput();
         $pos1 = strpos($serversData, ">>");
         $serversData = substr($serversData, $pos1 + 3 - strlen($serversData));
         if ($execRes) {
             $info[$hostname] = json_decode($serversData, true);
         } else {
             $info[$hostname] = array();
         }
     }
     return $info[$hostname];
 }
Exemplo n.º 4
0
 public static function getNetworkInterfaces()
 {
     $result = array();
     $shellAdapter = new ShellAdapter();
     $execRes = $shellAdapter->syncExec("sudo -u root /opt/webdir/bin/bx-node -o json");
     $jsonData = $shellAdapter->getLastOutput();
     if ($execRes) {
         $arData = json_decode($jsonData, true);
         if (isset($arData["params"]["pool_interfaces"])) {
             $result = $arData["params"]["pool_interfaces"];
         }
         if (is_array($result)) {
             foreach ($result as $iface => $ip) {
                 $result[$iface] = $iface . " (" . $ip . ")";
             }
         }
     }
     return $result;
 }
Exemplo n.º 5
0
 /**
  * Add host from order to pull.
  * @param string $providerId Provider identifier.
  * @param string $taskId Task identifier.
  * @return int
  * @throws \Bitrix\Main\ArgumentNullException
  */
 public static function addToPullFromOrder($providerId, $taskId)
 {
     if (strlen($providerId) <= 0) {
         throw new ArgumentNullException("providerId");
     }
     if (strlen($taskId) <= 0) {
         throw new ArgumentNullException("taskId");
     }
     $result = false;
     $shellAdapter = new ShellAdapter();
     $execRes = $shellAdapter->syncExec("sudo -u root /opt/webdir/bin/bx-provider -a order_to_host --provider " . $providerId . "  --task_id " . $taskId . " -o json");
     $jsonData = $shellAdapter->getLastOutput();
     if ($execRes) {
         $result = json_decode($jsonData, true);
     }
     return $result;
 }