GetList() public static méthode

public static GetList ( )
 protected function run2($stage)
 {
     $this->console->out("Populating new properties");
     $platforms = $envs = [];
     foreach (array_keys(\SERVER_PLATFORMS::GetList()) as $platform) {
         $platforms[$platform] = PlatformFactory::NewPlatform($platform);
     }
     $result = $this->db->Execute("\n                SELECT s.server_id, s.`platform`, s.`cloud_location`, s.env_id, s.`type`\n                FROM servers AS s\n                WHERE s.`status` NOT IN (?, ?) AND s.`type` IS NOT NULL\n            ", [Server::STATUS_PENDING_TERMINATE, Server::STATUS_TERMINATED]);
     while ($row = $result->FetchRow()) {
         if (!empty($row["type"])) {
             if (!array_key_exists($row["env_id"], $envs)) {
                 $envs[$row["env_id"]] = \Scalr_Environment::init()->loadById($row["env_id"]);
             }
             if ($this->isPlatformEnabled($envs[$row["env_id"]], $row["platform"])) {
                 try {
                     $instanceTypeEntity = $platforms[$row["platform"]]->getInstanceType($row["type"], $envs[$row["env_id"]], $row["cloud_location"]);
                     /* @var $instanceTypeEntity CloudInstanceType */
                     if ($instanceTypeEntity && (int) $instanceTypeEntity->vcpus > 0) {
                         $this->db->Execute("\n                                INSERT IGNORE INTO server_properties (`server_id`, `name`, `value`) VALUES (?, ?, ?)\n                            ", [$row["server_id"], Server::INFO_INSTANCE_VCPUS, $instanceTypeEntity->vcpus]);
                     }
                 } catch (\Exception $e) {
                     $this->console->warning("Can't get access to %s, error: %s", $row["platform"], $e->getMessage());
                 }
             }
         }
     }
 }
 /**
  * Data provider for testNewPlatform
  *
  * @return array
  */
 public function providerNewPlatform()
 {
     $ret = [];
     foreach (\SERVER_PLATFORMS::GetList() as $platform => $name) {
         $ret[] = [$platform];
     }
     return $ret;
 }
Exemple #3
0
 public function getEnabledPlatforms($addLocations = false)
 {
     $ePlatforms = $this->getEnvironment()->getEnabledPlatforms();
     $lPlatforms = SERVER_PLATFORMS::GetList();
     $platforms = array();
     foreach ($ePlatforms as $platform) {
         $platforms[$platform] = $addLocations ? array('id' => $platform, 'name' => $lPlatforms[$platform], 'locations' => PlatformFactory::NewPlatform($platform)->getLocations()) : $lPlatforms[$platform];
     }
     return $platforms;
 }
Exemple #4
0
 public function getEnabledPlatforms($addLocations = false, $includeGCELocations = true)
 {
     $ePlatforms = $this->user->isScalrAdmin() ? array_keys(SERVER_PLATFORMS::GetList()) : $this->getEnvironment()->getEnabledPlatforms();
     $lPlatforms = SERVER_PLATFORMS::GetList();
     $platforms = array();
     foreach ($ePlatforms as $platform) {
         $platforms[$platform] = $addLocations ? array('id' => $platform, 'name' => $lPlatforms[$platform], 'locations' => $platform !== SERVER_PLATFORMS::GCE || $includeGCELocations ? PlatformFactory::NewPlatform($platform)->getLocations() : array()) : $lPlatforms[$platform];
     }
     return $platforms;
 }
Exemple #5
0
 /**
  * @param jsonData $platforms
  * @throws Exception
  */
 public function xGetLocationsAction(JsonData $platforms)
 {
     $allPlatforms = $this->user->isScalrAdmin() ? array_keys(SERVER_PLATFORMS::GetList()) : $this->getEnvironment()->getEnabledPlatforms();
     $result = array();
     foreach ($platforms as $platform) {
         if (in_array($platform, $allPlatforms)) {
             $result[$platform] = !in_array($platform, array(SERVER_PLATFORMS::GCE, SERVER_PLATFORMS::ECS)) ? PlatformFactory::NewPlatform($platform)->getLocations($this->environment) : array();
         }
     }
     $this->response->data(array('locations' => $result));
 }
Exemple #6
0
 /**
  * {@inheritdoc}
  * @see \Scalr\System\Zmq\Cron\TaskInterface::enqueue()
  */
 public function enqueue()
 {
     $plt = [];
     $args = [date("Y-m-d H:00:00"), Server::STATUS_RUNNING];
     foreach (array_keys(\SERVER_PLATFORMS::GetList()) as $platform) {
         $plt[] = "SELECT CONVERT(? USING latin1) AS `platform`";
         $args[] = $platform;
     }
     $args[] = Server::INFO_INSTANCE_VCPUS;
     \Scalr::getDb()->Execute("\n            INSERT IGNORE INTO platform_usage (`time`, `platform`, `value`)\n            SELECT ? AS `time`, p.`platform`, SUM(IF(s.status = ?, IFNULL(sp.`value`, 0), 0))\n            FROM (" . implode(" UNION ALL ", $plt) . ") AS p\n            LEFT JOIN servers AS s ON p.platform = s.platform\n            LEFT JOIN server_properties AS sp ON s.server_id = sp.server_id AND sp.`name` = ?\n            GROUP BY p.`platform`\n            ", $args);
     return new ArrayObject([]);
 }
Exemple #7
0
 /**
  * DataProvider method for the testPlatformAction
  */
 public function providerPlatformAction()
 {
     $aPrefixed = array_fill_keys(array(SERVER_PLATFORMS::CLOUDSTACK, SERVER_PLATFORMS::IDCF, SERVER_PLATFORMS::UCLOUD, SERVER_PLATFORMS::OPENSTACK, SERVER_PLATFORMS::RACKSPACENG_UK, SERVER_PLATFORMS::RACKSPACENG_US, SERVER_PLATFORMS::OCS, SERVER_PLATFORMS::ECS, SERVER_PLATFORMS::NEBULA), true);
     $pars = array();
     foreach (\SERVER_PLATFORMS::GetList() as $platform => $opts) {
         if ($platform == \SERVER_PLATFORMS::RACKSPACE) {
             continue;
         }
         if ($platform == \SERVER_PLATFORMS::EUCALYPTUS) {
             continue;
         }
         $pars[] = array($platform, array_key_exists($platform, $aPrefixed) ? $platform . '.' : '');
     }
     return $pars;
 }
Exemple #8
0
 /**
  * @param jsonData $platforms
  * @throws Exception
  */
 public function xGetLocationsAction(JsonData $platforms)
 {
     $allPlatforms = $this->request->getScope() != ScopeInterface::SCOPE_ENVIRONMENT ? array_keys(SERVER_PLATFORMS::GetList()) : $this->getEnvironment()->getEnabledPlatforms();
     $result = array();
     foreach ($platforms as $platform) {
         if (in_array($platform, $allPlatforms)) {
             $result[$platform] = !in_array($platform, array(SERVER_PLATFORMS::GCE, SERVER_PLATFORMS::AZURE)) ? PlatformFactory::NewPlatform($platform)->getLocations($this->environment) : array();
         }
     }
     $this->response->data(array('locations' => $result));
 }
 protected function run2($stage)
 {
     if ($this->getCountOfAccountTagValues(TagEntity::TAG_ID_PLATFORM) && $this->console->confirm('Would you like to remove old platforms from account_tag_values?')) {
         $this->console->out("Removing old platforms");
         $this->db->Execute("DELETE FROM account_tag_values WHERE tag_id = ?", array(TagEntity::TAG_ID_PLATFORM));
     }
     $this->console->out('Populating platforms to the dictionary');
     $platforms = \SERVER_PLATFORMS::GetList();
     $pars = array();
     $values = '';
     foreach ($platforms as $id => $name) {
         $values .= ",('0', '" . TagEntity::TAG_ID_PLATFORM . "', ?, ?)";
         $pars[] = $id;
         $pars[] = $name;
     }
     $values = ltrim($values, ',');
     if ($values != '') {
         $this->db->Execute("\n                INSERT IGNORE account_tag_values (`account_id`, `tag_id`, `value_id`, `value_name`)\n                VALUES " . $values . "\n            ", $pars);
     }
 }
Exemple #10
0
 /**
  * View edit role page
  */
 public function editAction()
 {
     $this->request->restrictAccess(Acl::RESOURCE_FARMS_ROLES, Acl::PERM_FARMS_ROLES_MANAGE);
     // declare types of input variables (available types: int, string (default), bool, json, array; may be include default value for variable)
     $this->request->defineParams(array('roleId' => array('type' => 'int')));
     $params = array('platforms' => array(), 'isScalrAdmin' => $this->user->getType() == Scalr_Account_User::TYPE_SCALR_ADMIN);
     if (!$params['isScalrAdmin']) {
         $ePlatforms = $this->getEnvironment()->getEnabledPlatforms();
     } else {
         $ePlatforms = array_keys(SERVER_PLATFORMS::GetList());
     }
     $lPlatforms = SERVER_PLATFORMS::GetList();
     try {
         $llist = array();
         foreach ($ePlatforms as $platform) {
             $locations = array();
             foreach (PlatformFactory::NewPlatform($platform)->getLocations() as $key => $loc) {
                 $locations[] = array('id' => $key, 'name' => $loc);
                 $llist[$key] = $loc;
             }
             $params['platforms'][] = array('id' => $platform, 'name' => $lPlatforms[$platform], 'locations' => $locations);
         }
     } catch (Exception $e) {
     }
     $params['scriptData'] = self::loadController('Scripts')->getScriptingData();
     //$cats = $this->db->Execute("SELECT * FROM role_categories WHERE env_id='0' OR env_id = ?", array($this->getEnvironmentId()));
     //while ($cat = $cats->FetchRow())
     $params['categories'] = $this->db->GetAll("SELECT * FROM role_categories WHERE env_id='0'", array());
     if ($this->getParam('roleId')) {
         $dbRole = DBRole::loadById($this->getParam('roleId'));
         if ($this->user->getType() != Scalr_Account_User::TYPE_SCALR_ADMIN) {
             $this->user->getPermissions()->validate($dbRole);
         }
         $images = array();
         $imDetails = $dbRole->getImages(true);
         if (!empty($imDetails) && (is_array($imDetails) || $imDetails instanceof \Traversable)) {
             foreach ($imDetails as $platform => $locations) {
                 foreach ($locations as $location => $imageInfo) {
                     $images[] = array('image_id' => $imageInfo['image_id'], 'platform' => $platform, 'location' => $location, 'platform_name' => SERVER_PLATFORMS::GetName($platform), 'location_name' => $llist[$location], 'architecture' => $imageInfo['architecture']);
                 }
             }
         }
         $params['tags'] = array_flip($dbRole->getTags());
         $params['role'] = array('id' => $dbRole->id, 'name' => $dbRole->name, 'arch' => $imageInfo['architecture'], 'cat_id' => $dbRole->catId, 'os' => $dbRole->os, 'os_family' => $dbRole->osFamily, 'os_generation' => $dbRole->osGeneration, 'os_version' => $dbRole->osVersion, 'agent' => $dbRole->generation, 'description' => $dbRole->description, 'behaviors' => $dbRole->getBehaviors(), 'properties' => array(DBRole::PROPERTY_SSH_PORT => $dbRole->getProperty(DBRole::PROPERTY_SSH_PORT)), 'images' => $images, 'parameters' => $dbRole->getParameters(), 'scripts' => $dbRole->getScripts(), 'security_rules' => $dbRole->getSecurityRules());
         if ($dbRole->origin == ROLE_TYPE::CUSTOM) {
             $variables = new Scalr_Scripting_GlobalVariables($this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_ROLE);
             $params['role']['variables'] = json_encode($variables->getValues($dbRole->id));
         }
         if ($params['role']['security_rules']) {
             foreach ($params['role']['security_rules'] as &$r) {
                 $chunks = explode(":", $r['rule']);
                 $r['ipProtocol'] = $chunks[0];
                 $r['fromPort'] = $chunks[1];
                 $r['toPort'] = $chunks[2];
                 $r['cidrIp'] = $chunks[3];
                 $r['comment'] = $this->db->GetOne("SELECT `comment` FROM `comments` WHERE `env_id` = ? AND `rule` = ? AND `sg_name` = ? LIMIT 1", array($dbRole->envId, $r['rule'], "role:{$params['role']['id']}"));
                 if (!$r['comment']) {
                     $r['comment'] = "";
                 }
             }
         }
         if (!$params['role']['properties'][DBRole::PROPERTY_SSH_PORT]) {
             $params['role']['properties'][DBRole::PROPERTY_SSH_PORT] = 22;
         }
         $this->response->page('ui/roles/edit.js', $params, array('ui/scripts/scriptfield.js', 'ui/core/variablefield.js'), array('ui/scripts/scriptfield.css', 'ui/core/variablefield.css'));
     } else {
         $params['tags'] = array();
         $params['role'] = array('id' => 0, 'name' => "", 'arch' => "x86_64", 'agent' => 2, 'description' => "", 'behaviors' => array(), 'properties' => array(DBRole::PROPERTY_SSH_PORT => 22), 'images' => array(), 'parameters' => array(), 'scripts' => array());
         $this->response->page('ui/roles/edit.js', $params, array('ui/scripts/scriptfield.js'), array('ui/scripts/scriptfield.css'));
     }
 }
Exemple #11
0
 /**
  * View edit role page
  */
 public function editAction()
 {
     // declare types of input variables (available types: int, string (default), bool, json, array; may be include default value for variable)
     $this->request->defineParams(array('roleId' => array('type' => 'int')));
     $params = array('platforms' => array(), 'isScalrAdmin' => $this->user->getType() == Scalr_Account_User::TYPE_SCALR_ADMIN);
     if (!$params['isScalrAdmin']) {
         $ePlatforms = $this->getEnvironment()->getEnabledPlatforms();
     } else {
         $ePlatforms = array_keys(SERVER_PLATFORMS::GetList());
     }
     $lPlatforms = SERVER_PLATFORMS::GetList();
     try {
         $llist = array();
         foreach ($ePlatforms as $platform) {
             $locations = array();
             foreach (PlatformFactory::NewPlatform($platform)->getLocations() as $key => $loc) {
                 $locations[] = array('id' => $key, 'name' => $loc);
                 $llist[$key] = $loc;
             }
             $params['platforms'][] = array('id' => $platform, 'name' => $lPlatforms[$platform], 'locations' => $locations);
         }
     } catch (Exception $e) {
     }
     $params['scriptData'] = self::loadController('Scripts')->getScriptingData();
     if ($this->getParam('roleId')) {
         $dbRole = DBRole::loadById($this->getParam('roleId'));
         if ($this->user->getType() != Scalr_Account_User::TYPE_SCALR_ADMIN) {
             $this->user->getPermissions()->validate($dbRole);
         }
         $images = array();
         foreach ($dbRole->getImages() as $platform => $locations) {
             foreach ($locations as $location => $imageId) {
                 $images[] = array('image_id' => $imageId, 'platform' => $platform, 'location' => $location, 'platform_name' => SERVER_PLATFORMS::GetName($platform), 'location_name' => $llist[$location]);
             }
         }
         $params['tags'] = array_flip($dbRole->getTags());
         $params['role'] = array('id' => $dbRole->id, 'name' => $dbRole->name, 'arch' => $dbRole->architecture, 'os' => $dbRole->os, 'agent' => $dbRole->generation, 'description' => $dbRole->description, 'behaviors' => $dbRole->getBehaviors(), 'properties' => array(DBRole::PROPERTY_SSH_PORT => $dbRole->getProperty(DBRole::PROPERTY_SSH_PORT)), 'images' => $images, 'parameters' => $dbRole->getParameters(), 'scripts' => $dbRole->getScripts(), 'szr_version' => $dbRole->szrVersion, 'security_rules' => $dbRole->getSecurityRules());
         if ($params['role']['security_rules']) {
             foreach ($params['role']['security_rules'] as &$r) {
                 $chunks = explode(":", $r['rule']);
                 $r['ipProtocol'] = $chunks[0];
                 $r['fromPort'] = $chunks[1];
                 $r['toPort'] = $chunks[2];
                 $r['cidrIp'] = $chunks[3];
                 $r['comment'] = $this->db->GetOne("SELECT `comment` FROM `comments` WHERE `env_id` = ? AND `rule` = ? AND `sg_name` = ?", array($dbRole->envId, $r['rule'], "role:{$params['role']['id']}"));
                 if (!$r['comment']) {
                     $r['comment'] = "";
                 }
             }
         }
         if (!$params['role']['properties'][DBRole::PROPERTY_SSH_PORT]) {
             $params['role']['properties'][DBRole::PROPERTY_SSH_PORT] = 22;
         }
         $this->response->page('ui/roles/edit.js', $params, array('ui/scripts/scriptfield.js'), array('ui/scripts/scriptfield.css'));
     } else {
         if ($this->user->getType() != Scalr_Account_User::TYPE_SCALR_ADMIN) {
             throw new Scalr_Exception_InsufficientPermissions();
         } else {
             $params['tags'] = array();
             $params['role'] = array('id' => 0, 'name' => "", 'arch' => "i386", 'agent' => 2, 'description' => "", 'behaviors' => array(), 'properties' => array(DBRole::PROPERTY_SSH_PORT => 22), 'images' => array(), 'parameters' => array(), 'scripts' => array());
             $this->response->page('ui/roles/edit.js', $params, array('ui/scripts/scriptfield.js'), array('ui/scripts/scriptfield.css'));
         }
     }
 }
Exemple #12
0
 /**
  * Get information about role
  *
  * @param   int     $roleId      Identifier of role
  * @param   bool    $extended    Get extended information about role
  * @param   array   $canAddImage Array of platform, cloudLocation to check if role has image in that location
  * @return  array
  * @throws  Exception
  * @throws  Scalr_Exception_Core
  * @throws  Scalr_Exception_InsufficientPermissions
  */
 private function getInfo($roleId, $extended = false, $canAddImage = null)
 {
     /* @var $role Role */
     $role = Role::findPk($roleId);
     if (!$role) {
         throw new Scalr_Exception_Core(sprintf(_("Role ID#%s not found in database"), $roleId));
     }
     $this->request->checkPermissions($role);
     $usedBy = $role->getFarmsCount($this->user->getAccountId(), $this->getEnvironmentId(true));
     $platforms = array_keys($role->fetchImagesArray());
     $allPlatforms = array_flip(array_keys(SERVER_PLATFORMS::GetList()));
     usort($platforms, function ($a, $b) use($allPlatforms) {
         return $allPlatforms[$a] > $allPlatforms[$b] ? 1 : -1;
     });
     $result = array('name' => $role->name, 'behaviors' => $role->getBehaviors(), 'id' => $role->id, 'accountId' => $role->accountId, 'envId' => $role->envId, 'catId' => $role->catId, 'status' => $usedBy > 0 ? 'In use' : 'Not used', 'scope' => $role->getScope(), 'os' => $role->getOs()->name, 'osId' => $role->osId, 'osFamily' => $role->getOs()->family, 'dtAdded' => $role->added ? Scalr_Util_DateTime::convertTz($role->added) : NULL, 'dtLastUsed' => $role->lastUsed ? Scalr_Util_DateTime::convertTz($role->lastUsed) : NULL, 'isQuickStart' => $role->isQuickStart, 'isDeprecated' => $role->isDeprecated, 'isScalarized' => $role->isScalarized, 'platforms' => $platforms, 'environments' => !empty($envs = $role->getAllowedEnvironments()) ? $this->db->GetCol("SELECT name FROM client_environments WHERE id IN(" . join(',', $envs) . ")") : []);
     if ($canAddImage) {
         try {
             $role->getImage($canAddImage['platform'], $canAddImage['cloudLocation']);
             $result['canAddImage'] = false;
         } catch (Exception $e) {
             $result['canAddImage'] = true;
         }
     }
     if ($extended) {
         $result['description'] = $role->description;
         $result['images'] = [];
         foreach (RoleImage::find([['roleId' => $role->id]]) as $image) {
             /* @var $image RoleImage */
             $im = $image->getImage();
             $ext = [];
             if ($im) {
                 $ext = get_object_vars($im);
                 $ext['software'] = $im->getSoftwareAsString();
             }
             $result['images'][] = ['imageId' => $image->imageId, 'platform' => $image->platform, 'cloudLocation' => $image->cloudLocation, 'extended' => $ext];
         }
         if ($result['status'] == 'In use' && $this->getEnvironmentId(true)) {
             $farms = [];
             $f = [];
             foreach (FarmRole::find([['roleId' => $role->id]]) as $farmRole) {
                 /* @var $farmRole FarmRole */
                 $f[] = $farmRole->farmId;
             }
             $f = array_unique($f);
             if (count($f)) {
                 foreach (Farm::find([['id' => ['$in' => $f]], ['envId' => $this->getEnvironmentId()]]) as $fm) {
                     /* @var $fm Farm */
                     $farms[] = ['id' => $fm->id, 'name' => $fm->name];
                 }
             }
             $result['usedBy'] = ['farms' => $farms, 'cnt' => count($farms)];
         }
     }
     return $result;
 }
Exemple #13
0
 /**
  * Get list of roles for roles library
  */
 public function xGetListAction()
 {
     $this->request->restrictAccess(Acl::RESOURCE_FARMS_ROLES);
     $total = 0;
     $roles = array();
     $filterRoleId = $this->getParam('roleId');
     $filterCatId = $this->getParam('catId');
     $filterOsFamily = $this->getParam('osFamily');
     $filterKeyword = $this->getParam('keyword');
     $filterPlatform = $this->getParam('platform');
     $e_platforms = $this->getEnvironment()->getEnabledPlatforms();
     $platforms = array();
     $l_platforms = SERVER_PLATFORMS::GetList();
     foreach ($e_platforms as $platform) {
         $platforms[$platform] = $l_platforms[$platform];
     }
     if ($filterPlatform) {
         if (!$platforms[$filterPlatform]) {
             throw new Exception("Selected cloud not enabled in current environment");
         }
     }
     if ($filterCatId === 'shared') {
         $roles_sql = "SELECT DISTINCT(roles.id), platform FROM roles INNER JOIN role_images ON role_images.role_id = roles.id WHERE is_deprecated='0' AND generation = '2' AND env_id=?";
         $args[] = 0;
         if (!$filterPlatform) {
             $roles_sql .= " AND role_images.platform IN ('" . implode("','", array_keys($platforms)) . "')";
         } else {
             $roles_sql .= " AND role_images.platform = ?";
             $args[] = $filterPlatform;
         }
         if ($filterOsFamily) {
             $roles_sql .= ' AND os_family = ?';
             $args[] = $filterOsFamily;
         }
         $dbRoles = $this->db->Execute($roles_sql, $args);
         $software = array();
         $softwareOrdering = array('base' => 0, 'mysql' => 10, 'percona' => 20, 'mariadb' => 10, 'postgresql' => 30, 'mongodb' => 40, 'redis' => 50, 'apache' => 60, 'lamp' => 70, 'tomcat' => 80, 'haproxy' => 90, 'nginx' => 100, 'memcached' => 110, 'rabbitmq' => 120, 'vpcrouter' => 130);
         foreach ($dbRoles as $role) {
             $dbRole = DBRole::loadById($role['id']);
             // Get type
             if ($dbRole->hasBehavior(ROLE_BEHAVIORS::VPC_ROUTER)) {
                 $type = 'vpcrouter';
             } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::APACHE) && ($dbRole->hasBehavior(ROLE_BEHAVIORS::MYSQL2) || $dbRole->hasBehavior(ROLE_BEHAVIORS::MYSQL) || $dbRole->hasBehavior(ROLE_BEHAVIORS::PERCONA) || $dbRole->hasBehavior(ROLE_BEHAVIORS::MARIADB))) {
                 $type = 'lamp';
             } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::MYSQL2)) {
                 $type = 'mysql';
             } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::APACHE)) {
                 $type = 'apache';
             } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::TOMCAT)) {
                 $type = ROLE_BEHAVIORS::TOMCAT;
             } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::NGINX)) {
                 $type = 'nginx';
             } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::HAPROXY)) {
                 $type = 'haproxy';
             } elseif ($dbRole->getDbMsrBehavior()) {
                 $type = $dbRole->getDbMsrBehavior();
             } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::MONGODB)) {
                 $type = ROLE_BEHAVIORS::MONGODB;
             } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::RABBITMQ)) {
                 $type = ROLE_BEHAVIORS::RABBITMQ;
             } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::MEMCACHED)) {
                 $type = ROLE_BEHAVIORS::MEMCACHED;
             } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::BASE)) {
                 $type = ROLE_BEHAVIORS::BASE;
             } elseif ($dbRole->hasBehavior(ROLE_BEHAVIORS::MYSQL)) {
                 continue;
             }
             // Set hvm flag
             $hvm = stristr($dbRole->name, '-hvm-') ? 1 : 0;
             // Set arch flag
             $architecture = stristr($dbRole->name, '64-') ? 'x86_64' : 'i386';
             $images = $dbRole->getImages(true);
             foreach ($images as $cloud => $locations) {
                 if (!$platforms[$cloud]) {
                     unset($images[$cloud]);
                 } else {
                     foreach ($locations as $location => $image) {
                         if (!$image['architecture']) {
                             $images[$cloud][$location]['architecture'] = $architecture;
                         }
                     }
                 }
             }
             $item = array('role_id' => $dbRole->id, 'name' => $dbRole->name, 'behaviors' => $dbRole->getBehaviors(), 'origin' => $dbRole->origin, 'cat_name' => $dbRole->getCategoryName(), 'cat_id' => $dbRole->catId, 'os_name' => $dbRole->os, 'os_family' => $dbRole->osFamily, 'os_generation' => $dbRole->osGeneration, 'os_version' => $dbRole->osVersion, 'images' => $images, 'hvm' => $hvm, 'ebs' => 1, 'description' => $dbRole->description);
             $software[$type]['roles'][] = $item;
             $software[$type]['name'] = $type;
             $software[$type]['ordering'] = isset($softwareOrdering[$type]) ? $softwareOrdering[$type] : 1000;
             $total++;
         }
         $software = array_values($software);
     } else {
         $args[] = $this->getEnvironmentId();
         $roles_sql = "\n                SELECT DISTINCT(r.id), r.env_id\n                FROM roles r\n                LEFT JOIN roles_queue q ON r.id = q.role_id\n                INNER JOIN role_images as i ON i.role_id = r.id\n                WHERE generation = '2' AND env_id IN(0, ?)\n                AND q.id IS NULL\n                AND i.platform\n            ";
         if (!$filterPlatform) {
             $roles_sql .= " IN ('" . implode("','", array_keys($platforms)) . "')";
         } else {
             $roles_sql .= " = ?";
             $args[] = $filterPlatform;
         }
         if ($filterCatId === 'search') {
             $roles_sql .= ' AND r.name LIKE ' . $this->db->qstr('%' . trim($filterKeyword) . '%');
             if ($filterRoleId) {
                 $roles_sql .= ' AND r.id = ?';
                 $args[] = $filterRoleId;
             }
         } elseif ($filterCatId === 'recent') {
         } elseif ($filterCatId) {
             $roles_sql .= ' AND r.cat_id = ?';
             $args[] = $filterCatId;
         }
         if ($filterOsFamily) {
             $roles_sql .= ' AND r.os_family = ?';
             $args[] = $filterOsFamily;
         }
         $roles_sql .= ' GROUP BY r.id';
         if ($filterCatId === 'recent') {
             $roles_sql .= ' ORDER BY r.id DESC LIMIT 10';
         }
         $dbRoles = $this->db->Execute($roles_sql, $args);
         $globalVars = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_FARMROLE);
         foreach ($dbRoles as $role) {
             $dbRole = DBRole::loadById($role['id']);
             $architecture = stristr($dbRole->name, '64-') ? 'x86_64' : 'i386';
             $images = $dbRole->getImages(true);
             foreach ($images as $cloud => $locations) {
                 if (!$platforms[$cloud]) {
                     unset($images[$cloud]);
                 } else {
                     if ($dbRole->envId == 0) {
                         foreach ($locations as $location => $image) {
                             if (!$image['architecture']) {
                                 $images[$cloud][$location]['architecture'] = $architecture;
                             }
                         }
                     }
                 }
             }
             $roles[] = array('role_id' => $dbRole->id, 'name' => $dbRole->name, 'behaviors' => $dbRole->getBehaviors(), 'origin' => $dbRole->origin, 'cat_name' => $dbRole->getCategoryName(), 'cat_id' => $dbRole->catId, 'os_name' => $dbRole->os, 'os_family' => $dbRole->osFamily, 'os_generation' => $dbRole->osGeneration, 'os_version' => $dbRole->osVersion, 'images' => $images, 'tags' => $dbRole->getTags(), 'variables' => $globalVars->getValues($dbRole->id, 0, 0), 'shared' => $role['env_id'] == 0, 'description' => $dbRole->description);
         }
         $total = count($roles);
     }
     $moduleParams = array('roles' => $roles, 'software' => $software, 'total' => $total);
     $this->response->data($moduleParams);
 }
Exemple #14
0
 public function defaultAction()
 {
     //Platforms should be in the same order everywhere
     $platforms = array_values(array_intersect(array_keys(SERVER_PLATFORMS::GetList()), array_merge([SERVER_PLATFORMS::EC2], PlatformFactory::getOpenstackBasedPlatforms(), PlatformFactory::getCloudstackBasedPlatforms())));
     $this->response->page('ui/analytics/pricing/view.js', ['platforms' => $platforms, 'forbidAutomaticUpdate' => [SERVER_PLATFORMS::EC2 => !!SettingEntity::getValue(SettingEntity::ID_FORBID_AUTOMATIC_UPDATE_AWS_PRICES)]], [], ['ui/analytics/pricing/view.css']);
 }
Exemple #15
0
 public function editAction()
 {
     $env = $this->getEnvironmentInfo();
     if (!($this->user->getType() == Scalr_Account_User::TYPE_ACCOUNT_OWNER || $this->user->isTeamUserInEnvironment($env['id'], Scalr_Account_Team::PERMISSIONS_OWNER))) {
         throw new Scalr_Exception_InsufficientPermissions();
     }
     $platforms = SERVER_PLATFORMS::GetList();
     unset($platforms[SERVER_PLATFORMS::RDS]);
     //TODO:
     if (!$this->getParam('beta')) {
         unset($platforms[SERVER_PLATFORMS::OPENSTACK]);
     }
     $timezones = array();
     $timezoneAbbreviationsList = timezone_abbreviations_list();
     foreach ($timezoneAbbreviationsList as $timezoneAbbreviations) {
         foreach ($timezoneAbbreviations as $value) {
             if (preg_match('/^(America|Antartica|Arctic|Asia|Atlantic|Europe|Indian|Pacific|Australia)\\//', $value['timezone_id'])) {
                 $timezones[$value['timezone_id']] = $value['offset'];
             }
         }
     }
     @ksort($timezones);
     $timezones = array_keys($timezones);
     $this->response->page('ui/environments/edit.js', array('environment' => $env, 'platforms' => $platforms, 'timezones' => $timezones));
 }