setValue() public method

Sets policy settings.
public setValue ( string $category, string $name, integer $enabled, array $value )
$category string Governance category name
$name string Governance policy name
$enabled integer Possible values: 1 - Enable policy, 0 - disable policy
$value array Governance policy settings to set
コード例 #1
1
ファイル: Governance.php プロジェクト: rickb838/scalr
 public function xSaveAction()
 {
     $this->request->defineParams(array('category' => array('type' => 'string'), 'name' => array('type' => 'string'), 'value' => array('type' => 'json')));
     $governance = new Scalr_Governance($this->getEnvironmentId());
     $category = $this->getParam('category');
     $name = $this->getParam('name');
     $value = $this->getParam('value');
     if ($category == Scalr_Governance::CATEGORY_GENERAL && $name == Scalr_Governance::GENERAL_LEASE) {
         $enabled = (bool) $value['limits']['enableDefaultLeaseDuration'];
         unset($value['limits']['enableDefaultLeaseDuration']);
         if (!$governance->isEnabled(Scalr_Governance::CATEGORY_GENERAL, Scalr_Governance::GENERAL_LEASE) && $value['enabled'] == 1 && $enabled) {
             $dt = new DateTime();
             $dt->add(new DateInterval('P' . $value['limits']['defaultLifePeriod'] . 'D'));
             $farms = $this->db->GetCol('SELECT id FROM farms WHERE env_id = ? AND status = ?', array($this->getEnvironmentId(), FARM_STATUS::RUNNING));
             foreach ($farms as $farmId) {
                 $farm = DBFarm::LoadByID($farmId);
                 $farm->SetSetting(DBFarm::SETTING_LEASE_STATUS, 'Active');
                 $farm->SetSetting(DBFarm::SETTING_LEASE_TERMINATE_DATE, $dt->format('Y-m-d H:i:s'));
                 $farm->SetSetting(DBFarm::SETTING_LEASE_NOTIFICATION_SEND, '');
                 $farm->SetSetting(DBFarm::SETTING_LEASE_EXTEND_CNT, 0);
             }
         }
     }
     $governance->setValue($category, $name, $value);
     $this->response->success('Successfully saved');
 }
コード例 #2
0
ファイル: Governance.php プロジェクト: recipe/scalr
 public function xSaveAction()
 {
     $this->request->defineParams(array('name' => array('type' => 'string'), 'value' => array('type' => 'json')));
     $governance = new Scalr_Governance($this->getEnvironmentId());
     $governance->setValue($this->request->getParam('name'), $this->request->getParam('value'));
     $this->response->success('Successfully saved');
 }
コード例 #3
0
ファイル: Environments.php プロジェクト: rickb838/scalr
 public function xCloneAction()
 {
     if (!$this->user->isAccountSuperAdmin() && !$this->request->isAllowed(Acl::RESOURCE_ENVADMINISTRATION_ENV_CLOUDS)) {
         throw new Scalr_Exception_InsufficientPermissions();
     }
     $params = array('envId' => array('type' => 'int'), 'name' => array('type' => 'string', 'validator' => array(Scalr_Validator::REQUIRED => true, Scalr_Validator::NOHTML => true)));
     $this->request->defineParams($params);
     $this->request->validate();
     $oldEnv = Scalr_Environment::init()->loadById($this->getParam('envId'));
     $this->user->getPermissions()->validate($oldEnv);
     if ($this->request->isValid()) {
         if (!$this->user->isAccountOwner() && !$this->user->isAccountSuperAdmin()) {
             throw new Scalr_Exception_InsufficientPermissions();
         }
         $this->user->getAccount()->validateLimit(Scalr_Limits::ACCOUNT_ENVIRONMENTS, 1);
         $env = $this->user->getAccount()->createEnvironment($this->getParam('name'));
         $env->status = Scalr_Environment::STATUS_ACTIVE;
         //Copy cloud credentials
         $cloudConfig = $oldEnv->getFullConfiguration();
         foreach ($cloudConfig as $group => $props) {
             $env->setPlatformConfig($props, null, $group);
         }
         //Copy teams & ACLs
         $teams = $oldEnv->getTeams();
         foreach ($teams as $teamId) {
             $env->addTeam($teamId);
         }
         //Copy Env level global variables
         $oldGv = new Scalr_Scripting_GlobalVariables($oldEnv->clientId, $oldEnv->id, Scalr_Scripting_GlobalVariables::SCOPE_ENVIRONMENT);
         $variables = $oldGv->getValues();
         $newGv = new Scalr_Scripting_GlobalVariables($env->clientId, $env->id, Scalr_Scripting_GlobalVariables::SCOPE_ENVIRONMENT);
         $newGv->setValues($variables);
         //Copy governance rules
         $oldGov = new Scalr_Governance($oldEnv->id);
         $govRules = $oldGov->getValues();
         $newGov = new Scalr_Governance($env->id);
         foreach ($govRules as $category => $rules) {
             foreach ($rules as $name => $data) {
                 $newGov->setValue($category, $name, $data);
             }
         }
         $this->response->success("Environment successfully cloned");
         $this->response->data(array('env' => array('id' => $env->id, 'name' => $env->name, 'status' => $env->status, 'platforms' => $env->getEnabledPlatforms(), 'teams' => $teams, 'ccId' => $env->getPlatformConfigValue(Scalr_Environment::SETTING_CC_ID))));
     } else {
         $this->response->failure($this->request->getValidationErrorsMessage());
     }
 }