示例#1
0
 public function editAction()
 {
     $platforms = array();
     $governanceEnabledPlatforms = array(SERVER_PLATFORMS::EC2, SERVER_PLATFORMS::CLOUDSTACK, SERVER_PLATFORMS::IDCF, SERVER_PLATFORMS::OPENSTACK, SERVER_PLATFORMS::NEBULA, SERVER_PLATFORMS::MIRANTIS, SERVER_PLATFORMS::VIO, SERVER_PLATFORMS::VERIZON, SERVER_PLATFORMS::CISCO, SERVER_PLATFORMS::HPCLOUD, SERVER_PLATFORMS::OCS, SERVER_PLATFORMS::RACKSPACENG_US, SERVER_PLATFORMS::AZURE);
     //intersection of enabled platforms and supported by governance
     foreach (array_intersect($this->getEnvironment()->getEnabledPlatforms(), $governanceEnabledPlatforms) as $platform) {
         //we only need ec2 locations at the moment
         $platforms[$platform] = $platform == SERVER_PLATFORMS::EC2 ? self::loadController('Platforms')->getCloudLocations($platform, false) : array();
     }
     $chefServers = [];
     foreach (ChefServer::getList($this->user->getAccountId(), $this->getEnvironmentId()) as $chefServer) {
         $chefServers[] = ['id' => $chefServer->id, 'url' => $chefServer->url, 'scope' => $chefServer->getScope()];
     }
     $governance = new Scalr_Governance($this->getEnvironmentId());
     $this->response->page('ui/core/governance/edit.js', array('platforms' => $platforms, 'values' => $governance->getValues(), 'chef' => ['servers' => $chefServers], 'scalr.aws.ec2.limits.security_groups_per_instance' => \Scalr::config('scalr.aws.ec2.limits.security_groups_per_instance')), array('ui/core/governance/lease.js'), array('ui/core/governance/edit.css'));
 }
示例#2
0
 /**
  * @param ChefServer $server
  */
 private function getServerData($server)
 {
     $data = ['id' => $server->id, 'url' => $server->url, 'username' => $server->username, 'status' => $server->isInUse($this->user->getAccountId(), $this->getEnvironmentId(true), $this->request->getScope()), 'scope' => $server->getScope()];
     if ($this->request->getScope() == $server->getScope()) {
         $data['authKey'] = $this->getCrypto()->decrypt($server->authKey);
         $data['vUsername'] = $server->vUsername;
         $data['vAuthKey'] = $this->getCrypto()->decrypt($server->vAuthKey);
     }
     return $data;
 }
示例#3
0
文件: Chef.php 项目: mheydt/scalr
 /**
  * @param int $servId
  * @param string $chefEnv
  */
 private function getChefClient($servId)
 {
     $criteria[] = ['id' => $servId];
     if ($this->user->isAdmin()) {
         $criteria[] = ['accountId' => null];
         $criteria[] = ['envId' => null];
         $criteria[] = ['level' => ChefServer::LEVEL_SCALR];
     } else {
         $criteria[] = ['$or' => [['$and' => [['accountId' => $this->user->getAccountId()], ['envId' => $this->getEnvironmentId(true)], ['level' => ChefServer::LEVEL_ENVIRONMENT]]], ['$and' => [['accountId' => $this->user->getAccountId()], ['envId' => null], ['level' => ChefServer::LEVEL_ACCOUNT]]], ['$and' => [['accountId' => null], ['envId' => null], ['level' => ChefServer::LEVEL_SCALR]]]]];
     }
     $server = ChefServer::findOne($criteria);
     if (!$server) {
         throw new Scalr_Exception_InsufficientPermissions();
     }
     return Scalr_Service_Chef_Client::getChef($server->url, $server->username, $this->getCrypto()->decrypt($server->authKey));
 }
示例#4
0
 public static function getList($accountId, $envId, $scope = self::SCOPE_ENVIRONMENT)
 {
     $criteria = [];
     switch ($scope) {
         case self::SCOPE_ENVIRONMENT:
             $criteria[] = ['$or' => [['$and' => [['accountId' => $accountId], ['envId' => $envId], ['level' => self::LEVEL_ENVIRONMENT]]], ['$and' => [['accountId' => $accountId], ['envId' => null], ['level' => self::LEVEL_ACCOUNT]]], ['$and' => [['accountId' => null], ['envId' => null], ['level' => self::LEVEL_SCALR]]]]];
             break;
         case self::SCOPE_ACCOUNT:
             $criteria[] = ['$or' => [['$and' => [['accountId' => $accountId], ['envId' => null], ['level' => self::LEVEL_ACCOUNT]]], ['$and' => [['accountId' => null], ['envId' => null], ['level' => self::LEVEL_SCALR]]]]];
             break;
         case self::SCOPE_SCALR:
             $criteria[] = ['level' => self::LEVEL_SCALR];
             $criteria[] = ['envId' => null];
             $criteria[] = ['accountId' => null];
             break;
     }
     return ChefServer::result(ChefServer::RESULT_ENTITY_COLLECTION)->find($criteria);
 }
示例#5
0
文件: Chef.php 项目: scalr/scalr
 /**
  * Returns list of chef servers applying governance
  *
  * @return array
  */
 public function xListServersAction()
 {
     $limits = null;
     if (!$this->user->isAdmin()) {
         $governance = new Scalr_Governance($this->getEnvironmentId(true));
         $limits = $governance->getValue(Scalr_Governance::CATEGORY_GENERAL, Scalr_Governance::GENERAL_CHEF, null);
     }
     $list = [];
     foreach (ChefServer::getList($this->user->getAccountId(), $this->getEnvironmentId(true), $this->request->getScope()) as $server) {
         if (!$limits || isset($limits['servers'][(string) $server->id])) {
             $list[] = ['id' => (string) $server->id, 'url' => $server->url, 'username' => $server->username, 'scope' => $server->getScope()];
         }
     }
     $this->response->data(['data' => $list]);
 }