Exemplo n.º 1
0
 private static function copyHostTemplates($deployment, $revision, array $htInfo)
 {
     if (self::$init === false) {
         self::init();
     }
     foreach ($htInfo as $ht => $htArray) {
         if ($htArray['deployment'] == self::$m_commonrepo && $htArray['deployment'] == 'common') {
             continue;
         }
         if ($htArray['deployment'] == self::$m_commonrepo) {
             continue;
         }
         unset($htArray['deployment']);
         foreach ($htArray as $key => $value) {
             if (is_array($htArray[$key])) {
                 $htArray[$key] = implode(',', $htArray[$key]);
             }
         }
         RevDeploy::createDeploymentHostTemplate($deployment, $ht, $htArray, $revision);
     }
 }
 public function copy_write()
 {
     $viewData = new ViewData();
     $deployment = $this->getDeployment('host_template_error');
     $this->checkGroupAuth($deployment);
     $this->checkDeploymentRevStatus($deployment);
     $modrevision = RevDeploy::getDeploymentNextRev($deployment);
     $hostName = $this->getParam('hostName');
     $hostInfo = $this->fetchHostTemplateInfo($deployment, 'copy_write', $modrevision);
     if (RevDeploy::existsDeploymentHostTemplate($deployment, $hostName, $modrevision) === true) {
         $viewData->error = 'Host template information exists for ' . $hostName . ' into ' . $deployment . ' Deployment';
         $viewData->action = 'copy_write';
         $viewData->hosttemplate = $hostName;
         $viewData->deployment = $deployment;
         $viewData->hosttemplates = RevDeploy::getCommonMergedDeploymentHostTemplates($deployment, $modrevision);
         $viewData->hostchkcmds = RevDeploy::getCommonMergedDeploymentHostCheckCommands($deployment, $modrevision);
         $viewData->timeperiods = RevDeploy::getCommonMergedDeploymentTimeperiods($deployment, $modrevision);
         $viewData->contacts = RevDeploy::getCommonMergedDeploymentContacts($deployment, $modrevision);
         $viewData->contactgroups = RevDeploy::getCommonMergedDeploymentContactGroups($deployment, $modrevision);
         $viewData->hostInfo = $hostInfo;
         $this->sendResponse('host_template_action_stage', $viewData);
     }
     if (RevDeploy::createDeploymentHostTemplate($deployment, $hostName, $hostInfo, $modrevision) === false) {
         $viewData->header = $this->getErrorHeader('host_template_error');
         $viewData->error = 'Unable to write host tempalte information for ' . $hostName . ' into ' . $deployment . ' Deployment';
         $this->sendError('generic_error', $viewData);
     }
     $viewData->deployment = $deployment;
     $viewData->host = $hostName;
     $this->sendResponse('host_template_write', $viewData);
 }
Exemplo n.º 3
0
        // Lets make sure we have the minimum required keys for defining a host template
        validateContacts($app, $deployment, $hostTemplateInfo);
        foreach ($required_keys as $rkey) {
            if (!isset($hostTemplateInfo[$rkey]) || empty($hostTemplateInfo[$rkey])) {
                $apiResponse = new APIViewData(1, $deployment, "Unable to detect required parameter {$rkey} " . hosttemplate_rkeyMessage($rkey));
                $app->halt(404, $apiResponse->returnJson());
            }
        }
    }
    $hostTemplateInfo = hosttemplate_validate($app, $deployment, $hostTemplateInfo);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (RevDeploy::existsDeploymentHostTemplate($deployment, $hostTemplateInfo['name'], $deployRev) === true) {
        RevDeploy::modifyDeploymentHostTemplate($deployment, $hostTemplateInfo['name'], $hostTemplateInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Modified Host Template " . $hostTemplateInfo['name']);
    } else {
        RevDeploy::createDeploymentHostTemplate($deployment, $hostTemplateInfo['name'], $hostTemplateInfo, $deployRev);
        $apiResponse = new APIViewData(0, $deployment, "Successfully Created Host Template " . $hostTemplateInfo['name']);
    }
    $apiResponse->printJson();
})->name('saigon-api-create-host-template');
$app->delete('/sapi/hosttemplate/:deployment/:hosttemplate', function ($deployment, $hosttemplate) use($app) {
    check_deployment_exists($app, $deployment);
    check_auth($app, $deployment);
    check_revision_status($deployment);
    $deployRev = RevDeploy::getDeploymentNextRev($deployment);
    if (preg_match('/,/', $hosttemplate)) {
        $hosttemplates = preg_split('/\\s?,\\s?/', $hosttemplate);
        foreach ($hosttemplates as $httemp) {
            RevDeploy::deleteDeploymentHostTemplate($deployment, $httemp, $deployRev);
        }
    } else {