getValues() public method

public getValues ( $roleId, $farmId, $farmRoleId, $serverId = '' )
Esempio n. 1
0
 public function xCloneAction()
 {
     if (!$this->user->isAccountSuperAdmin() && !$this->request->isAllowed(Acl::RESOURCE_ENV_CLOUDS_ENVIRONMENT)) {
         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, ScopeInterface::SCOPE_ENVIRONMENT);
         $variables = $oldGv->getValues();
         $newGv = new Scalr_Scripting_GlobalVariables($env->clientId, $env->id, ScopeInterface::SCOPE_ENVIRONMENT);
         $newGv->setValues($variables, 0, 0, 0, '', false, true);
         //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['enabled'], $data['limits']);
             }
         }
         $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(), true);
     }
 }
Esempio n. 2
0
 public static function createFromBundleTask(BundleTask $BundleTask)
 {
     $db = \Scalr::getDb();
     $DBServer = DBServer::LoadByID($BundleTask->serverId);
     if ($BundleTask->prototypeRoleId) {
         $proto_role = $db->GetRow("SELECT * FROM roles WHERE id=? LIMIT 1", array($BundleTask->prototypeRoleId));
         if (!$proto_role['architecture']) {
             $proto_role['architecture'] = $DBServer->GetProperty(SERVER_PROPERTIES::ARCHITECTURE);
         }
     } else {
         $behaviors = array_unique(explode(',', $DBServer->GetProperty(SERVER_PROPERTIES::SZR_IMPORTING_BEHAVIOR)));
         sort($behaviors);
         $proto_role = array("behaviors" => join(',', $behaviors), "architecture" => $DBServer->GetProperty(SERVER_PROPERTIES::ARCHITECTURE), "name" => "*import*");
     }
     if (!$proto_role['architecture']) {
         $proto_role['architecture'] = 'x86_64';
     }
     if (!$BundleTask->cloudLocation) {
         if ($DBServer) {
             $BundleTask->cloudLocation = $DBServer->GetCloudLocation();
         }
     }
     $osId = $BundleTask->osId;
     $meta = $BundleTask->getSnapshotDetails();
     if (!$osId) {
         if ($proto_role) {
             $osId = $proto_role['os_id'];
         } elseif ($meta['os'] && $meta['os']->version) {
             /*
                             if ($meta['os']->version == '2008Server') {
                                 $osInfo->name = 'Windows 2008 Server';
                                 $osInfo->family = 'windows';
                                 $osInfo->generation = '2008';
                                 $osInfo->version = '2008Server';
                             } elseif ($meta['os']->version == '2008ServerR2') {
                                 $osInfo->name = 'Windows 2008 Server R2';
                                 $osInfo->family = 'windows';
                                 $osInfo->generation = '2008';
                                 $osInfo->version = '2008ServerR2';
                             }*/
             //TODO:
         }
     }
     if ($proto_role['cat_id']) {
         $catId = $proto_role['cat_id'];
     } else {
         $catId = ROLE_BEHAVIORS::GetCategoryId($proto_role['behaviors']);
     }
     $db->Execute("INSERT INTO roles SET\n            name\t\t\t= ?,\n            origin\t\t\t= ?,\n            dtadded         = NOW(),\n            client_id\t\t= ?,\n            env_id\t\t\t= ?,\n            cat_id          = ?,\n            description\t\t= ?,\n            behaviors\t\t= ?,\n            generation\t\t= ?,\n            added_by_email  = ?,\n            added_by_userid = ?,\n            os_id\t\t\t= ?\n        ", array($BundleTask->roleName, ROLE_TYPE::CUSTOM, $BundleTask->clientId, $BundleTask->envId, $catId, $BundleTask->description, $proto_role['behaviors'], 2, $BundleTask->createdByEmail, $BundleTask->createdById, $osId));
     $role_id = $db->Insert_Id();
     $BundleTask->roleId = $role_id;
     $BundleTask->Save();
     $BundleTask->Log(sprintf("Created new role. Role name: %s. Role ID: %s", $BundleTask->roleName, $BundleTask->roleId));
     $role = self::loadById($role_id);
     $behaviors = explode(",", $proto_role['behaviors']);
     foreach ($behaviors as $behavior) {
         $db->Execute("INSERT IGNORE INTO role_behaviors SET\n                role_id\t\t\t= ?,\n                behavior\t\t= ?\n            ", array($role_id, $behavior));
     }
     // Set image
     $role->__getNewRoleObject()->setImage($BundleTask->platform, $BundleTask->cloudLocation, $BundleTask->snapshotId, $BundleTask->createdById, $BundleTask->createdByEmail);
     // Set params
     if ($proto_role['id']) {
         $dbSecRules = $db->GetAll("SELECT * FROM role_security_rules WHERE role_id = ?", array($proto_role['id']));
         foreach ($dbSecRules as $dbSecRule) {
             $db->Execute("INSERT INTO role_security_rules SET role_id = ?, rule = ?", array($role_id, $dbSecRule['rule']));
         }
         $props = $db->GetAll("SELECT * FROM role_properties WHERE role_id=?", array($proto_role['id']));
         foreach ($props as $prop) {
             $role->setProperty($prop['name'], $prop['value']);
         }
         $scripts = $db->GetAll("SELECT * FROM role_scripts WHERE role_id=?", array($proto_role['id']));
         foreach ($scripts as &$script) {
             $script['params'] = unserialize($script['params']);
         }
         $role->setScripts($scripts);
         $variables = new Scalr_Scripting_GlobalVariables($BundleTask->clientId, $proto_role['env_id'], ScopeInterface::SCOPE_ROLE);
         $variables->setValues($variables->getValues($proto_role['id']), $role->id);
     }
     $role->syncAnalyticsTags();
     return $role;
 }
Esempio n. 3
0
 public function buildAction()
 {
     $this->request->restrictAccess(Acl::RESOURCE_FARMS, Acl::PERM_FARMS_MANAGE);
     $this->request->defineParams(array('farmId' => array('type' => 'int'), 'roleId' => array('type' => 'int')));
     $farmId = $this->getParam('farmId');
     $roleId = $this->getParam('roleId');
     $moduleParams = array('farmId' => $farmId, 'roleId' => $roleId, 'behaviors' => ROLE_BEHAVIORS::GetName(null, true));
     unset($moduleParams['behaviors'][ROLE_BEHAVIORS::CASSANDRA]);
     unset($moduleParams['behaviors'][ROLE_BEHAVIORS::CUSTOM]);
     unset($moduleParams['behaviors'][ROLE_BEHAVIORS::HAPROXY]);
     //platforms list
     $platforms = self::loadController('Platforms')->getEnabledPlatforms();
     if (empty($platforms)) {
         throw new Exception('Before building new farm you need to configure environment and setup cloud credentials');
     }
     //categories list
     $categories = $this->db->GetAll("SELECT c.id, c.name, COUNT(DISTINCT r.id) AS total\n             FROM role_categories c\n             LEFT JOIN roles r ON c.id = r.cat_id AND r.env_id IN(0, ?) AND r.id IN (\n                SELECT role_id\n                FROM role_images\n                WHERE role_id = r.id\n                AND platform IN ('" . implode("','", array_keys($platforms)) . "')\n             )\n             LEFT JOIN roles_queue q ON r.id = q.role_id\n             WHERE c.env_id IN (0, ?)\n             AND q.id IS NULL\n             GROUP BY c.id\n            ", array($this->environment->id, $this->environment->id));
     $moduleParams['categories'] = array();
     foreach ($categories as $g) {
         $moduleParams['categories'][$g['id']] = $g;
     }
     $moduleParams['farmVpcEc2Enabled'] = $this->getEnvironment()->isPlatformEnabled(SERVER_PLATFORMS::EC2);
     if ($moduleParams['farmVpcEc2Enabled']) {
         $moduleParams['farmVpcEc2Locations'] = self::loadController('Platforms')->getCloudLocations(SERVER_PLATFORMS::EC2, false);
     }
     if ($farmId) {
         $c = self::loadController('Builder', 'Scalr_UI_Controller_Farms');
         $moduleParams['farm'] = $c->getFarm2($farmId);
     } else {
         // TODO: remove hack, do better
         $vars = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_FARM);
         $moduleParams['farmVariables'] = $vars->getValues();
     }
     $moduleParams['tabs'] = array('vpcrouter', 'dbmsr', 'mongodb', 'mysql', 'scaling', 'network', 'gce', 'cloudfoundry', 'rabbitmq', 'haproxy', 'proxy', 'rds', 'scripting', 'nimbula', 'ec2', 'security', 'devel', 'storage', 'variables', 'advanced');
     if ($this->user->getAccount()->isFeatureEnabled(Scalr_Limits::FEATURE_CHEF)) {
         $moduleParams['tabs'][] = 'chef';
     }
     //deprecated tabs
     $moduleParams['tabs'][] = 'deployments';
     $moduleParams['tabs'][] = 'ebs';
     $moduleParams['tabs'][] = 'params';
     $moduleParams['tabs'][] = 'servicesconfig';
     $conf = $this->getContainer()->config->get('scalr.load_statistics.connections.plotter');
     $moduleParams['tabParams'] = array('farmId' => $farmId, 'farmHash' => $moduleParams['farm'] ? $moduleParams['farm']['farm']['hash'] : '', 'accountId' => $this->environment->getPlatformConfigValue(Ec2PlatformModule::ACCOUNT_ID), 'remoteAddress' => $this->request->getRemoteAddr(), 'monitoringHostUrl' => "{$conf['scheme']}://{$conf['host']}:{$conf['port']}", 'nginx' => array('server_section' => @file_get_contents("../templates/services/nginx/server_section.tpl"), 'server_section_ssl' => @file_get_contents("../templates/services/nginx/server_section_ssl.tpl")));
     // TODO: Features
     $moduleParams['tabParams']['featureRAID'] = $this->user->getAccount()->isFeatureEnabled(Scalr_Limits::FEATURE_RAID);
     $moduleParams['tabParams']['featureMFS'] = $this->user->getAccount()->isFeatureEnabled(Scalr_Limits::FEATURE_MFS);
     $moduleParams['tabParams']['scalr.dns.global.enabled'] = \Scalr::config('scalr.dns.global.enabled');
     $moduleParams['tabParams']['scalr.instances_connection_policy'] = \Scalr::config('scalr.instances_connection_policy');
     $moduleParams['tabParams']['scalr.scalarizr_update.repos'] = array_keys(\Scalr::config('scalr.scalarizr_update.repos'));
     $moduleParams['tabParams']['scalr.scalarizr_update.default_repo'] = \Scalr::config('scalr.scalarizr_update.default_repo');
     $moduleParams['metrics'] = self::loadController('Metrics', 'Scalr_UI_Controller_Scaling')->getList();
     $moduleParams['timezones_list'] = Scalr_Util_DateTime::getTimezones();
     $moduleParams['timezone_default'] = $this->user->getSetting(Scalr_Account_User::SETTING_UI_TIMEZONE);
     if ($moduleParams['farm']['farm']['ownerEditable']) {
         $moduleParams['usersList'] = Scalr_Account_User::getList($this->user->getAccountId());
     }
     $governance = new Scalr_Governance($this->getEnvironmentId());
     $moduleParams['governance'] = $governance->getValues(true);
     $defaultFarmRoleSecurityGroups = array('default');
     if (\Scalr::config('scalr.aws.security_group_name')) {
         $defaultFarmRoleSecurityGroups[] = \Scalr::config('scalr.aws.security_group_name');
     }
     $moduleParams['roleDefaultSettings'] = array('base.keep_scripting_logs_time' => \Scalr::config('scalr.system.scripting.default_instance_log_rotation_period'), 'security_groups.list' => json_encode($defaultFarmRoleSecurityGroups));
     //cost analytics
     if ($this->getContainer()->analytics->enabled && $this->getEnvironment()->getPlatformConfigValue(Scalr_Environment::SETTING_CC_ID)) {
         $costCenter = $this->getContainer()->analytics->ccs->get($this->getEnvironment()->getPlatformConfigValue(Scalr_Environment::SETTING_CC_ID));
         $projects = [];
         if ($costCenter instanceof CostCentreEntity) {
             $projectsIterator = new SharedProjectsFilterIterator($costCenter->getProjects(), $costCenter->ccId, $this->user, $this->getEnvironment());
             foreach ($projectsIterator as $item) {
                 /* @var $item ProjectEntity */
                 $projects[] = array('projectId' => $item->projectId, 'name' => $item->name);
             }
             $costCentreName = $costCenter->name;
         } else {
             $costCentreName = '';
         }
         $moduleParams['analytics'] = array('costCenterName' => $costCentreName, 'projects' => $projects);
         if ($farmId) {
             $dbFarm = DBFarm::LoadByID($farmId);
             $moduleParams['farm']['farm']['projectId'] = $dbFarm->GetSetting(DBFarm::SETTING_PROJECT_ID);
         }
     }
     $this->response->page('ui/farms/builder.js', $moduleParams, array('ui/farms/builder/selroles.js', 'ui/farms/builder/roleedit.js', 'ui/farms/builder/roleslibrary.js', 'ui/farms/builder/tabs/dbmsr.js', 'ui/farms/builder/tabs/cloudfoundry.js', 'ui/farms/builder/tabs/rabbitmq.js', 'ui/farms/builder/tabs/mongodb.js', 'ui/farms/builder/tabs/haproxy.js', 'ui/farms/builder/tabs/proxy.js', 'ui/farms/builder/tabs/mysql.js', 'ui/farms/builder/tabs/nimbula.js', 'ui/farms/builder/tabs/rds.js', 'ui/farms/builder/tabs/gce.js', 'ui/farms/builder/tabs/scaling.js', 'ui/farms/builder/tabs/scripting.js', 'ui/farms/builder/tabs/advanced.js', 'ui/farms/builder/tabs/ec2.js', 'ui/farms/builder/tabs/security.js', 'ui/farms/builder/tabs/storage.js', 'ui/farms/builder/tabs/variables.js', 'ui/farms/builder/tabs/devel.js', 'ui/farms/builder/tabs/chef.js', 'ui/farms/builder/tabs/vpcrouter.js', 'ui/farms/builder/tabs/network.js', 'ui/farms/builder/tabs/deployments.js', 'ui/farms/builder/tabs/ebs.js', 'ui/farms/builder/tabs/params.js', 'ui/farms/builder/tabs/servicesconfig.js', 'ui/farms/builder/roleslibrary/ec2.js', 'ui/farms/builder/roleslibrary/vpc.js', 'ui/farms/builder/roleslibrary/euca.js', 'ui/farms/builder/roleslibrary/rackspace.js', 'ui/farms/builder/roleslibrary/openstack.js', 'ui/farms/builder/roleslibrary/cloudstack.js', 'ui/farms/builder/roleslibrary/gce.js', 'ui/farms/builder/roleslibrary/mongodb.js', 'ui/farms/builder/roleslibrary/dbmsr.js', 'ui/farms/builder/roleslibrary/proxy.js', 'ui/farms/builder/roleslibrary/haproxy.js', 'ui/farms/builder/roleslibrary/chef.js', 'codemirror/codemirror.js', 'ui/core/variablefield.js', 'ui/scripts/scriptfield.js', 'ux-boxselect.js', 'ui/monitoring/window.js', 'ui/services/chef/chefsettings.js', 'ui/security/groups/sgeditor.js'), array('ui/farms/builder/selroles.css', 'ui/farms/builder/roleedit.css', 'ui/farms/builder/roleslibrary.css', 'codemirror/codemirror.css', 'ui/core/variablefield.css', 'ui/scripts/scriptfield.css', 'ui/farms/builder/tabs/scaling.css'));
 }
Esempio n. 4
0
 public function getDefinition()
 {
     $roleDefinition = new stdClass();
     $roleDefinition->roleId = $this->RoleID;
     $roleDefinition->platform = $this->Platform;
     $roleDefinition->cloudLocation = $this->CloudLocation;
     $roleDefinition->alias = $this->Alias;
     // Settings
     $roleDefinition->settings = array();
     foreach ($this->GetAllSettings() as $k => $v) {
         $roleDefinition->settings[$k] = $v;
     }
     //Farm Global Variables
     $variables = new Scalr_Scripting_GlobalVariables($this->GetFarmObject()->ClientID, $this->GetFarmObject()->EnvID, Scalr_Scripting_GlobalVariables::SCOPE_FARMROLE);
     $roleDefinition->globalVariables = $variables->getValues($this->RoleID, $this->FarmID, $this->ID);
     //Storage
     $storage = $this->getStorage();
     $configs = $storage->getConfigs();
     if (!empty($configs)) {
         foreach ($configs as $cfg) {
             $cfg = (array) $cfg;
             unset($cfg['id']);
             unset($cfg['status']);
             $roleDefinition->storage[] = $cfg;
         }
     }
     // Scripts
     $scripts = $this->DB->GetAll("SELECT * FROM farm_role_scripts WHERE farm_roleid=? AND issystem='1'", array($this->ID));
     $roleDefinition->scripts = array();
     foreach ($scripts as $script) {
         $itm = new stdClass();
         $itm->event = $script['event_name'];
         $itm->scriptId = (int) $script['scriptid'];
         $itm->params = unserialize($script['params']);
         $itm->target = $script['target'];
         $itm->version = (int) $script['version'];
         $itm->timeout = $script['timeout'];
         $itm->isSync = $script['issync'];
         $itm->isMenuItem = $script['ismenuitem'];
         $itm->orderIndex = $script['order_index'];
         $itm->scriptPath = $script['script_path'];
         $itm->runAs = $script['run_as'];
         $roleDefinition->scripts[] = $itm;
     }
     // Scaling times
     $scalingTimes = $this->DB->GetAll("SELECT * FROM farm_role_scaling_times WHERE farm_roleid = ?", array($this->ID));
     $roleDefinition->scalingTimes = array();
     foreach ($scalingTimes as $time) {
         $itm = new stdClass();
         $itm->startTime = $time['start_time'];
         $itm->endTime = $time['end_time'];
         $itm->daysOfWeek = $time['days_of_week'];
         $itm->instanceCount = $time['instances_count'];
         $roleDefinition->scalingTimes[] = $itm;
     }
     // Scaling metrics
     $scalingMetrics = $this->DB->GetAll("SELECT * FROM farm_role_scaling_metrics WHERE farm_roleid = ?", array($this->ID));
     $roleDefinition->scalingMetrics = array();
     foreach ($scalingMetrics as $metric) {
         $itm = new stdClass();
         $itm->metricId = $metric['metric_id'];
         $itm->settings = unserialize($metric['settings']);
         $roleDefinition->scalingMetrics[] = $itm;
     }
     return $roleDefinition;
 }
Esempio n. 5
0
 public function editAction()
 {
     $this->request->restrictAccess(Acl::RESOURCE_FARMS_ROLES, Acl::PERM_FARMS_ROLES_MANAGE);
     $this->request->defineParams(array('roleId' => array('type' => 'int')));
     $params = array();
     $params['scriptData'] = \Scalr\Model\Entity\Script::getScriptingData($this->user->getAccountId(), $this->getEnvironmentId(true));
     $params['categories'] = $this->db->GetAll("SELECT * FROM role_categories WHERE env_id IS NULL OR env_id = ?", [$this->user->isScalrAdmin() ? null : $this->getEnvironmentId()]);
     $params['accountScripts'] = [];
     if (!$this->user->isScalrAdmin()) {
         foreach (self::loadController('Orchestration', 'Scalr_UI_Controller_Account2')->getOrchestrationRules() as $script) {
             $script['system'] = 'account';
             $params['accountScripts'][] = $script;
         }
     }
     $variables = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->user->isScalrAdmin() ? 0 : $this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_ROLE);
     if ($this->getParam('roleId')) {
         $dbRole = DBRole::loadById($this->getParam('roleId'));
         if (!$this->user->isScalrAdmin()) {
             $this->user->getPermissions()->validate($dbRole);
         }
         $images = array();
         foreach (RoleImage::find([['roleId' => $dbRole->id]]) as $image) {
             /* @var $image RoleImage */
             $im = $image->getImage();
             $a = get_object_vars($image);
             if ($im) {
                 $b = get_object_vars($im);
                 $b['dtAdded'] = Scalr_Util_DateTime::convertTz($b['dtAdded']);
                 $b['software'] = $im->getSoftwareAsString();
                 $a['name'] = $im->name;
                 $a['hash'] = $im->hash;
                 $a['extended'] = $b;
             }
             $images[] = $a;
         }
         $params['role'] = array('roleId' => $dbRole->id, 'name' => $dbRole->name, 'catId' => $dbRole->catId, 'os' => $dbRole->getOs()->name, 'osId' => $dbRole->osId, 'osFamily' => $dbRole->getOs()->family, 'osGeneration' => $dbRole->getOs()->generation, 'osVersion' => $dbRole->getOs()->version, 'description' => $dbRole->description, 'behaviors' => $dbRole->getBehaviors(), 'images' => $images, 'scripts' => $dbRole->getScripts(), 'dtadded' => Scalr_Util_DateTime::convertTz($dbRole->dateAdded), 'addedByEmail' => $dbRole->addedByEmail, 'chef' => $dbRole->getProperties('chef.'));
         $params['role']['variables'] = $variables->getValues($dbRole->id);
         if ($this->user->isScalrAdmin()) {
             $params['roleUsage'] = array('farms' => $dbRole->getFarmRolesCount(), 'instances' => $this->db->GetOne("SELECT COUNT(*) FROM servers LEFT JOIN farm_roles ON servers.farm_roleid = farm_roles.id WHERE farm_roles.role_id=?", array($dbRole->id)));
         } else {
             $params['roleUsage'] = array('farms' => $dbRole->getFarmRolesCount($this->getEnvironmentId()), 'instances' => $this->db->GetOne("SELECT COUNT(*) FROM servers LEFT JOIN farm_roles ON servers.farm_roleid = farm_roles.id WHERE farm_roles.role_id=? AND env_id=?", array($dbRole->id, $this->getEnvironmentId())));
         }
     } else {
         $params['role'] = array('roleId' => 0, 'name' => '', 'arch' => 'x86_64', 'agent' => 2, 'description' => '', 'behaviors' => array(), 'images' => array(), 'scripts' => array(), 'tags' => array(), 'variables' => $variables->getValues());
     }
     $this->response->page('ui/roles/edit.js', $params, array('ui/roles/edit/overview.js', 'ui/roles/edit/images.js', 'ui/roles/edit/scripting.js', 'ui/roles/edit/variables.js', 'ui/roles/edit/chef.js', 'ui/scripts/scriptfield.js', 'ui/core/variablefield.js', 'ui/services/chef/chefsettings.js'), array('ui/roles/edit.css', 'ui/scripts/scriptfield.css'));
 }
Esempio n. 6
0
 public function variablesAction()
 {
     if ($this->user->isAdmin()) {
         throw new Scalr_Exception_InsufficientPermissions();
     }
     $this->request->restrictAccess(Acl::RESOURCE_ENVADMINISTRATION_GLOBAL_VARIABLES);
     $vars = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_ENVIRONMENT);
     $this->response->page('ui/core/variables.js', array('variables' => json_encode($vars->getValues())), array('ui/core/variablefield.js'), array('ui/core/variablefield.css'));
 }
Esempio n. 7
0
 public function edit2Action()
 {
     $this->request->restrictAccess(Acl::RESOURCE_FARMS_ROLES, Acl::PERM_FARMS_ROLES_MANAGE);
     $this->request->defineParams(array('roleId' => array('type' => 'int')));
     $params = array('platforms' => array());
     $platforms = $this->user->isScalrAdmin() ? (array) \Scalr::config('scalr.allowed_clouds') : $this->getEnvironment()->getEnabledPlatforms();
     foreach ($platforms as $platform) {
         $params['platforms'][$platform] = array('locations' => array());
         if ($platform !== 'gce') {
             foreach (PlatformFactory::NewPlatform($platform)->getLocations() as $lk => $lv) {
                 $params['platforms'][$platform]['locations'][$lk] = $lv;
             }
         }
     }
     $params['scriptData'] = self::loadController('Scripts')->getScriptingData();
     $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->isScalrAdmin()) {
             $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, 'architecture' => $imageInfo['architecture']);
                 }
             }
         }
         $params['role'] = array('roleId' => $dbRole->id, 'name' => $dbRole->name, 'catId' => $dbRole->catId, 'os' => $dbRole->os, 'osFamily' => $dbRole->osFamily, 'osGeneration' => $dbRole->osGeneration, 'osVersion' => $dbRole->osVersion, 'description' => $dbRole->description, 'behaviors' => $dbRole->getBehaviors(), 'images' => $images, 'scripts' => $dbRole->getScripts(), 'dtadded' => Scalr_Util_DateTime::convertTz($dbRole->{$dbRole}->dateAdded), 'addedByEmail' => $dbRole->addedByEmail, 'software' => $dbRole->getSoftwareList(), 'tags' => array_flip($dbRole->getTags()));
         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));
         }
     } else {
         $params['role'] = array('roleId' => 0, 'name' => '', 'arch' => 'x86_64', 'agent' => 2, 'description' => '', 'behaviors' => array(), 'images' => array(), 'scripts' => array(), 'tags' => array());
     }
     $this->response->page('ui/roles/edit2.js', $params, array('ui/roles/edit/overview.js', 'ui/roles/edit/images.js', 'ui/roles/edit/scripting.js', 'ui/roles/edit/variables.js', 'ui/roles/edit/chef.js', 'ui/scripts/scriptfield2.js', 'ui/core/variablefield.js', 'ux-boxselect.js', 'ui/services/chef/chefsettings.js'), array('ui/roles/edit2.css', 'ui/scripts/scriptfield2.css', 'ui/core/variablefield.css'));
 }
Esempio n. 8
0
 public function getDefinition()
 {
     $farmDefinition = new stdClass();
     $farmDefinition->name = $this->Name;
     $farmDefinition->rolesLaunchOrder = $this->RolesLaunchOrder;
     // Farm Roles
     $farmDefinition->roles = array();
     foreach ($this->GetFarmRoles() as $dbFarmRole) {
         $farmDefinition->roles[] = $dbFarmRole->getDefinition();
     }
     //Farm Global Variables
     $variables = new Scalr_Scripting_GlobalVariables($this->ClientID, $this->EnvID, ScopeInterface::SCOPE_FARM);
     $farmDefinition->globalVariables = $variables->getValues(0, $this->ID, 0);
     //Farm Settings
     $farmDefinition->settings = $this->GetAllSettings();
     return $farmDefinition;
 }
Esempio n. 9
0
 public function getFarm2($farmId)
 {
     $dbFarm = DBFarm::LoadByID($farmId);
     $this->user->getPermissions()->validate($dbFarm);
     $farmRoleId = $this->getParam('farmRoleId');
     $farmRoles = array();
     $variables = new Scalr_Scripting_GlobalVariables($this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_FARM);
     $farmRoleVariables = new Scalr_Scripting_GlobalVariables($this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_FARMROLE);
     foreach ($dbFarm->GetFarmRoles() as $dbFarmRole) {
         if ($farmRoleId && $farmRoleId != $dbFarmRole->ID) {
             continue;
         }
         $scripts = $this->db->GetAll("\n                SELECT farm_role_scripts.*, scripts.name\n                FROM farm_role_scripts\n                LEFT JOIN scripts ON scripts.id = farm_role_scripts.scriptid\n                WHERE farm_roleid=? AND issystem='1'\n            ", array($dbFarmRole->ID));
         $scriptsObject = array();
         foreach ($scripts as $script) {
             if (!empty($script['scriptid']) || !empty($script['script_path'])) {
                 $s = array('script_id' => $script['scriptid'], 'script' => $script['name'], 'params' => unserialize($script['params']), 'target' => $script['target'], 'version' => $script['version'], 'timeout' => $script['timeout'], 'issync' => $script['issync'], 'order_index' => $script['order_index'], 'event' => $script['event_name'], 'script_path' => $script['script_path'], 'run_as' => $script['run_as']);
             }
             if ($script['target'] == Scalr_Script::TARGET_BEHAVIORS || $script['target'] == Scalr_Script::TARGET_ROLES) {
                 $varName = $script['target'] == Scalr_Script::TARGET_ROLES ? 'target_roles' : 'target_behaviors';
                 $s[$varName] = array();
                 $r = $this->db->GetAll("SELECT `target` FROM farm_role_scripting_targets WHERE farm_role_script_id = ?", array($script['id']));
                 foreach ($r as $v) {
                     array_push($s[$varName], $v['target']);
                 }
             }
             $scriptsObject[] = $s;
         }
         //Scripting params
         $scriptingParams = $this->db->Execute("\n                SELECT * FROM farm_role_scripting_params\n                WHERE farm_role_id = ? AND farm_role_script_id = '0'\n            ", array($dbFarmRole->ID));
         $sParams = array();
         while ($p = $scriptingParams->FetchRow()) {
             $sParams[] = array('hash' => $p['hash'], 'role_script_id' => $p['role_script_id'], 'params' => unserialize($p['params']));
         }
         $scalingManager = new Scalr_Scaling_Manager($dbFarmRole);
         $scaling = array();
         foreach ($scalingManager->getFarmRoleMetrics() as $farmRoleMetric) {
             $scaling[$farmRoleMetric->metricId] = $farmRoleMetric->getSettings();
         }
         $dbPresets = $this->db->GetAll("SELECT * FROM farm_role_service_config_presets WHERE farm_roleid=?", array($dbFarmRole->ID));
         $presets = array();
         foreach ($dbPresets as $preset) {
             $presets[$preset['behavior']] = $preset['preset_id'];
         }
         if ($dbFarmRole->NewRoleID) {
             $roleName = DBRole::loadById($dbFarmRole->NewRoleID)->name;
             $isBundling = true;
         } else {
             $roleName = $dbFarmRole->GetRoleObject()->name;
             $isBundling = false;
         }
         $imageDetails = $dbFarmRole->GetRoleObject()->getImageDetails($dbFarmRole->Platform, $dbFarmRole->CloudLocation);
         $storages = array('configs' => $dbFarmRole->getStorage()->getConfigs());
         foreach ($dbFarmRole->getStorage()->getVolumes() as $configKey => $config) {
             $storages['devices'][$configKey] = array();
             foreach ($config as $device) {
                 $info = array('farmRoleId' => $device->farmRoleId, 'placement' => $device->placement, 'serverIndex' => $device->serverIndex, 'storageId' => $device->storageId, 'storageConfigId' => $device->storageConfigId, 'status' => $device->status);
                 try {
                     $server = DBServer::LoadByFarmRoleIDAndIndex($device->farmRoleId, $device->serverIndex);
                     if ($server->status != SERVER_STATUS::TERMINATED && $server->status != SERVER_STATUS::TROUBLESHOOTING) {
                         $info['serverId'] = $server->serverId;
                         $info['serverInstanceId'] = $server->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID);
                     }
                 } catch (Exception $e) {
                     $this->response->varDump($e->getMessage());
                     $this->response->varDump($e->getTraceAsString());
                 }
                 $storages['devices'][$configKey][] = $info;
             }
         }
         $imageInfo = $dbFarmRole->GetRoleObject()->getImageDetails($dbFarmRole->Platform, $dbFarmRole->CloudLocation);
         $architecture = $imageInfo['architecture'];
         $securityGroups = $this->getInitialSecurityGroupsList($dbFarmRole);
         $farmRoles[] = array('farm_role_id' => $dbFarmRole->ID, 'alias' => $dbFarmRole->Alias ? $dbFarmRole->Alias : $dbFarmRole->GetRoleObject()->name, 'role_id' => $dbFarmRole->RoleID, 'platform' => $dbFarmRole->Platform, 'os' => $dbFarmRole->GetRoleObject()->os, 'os_family' => $dbFarmRole->GetRoleObject()->osFamily, 'os_generation' => $dbFarmRole->GetRoleObject()->osGeneration, 'os_version' => $dbFarmRole->GetRoleObject()->osVersion, 'generation' => $dbFarmRole->GetRoleObject()->generation, 'group' => $dbFarmRole->GetRoleObject()->getCategoryName(), 'cat_id' => $dbFarmRole->GetRoleObject()->catId, 'arch' => $architecture, 'name' => $roleName, 'is_bundle_running' => $isBundling, 'behaviors' => implode(",", $dbFarmRole->GetRoleObject()->getBehaviors()), 'scripting' => $scriptsObject, 'scripting_params' => $sParams, 'settings' => $dbFarmRole->GetAllSettings(), 'cloud_location' => $dbFarmRole->CloudLocation, 'launch_index' => (int) $dbFarmRole->LaunchIndex, 'scaling' => $scaling, 'config_presets' => $presets, 'tags' => $dbFarmRole->GetRoleObject()->getTags(), 'storages' => $storages, 'variables' => $farmRoleVariables->getValues($dbFarmRole->GetRoleID(), $dbFarm->ID, $dbFarmRole->ID), 'running_servers' => $dbFarmRole->GetRunningInstancesCount(), 'security_groups' => $securityGroups);
     }
     $vpc = array();
     if ($dbFarm->GetSetting(DBFarm::SETTING_EC2_VPC_ID)) {
         $vpc = array('id' => $dbFarm->GetSetting(DBFarm::SETTING_EC2_VPC_ID), 'region' => $dbFarm->GetSetting(DBFarm::SETTING_EC2_VPC_REGION));
     }
     return array('farm' => array('name' => $dbFarm->Name, 'description' => $dbFarm->Comments, 'rolesLaunchOrder' => $dbFarm->RolesLaunchOrder, 'timezone' => $dbFarm->GetSetting(DBFarm::SETTING_TIMEZONE), 'variables' => $variables->getValues(0, $dbFarm->ID), 'vpc' => $vpc, 'status' => $dbFarm->Status), 'roles' => $farmRoles, 'lock' => $dbFarm->isLocked(false), 'changed' => $dbFarm->changedTime);
 }
Esempio n. 10
0
 /**
  * @param int $farmId optional
  * @param int $roleId optional
  * @param string $scalrPageHash optional
  * @param string $scalrPageUiHash optional
  * @throws Scalr_Exception_InsufficientPermissions
  */
 public function xGetFarmAction($farmId = null, $roleId = null, $scalrPageHash = null, $scalrPageUiHash = null)
 {
     if ($scalrPageHash && $scalrPageHash != $this->calcFarmDesignerHash()) {
         $this->response->data(['scalrPageHashMismatch' => true]);
         return;
     }
     if ($scalrPageUiHash && $scalrPageUiHash != $this->response->pageUiHash()) {
         $this->response->data(['scalrPageUiHashMismatch' => true]);
         return;
     }
     $moduleParams = array('farmId' => $farmId, 'roleId' => $roleId, 'behaviors' => ROLE_BEHAVIORS::GetName(null, true));
     unset($moduleParams['behaviors'][ROLE_BEHAVIORS::CASSANDRA]);
     unset($moduleParams['behaviors'][ROLE_BEHAVIORS::CUSTOM]);
     unset($moduleParams['behaviors'][ROLE_BEHAVIORS::HAPROXY]);
     //platforms list
     $platforms = self::loadController('Platforms')->getEnabledPlatforms();
     if (empty($platforms)) {
         throw new Exception('Before building new farm you need to configure environment and setup cloud credentials');
     }
     //categories list
     $categories = $this->db->GetAll("SELECT c.id, c.name, COUNT(DISTINCT r.id) AS total\n             FROM role_categories c\n             LEFT JOIN roles r ON c.id = r.cat_id AND (r.env_id IS NULL OR r.env_id = ?) AND r.id IN (\n                SELECT role_id\n                FROM role_images\n                WHERE role_id = r.id\n                AND platform IN ('" . implode("','", array_keys($platforms)) . "')\n             )\n             WHERE c.env_id IS NULL OR c.env_id = ?\n             GROUP BY c.id\n            ", array($this->environment->id, $this->environment->id));
     $moduleParams['categories'] = array();
     foreach ($categories as $g) {
         $moduleParams['categories'][$g['id']] = $g;
     }
     $moduleParams['farmVpcEc2Enabled'] = $this->getEnvironment()->isPlatformEnabled(SERVER_PLATFORMS::EC2);
     if ($moduleParams['farmVpcEc2Enabled']) {
         $moduleParams['farmVpcEc2Locations'] = self::loadController('Platforms')->getCloudLocations(SERVER_PLATFORMS::EC2, false);
     }
     if ($farmId) {
         $this->request->restrictFarmAccess(DBFarm::LoadByID($farmId), Acl::PERM_FARMS_MANAGE);
         $c = self::loadController('Builder', 'Scalr_UI_Controller_Farms');
         $moduleParams['farm'] = $c->getFarm2($farmId);
     } else {
         $this->request->restrictFarmAccess(null, Acl::PERM_FARMS_MANAGE);
         // TODO: remove hack, do better
         $vars = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->getEnvironmentId(), ScopeInterface::SCOPE_FARM);
         $moduleParams['farmVariables'] = $vars->getValues();
     }
     $moduleParams['tabs'] = array('vpcrouter', 'dbmsr', 'mongodb', 'mysql', 'scaling', 'network', 'cloudfoundry', 'rabbitmq', 'haproxy', 'proxy', 'scripting', 'ec2', 'openstack', 'gce', 'azure', 'security', 'devel', 'storage', 'variables', 'advanced', 'chef');
     //deprecated tabs
     if (\Scalr::config('scalr.ui.show_deprecated_features')) {
         $moduleParams['tabs'][] = 'deployments';
         $moduleParams['tabs'][] = 'ebs';
         $moduleParams['tabs'][] = 'servicesconfig';
     }
     $conf = $this->getContainer()->config->get('scalr.load_statistics.connections.plotter');
     $moduleParams['tabParams'] = array('farmId' => $farmId, 'farmHash' => $moduleParams['farm'] ? $moduleParams['farm']['farm']['hash'] : '', 'accountId' => $this->environment->cloudCredentials(SERVER_PLATFORMS::EC2)->properties[Entity\CloudCredentialsProperty::AWS_ACCOUNT_ID], 'remoteAddress' => $this->request->getRemoteAddr(), 'monitoringHostUrl' => "{$conf['scheme']}://{$conf['host']}:{$conf['port']}", 'nginx' => array('server_section' => file_get_contents(APPPATH . '/templates/services/nginx/server_section.tpl'), 'server_section_ssl' => file_get_contents(APPPATH . '/templates/services/nginx/server_section_ssl.tpl')));
     $moduleParams['tabParams']['scalr.dns.global.enabled'] = \Scalr::config('scalr.dns.global.enabled');
     $moduleParams['tabParams']['scalr.instances_connection_policy'] = \Scalr::config('scalr.instances_connection_policy');
     $moduleParams['tabParams']['scalr.scalarizr_update.repos'] = array_keys(\Scalr::config('scalr.scalarizr_update.repos'));
     $moduleParams['tabParams']['scalr.scalarizr_update.devel_repos'] = is_array(\Scalr::config('scalr.scalarizr_update.devel_repos')) ? array_keys(\Scalr::config('scalr.scalarizr_update.devel_repos')) : [];
     $moduleParams['tabParams']['scalr.scalarizr_update.default_repo'] = \Scalr::config('scalr.scalarizr_update.default_repo');
     $moduleParams['tabParams']['scalr.aws.ec2.limits.security_groups_per_instance'] = \Scalr::config('scalr.aws.ec2.limits.security_groups_per_instance');
     $moduleParams['metrics'] = Entity\ScalingMetric::getList($this->getEnvironmentId());
     $moduleParams['timezones_list'] = Scalr_Util_DateTime::getTimezones();
     $moduleParams['timezone_default'] = $this->user->getSetting(Scalr_Account_User::SETTING_UI_TIMEZONE);
     if ($moduleParams['farm']['farm']['ownerEditable']) {
         $moduleParams['usersList'] = Scalr_Account_User::getList($this->user->getAccountId());
     }
     $defaultFarmRoleSecurityGroups = array('default');
     if (\Scalr::config('scalr.aws.security_group_name')) {
         $defaultFarmRoleSecurityGroups[] = \Scalr::config('scalr.aws.security_group_name');
     }
     $moduleParams['roleDefaultSettings'] = array('base.keep_scripting_logs_time' => \Scalr::config('scalr.system.scripting.default_instance_log_rotation_period'), 'security_groups.list' => json_encode($defaultFarmRoleSecurityGroups), 'base.abort_init_on_script_fail' => \Scalr::config('scalr.system.scripting.default_abort_init_on_script_fail') ? 1 : 0, 'base.disable_firewall_management' => \Scalr::config('scalr.system.default_disable_firewall_management') ? 1 : 0);
     //cost analytics
     if ($this->getContainer()->analytics->enabled && $this->getEnvironment()->getPlatformConfigValue(Scalr_Environment::SETTING_CC_ID)) {
         $farmCostData = $this->getFarmCostData($farmId);
         $moduleParams['analytics'] = $farmCostData['analytics'];
         if ($farmId) {
             $moduleParams['farm']['farm']['projectId'] = $farmCostData['projectId'];
             $moduleParams['analytics']['farmCostMetering'] = $farmCostData['farmCostMetering'];
         }
     }
     $moduleParams['farmLaunchPermission'] = $farmId ? $moduleParams['farm']['farm']['launchPermission'] : $this->request->isFarmAllowed(null, Acl::PERM_FARMS_LAUNCH_TERMINATE);
     if ($moduleParams['farm']['farm']['teamOwnerEditable'] || !$farmId) {
         if ($this->user->canManageAcl()) {
             $teams = $this->db->getAll('SELECT id, name, description FROM account_teams WHERE account_id = ?', array($this->user->getAccountId()));
         } else {
             $teams = $this->user->getTeams();
             $teamId = $moduleParams['farm']['farm']['teamOwner'];
             $flag = !!$teamId;
             foreach ($teams as $t) {
                 if ($t['id'] == $teamId) {
                     $flag = false;
                     break;
                 }
             }
             if ($flag) {
                 // team is missed in list, add manually
                 $team = $this->db->GetRow('SELECT name, description FROM account_teams WHERE id = ?', [$teamId]);
                 array_unshift($teams, ['id' => $teamId, 'name' => $team ? $team['name'] : '', 'description' => $team ? $team['description'] : '']);
             }
         }
         array_unshift($teams, ['id' => 0, 'name' => '']);
         $moduleParams['teamsList'] = $teams;
     }
     $this->response->data($moduleParams);
 }
Esempio n. 11
0
 public static function createFromBundleTask(BundleTask $BundleTask)
 {
     $db = \Scalr::getDb();
     $DBServer = DBServer::LoadByID($BundleTask->serverId);
     if ($BundleTask->prototypeRoleId) {
         $proto_role = $db->GetRow("SELECT * FROM roles WHERE id=? LIMIT 1", array($BundleTask->prototypeRoleId));
         if (!$proto_role['architecture']) {
             $proto_role['architecture'] = $DBServer->GetProperty(SERVER_PROPERTIES::ARCHITECTURE);
         }
     } else {
         $proto_role = array("behaviors" => $DBServer->GetProperty(SERVER_PROPERTIES::SZR_IMPORTING_BEHAVIOR), "architecture" => $DBServer->GetProperty(SERVER_PROPERTIES::ARCHITECTURE), "name" => "*import*");
     }
     if (!$proto_role['architecture']) {
         $proto_role['architecture'] = 'x86_64';
     }
     if (!$BundleTask->cloudLocation) {
         if ($DBServer) {
             $BundleTask->cloudLocation = $DBServer->GetCloudLocation();
         }
     }
     $osInfo = $BundleTask->getOsDetails();
     $meta = $BundleTask->getSnapshotDetails();
     if (!$osInfo->family || !$osInfo->generation) {
         $osInfo = new stdClass();
         if ($proto_role) {
             $osInfo->name = $proto_role['os'];
             $osInfo->family = $proto_role['os_family'];
             $osInfo->generation = $proto_role['os_generation'];
             $osInfo->version = $proto_role['os_version'];
         } elseif ($meta['os'] && $meta['os']->version) {
             if ($meta['os']->version == '2008Server') {
                 $osInfo->name = 'Windows 2008 Server';
                 $osInfo->family = 'windows';
                 $osInfo->generation = '2008';
                 $osInfo->version = '2008Server';
             } elseif ($meta['os']->version == '2008ServerR2') {
                 $osInfo->name = 'Windows 2008 Server R2';
                 $osInfo->family = 'windows';
                 $osInfo->generation = '2008';
                 $osInfo->version = '2008ServerR2';
             }
         }
     }
     if ($proto_role['cat_id']) {
         $catId = $proto_role['cat_id'];
     } else {
         $catId = ROLE_BEHAVIORS::GetCategoryId($proto_role['behaviors']);
     }
     $db->Execute("INSERT INTO roles SET\n            name\t\t\t= ?,\n            origin\t\t\t= ?,\n            dtadded         = NOW(),\n            client_id\t\t= ?,\n            env_id\t\t\t= ?,\n            cat_id          = ?,\n            description\t\t= ?,\n            behaviors\t\t= ?,\n            history\t\t\t= ?,\n            generation\t\t= ?,\n            added_by_email  = ?,\n            added_by_userid = ?,\n            os\t\t\t\t= ?,\n            os_family       = ?,\n            os_version      = ?,\n            os_generation   = ?\n        ", array($BundleTask->roleName, ROLE_TYPE::CUSTOM, $BundleTask->clientId, $BundleTask->envId, $catId, $BundleTask->description, $proto_role['behaviors'], trim("{$proto_role['history']},{$proto_role['name']}", ","), 2, $BundleTask->createdByEmail, $BundleTask->createdById, $osInfo->name, $osInfo->family, $osInfo->version, $osInfo->generation));
     $role_id = $db->Insert_Id();
     $BundleTask->roleId = $role_id;
     $BundleTask->Save();
     $BundleTask->Log(sprintf("Created new role. Role name: %s. Role ID: %s", $BundleTask->roleName, $BundleTask->roleId));
     $role = self::loadById($role_id);
     $behaviors = explode(",", $proto_role['behaviors']);
     foreach ($behaviors as $behavior) {
         $db->Execute("INSERT INTO role_behaviors SET\n                role_id\t\t\t= ?,\n                behavior\t\t= ?\n            ", array($role_id, $behavior));
     }
     // Set image
     $role->setImage($BundleTask->snapshotId, $BundleTask->platform, $BundleTask->platform != SERVER_PLATFORMS::GCE ? $BundleTask->cloudLocation : "", $meta['szr_version'], $proto_role['architecture']);
     // Set params
     if ($proto_role['id']) {
         $dbParams = $db->GetAll("SELECT name,type,isrequired,defval,allow_multiple_choice,options,hash,issystem\n                FROM role_parameters WHERE role_id = ?", array($proto_role['id']));
         $role->setParameters($dbParams);
         $dbSecRules = $db->GetAll("SELECT * FROM role_security_rules WHERE role_id = ?", array($proto_role['id']));
         foreach ($dbSecRules as $dbSecRule) {
             $db->Execute("INSERT INTO role_security_rules SET role_id = ?, rule = ?", array($role_id, $dbSecRule['rule']));
         }
         $props = $db->GetAll("SELECT * FROM role_properties WHERE role_id=?", array($proto_role['id']));
         foreach ($props as $prop) {
             $role->setProperty($prop['name'], $prop['value']);
         }
         $scripts = $db->GetAll("SELECT * FROM role_scripts WHERE role_id=?", array($proto_role['id']));
         foreach ($scripts as &$script) {
             $script['params'] = unserialize($script['params']);
         }
         $role->setScripts($scripts);
         $variables = new Scalr_Scripting_GlobalVariables($proto_role['env_id'], Scalr_Scripting_GlobalVariables::SCOPE_ROLE);
         $variables->setValues($variables->getValues($proto_role['id']), $role->id);
     }
     // Set software
     if ($meta) {
         $software = array();
         foreach ((array) $meta['software'] as $soft) {
             $software[$soft->name] = $soft->version;
         }
         $role->setSoftware($software);
         $role->setTags((array) $meta['tags']);
         if ($BundleTask->platform == SERVER_PLATFORMS::NIMBULA) {
             $props = array(array('name' => self::PROPERTY_NIMBULA_INIT_ROOT_USER, 'value' => $meta['init_root_user']), array('name' => self::PROPERTY_NIMBULA_INIT_ROOT_PASS, 'value' => $meta['init_root_pass']), array('name' => self::PROPERTY_NIMBULA_ENTRY, 'value' => ''));
             foreach ($props as $prop) {
                 $role->setProperty($prop['name'], $prop['value']);
             }
         }
     }
     return $role;
 }
Esempio n. 12
0
 /**
  * @param   int   $roleId
  * @throws  Exception
  * @throws  Scalr_Exception_Core
  * @throws  Scalr_Exception_InsufficientPermissions
  * @throws  Scalr_UI_Exception_NotFound
  */
 public function editAction($roleId = 0)
 {
     $this->request->restrictAccess('ROLES', 'MANAGE');
     $params = array();
     $params['scriptData'] = \Scalr\Model\Entity\Script::getScriptingData($this->user->getAccountId(), $this->getEnvironmentId(true));
     $params['categories'] = array_values($this->listRoleCategories());
     $params['accountScripts'] = [];
     if (!$this->user->isScalrAdmin()) {
         foreach (Scalr_UI_Controller_Account2_Orchestration::controller()->getOrchestrationRules() as $script) {
             $script['system'] = 'account';
             $params['accountScripts'][] = $script;
         }
     }
     $envs = [];
     if ($this->request->getScope() == ScopeInterface::SCOPE_ACCOUNT) {
         foreach (Environment::find([['accountId' => $this->user->getAccountId()]], null, ['name' => true]) as $env) {
             /* @var $env Environment */
             $envs[] = ['id' => $env->id, 'name' => $env->name, 'enabled' => 1];
         }
     }
     $variables = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->getEnvironmentId(true), ScopeInterface::SCOPE_ROLE);
     if ($roleId) {
         /* @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, true);
         $images = array();
         foreach (RoleImage::find([['roleId' => $role->id]]) as $image) {
             /* @var $image RoleImage */
             $im = $image->getImage();
             $a = get_object_vars($image);
             if ($im) {
                 $b = get_object_vars($im);
                 $b['scope'] = $im->getScope();
                 $b['dtAdded'] = Scalr_Util_DateTime::convertTz($b['dtAdded']);
                 $b['software'] = $im->getSoftwareAsString();
                 $a['name'] = $im->name;
                 $a['hash'] = $im->hash;
                 $a['extended'] = $b;
             }
             $images[] = $a;
         }
         $properties = [];
         foreach (RoleProperty::find([['roleId' => $role->id], ['name' => ['$like' => 'chef.%']]]) as $prop) {
             /* @var $prop RoleProperty */
             $properties[$prop->name] = $prop->value;
         }
         $params['role'] = array('roleId' => $role->id, 'name' => $role->name, 'catId' => $role->catId, 'os' => $role->getOs()->name, 'osId' => $role->osId, 'osFamily' => $role->getOs()->family, 'osGeneration' => $role->getOs()->generation, 'osVersion' => $role->getOs()->version, 'description' => $role->description, 'behaviors' => $role->getBehaviors(), 'images' => $images, 'scripts' => $role->getScripts(), 'dtadded' => Scalr_Util_DateTime::convertTz($role->added), 'addedByEmail' => $role->addedByEmail, 'chef' => $properties, 'isQuickStart' => $role->isQuickStart, 'isDeprecated' => $role->isDeprecated, 'isScalarized' => $role->isScalarized, 'environments' => []);
         if ($this->request->getScope() == ScopeInterface::SCOPE_ACCOUNT) {
             $allowedEnvs = $role->getAllowedEnvironments();
             if (!empty($allowedEnvs)) {
                 foreach ($envs as &$env) {
                     $env['enabled'] = in_array($env['id'], $allowedEnvs) ? 1 : 0;
                 }
             }
             $params['role']['environments'] = $envs;
         }
         $params['role']['variables'] = $variables->getValues($role->id);
         $params['roleUsage'] = ['farms' => $role->getFarmsCount($this->user->getAccountId(), $this->getEnvironmentId(true)), 'instances' => $role->getServersCount($this->user->getAccountId(), $this->getEnvironmentId(true))];
     } else {
         $params['role'] = array('roleId' => 0, 'name' => '', 'arch' => 'x86_64', 'agent' => 2, 'description' => '', 'behaviors' => array(), 'images' => array(), 'scripts' => array(), 'tags' => array(), 'environments' => [], 'variables' => $variables->getValues(), 'isScalarized' => 1);
         if ($this->request->getScope() == ScopeInterface::SCOPE_ACCOUNT) {
             $params['role']['environments'] = $envs;
         }
     }
     $this->response->page('ui/roles/edit.js', $params, ['ui/roles/edit/overview.js', 'ui/roles/edit/images.js', 'ui/roles/edit/scripting.js', 'ui/roles/edit/variables.js', 'ui/roles/edit/chef.js', 'ui/roles/edit/environments.js', 'ui/scripts/scriptfield.js', 'ui/core/variablefield.js', 'ui/services/chef/chefsettings.js'], ['ui/roles/edit.css', 'ui/scripts/scriptfield.css']);
 }
Esempio n. 13
0
 public function editAction()
 {
     $this->request->restrictAccess(Acl::RESOURCE_FARMS_ROLES, Acl::PERM_FARMS_ROLES_MANAGE);
     $this->request->defineParams(array('roleId' => array('type' => 'int')));
     $params = array();
     $params['scriptData'] = \Scalr\Model\Entity\Script::getScriptingData($this->user->getAccountId(), $this->getEnvironment() ? $this->getEnvironmentId() : NULL);
     $params['categories'] = $this->db->GetAll("SELECT * FROM role_categories WHERE env_id IN (0, ?)", array($this->user->isScalrAdmin() ? 0 : $this->getEnvironmentId()));
     if ($this->getParam('roleId')) {
         $dbRole = DBRole::loadById($this->getParam('roleId'));
         if (!$this->user->isScalrAdmin()) {
             $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, 'architecture' => $imageInfo['architecture']);
                 }
             }
         }
         $params['role'] = array('roleId' => $dbRole->id, 'name' => $dbRole->name, 'catId' => $dbRole->catId, 'os' => $dbRole->os, 'osFamily' => $dbRole->osFamily, 'osGeneration' => $dbRole->osGeneration, 'osVersion' => $dbRole->osVersion, 'description' => $dbRole->description, 'behaviors' => $dbRole->getBehaviors(), 'images' => $images, 'scripts' => $dbRole->getScripts(), 'dtadded' => Scalr_Util_DateTime::convertTz($dbRole->dateAdded), 'addedByEmail' => $dbRole->addedByEmail, 'software' => $dbRole->getSoftwareList(), 'tags' => array_fill_keys($dbRole->getTags(), 1), 'chef' => $dbRole->getProperties('chef.'));
         $variables = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->user->isScalrAdmin() ? 0 : $this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_ROLE);
         $params['role']['variables'] = $variables->getValues($dbRole->id);
         if ($this->user->isScalrAdmin()) {
             $params['roleUsage'] = array('farms' => $dbRole->getFarmRolesCount(), 'instances' => $this->db->GetOne("SELECT COUNT(*) FROM servers WHERE role_id=?", array($dbRole->id)));
         } else {
             $params['roleUsage'] = array('farms' => $dbRole->getFarmRolesCount($this->getEnvironmentId()), 'instances' => $this->db->GetOne("SELECT COUNT(*) FROM servers WHERE role_id=? AND env_id=?", array($dbRole->id, $this->getEnvironmentId())));
         }
     } else {
         $params['role'] = array('roleId' => 0, 'name' => '', 'arch' => 'x86_64', 'agent' => 2, 'description' => '', 'behaviors' => array(), 'images' => array(), 'scripts' => array(), 'tags' => array());
     }
     $this->response->page('ui/roles/edit.js', $params, array('ui/roles/edit/overview.js', 'ui/roles/edit/images.js', 'ui/roles/edit/scripting.js', 'ui/roles/edit/variables.js', 'ui/roles/edit/chef.js', 'ui/scripts/scriptfield.js', 'ui/core/variablefield.js', 'ux-boxselect.js', 'ui/services/chef/chefsettings.js'), array('ui/roles/edit.css', 'ui/scripts/scriptfield.css', 'ui/core/variablefield.css'));
 }
Esempio n. 14
0
 public function viewAction()
 {
     $vars = new Scalr_Scripting_GlobalVariables(0, 0, ScopeInterface::SCOPE_SCALR);
     $this->response->page('ui/admin/variables/view.js', array('variables' => json_encode($vars->getValues())), array('ui/core/variablefield.js'));
 }
Esempio n. 15
0
 /**
  * @param int $farmId optional
  * @param int $roleId optional
  * @param string $scalrPageHash optional
  * @param string $scalrPageUiHash optional
  * @throws Scalr_Exception_InsufficientPermissions
  */
 public function xGetFarmAction($farmId = null, $roleId = null, $scalrPageHash = null, $scalrPageUiHash = null)
 {
     if ($scalrPageHash && $scalrPageHash != $this->calcFarmDesignerHash()) {
         $this->response->data(['scalrPageHashMismatch' => true]);
         return;
     }
     if ($scalrPageUiHash && $scalrPageUiHash != $this->response->pageUiHash()) {
         $this->response->data(['scalrPageUiHashMismatch' => true]);
         return;
     }
     $moduleParams = array('farmId' => $farmId, 'roleId' => $roleId, 'behaviors' => ROLE_BEHAVIORS::GetName(null, true));
     unset($moduleParams['behaviors'][ROLE_BEHAVIORS::CASSANDRA]);
     unset($moduleParams['behaviors'][ROLE_BEHAVIORS::CUSTOM]);
     unset($moduleParams['behaviors'][ROLE_BEHAVIORS::HAPROXY]);
     //platforms list
     $platforms = self::loadController('Platforms')->getEnabledPlatforms();
     if (empty($platforms)) {
         throw new Exception('Before building new farm you need to configure environment and setup cloud credentials');
     }
     $moduleParams['categories'] = self::loadController('Roles')->listRoleCategories(true, true);
     $moduleParams['farmVpcEc2Enabled'] = $this->getEnvironment()->isPlatformEnabled(SERVER_PLATFORMS::EC2);
     if ($moduleParams['farmVpcEc2Enabled']) {
         $moduleParams['farmVpcEc2Locations'] = self::loadController('Platforms')->getCloudLocations(SERVER_PLATFORMS::EC2, false);
     }
     if ($farmId) {
         $this->request->checkPermissions(DBFarm::LoadByID($farmId)->__getNewFarmObject(), Acl::PERM_FARMS_UPDATE);
         $c = self::loadController('Builder', 'Scalr_UI_Controller_Farms');
         $moduleParams['farm'] = $c->getFarm2($farmId);
     } else {
         $this->request->restrictAccess(Acl::RESOURCE_OWN_FARMS, Acl::PERM_FARMS_CREATE);
         // TODO: remove hack, do better
         $vars = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->getEnvironmentId(), ScopeInterface::SCOPE_FARM);
         $moduleParams['farmVariables'] = $vars->getValues();
     }
     $moduleParams['tabs'] = array('vpcrouter', 'dbmsr', 'mongodb', 'mysql', 'scaling', 'network', 'cloudfoundry', 'rabbitmq', 'haproxy', 'proxy', 'scripting', 'ec2', 'openstack', 'gce', 'azure', 'security', 'devel', 'storage', 'variables', 'advanced', 'chef');
     //deprecated tabs
     if (\Scalr::config('scalr.ui.show_deprecated_features')) {
         $moduleParams['tabs'][] = 'ebs';
     }
     $conf = $this->getContainer()->config->get('scalr.load_statistics.connections.plotter');
     $moduleParams['tabParams'] = array('farmId' => $farmId, 'farmHash' => $moduleParams['farm'] ? $moduleParams['farm']['farm']['hash'] : '', 'accountId' => $this->environment->keychain(SERVER_PLATFORMS::EC2)->properties[Entity\CloudCredentialsProperty::AWS_ACCOUNT_ID], 'remoteAddress' => $this->request->getRemoteAddr(), 'monitoringHostUrl' => "{$conf['scheme']}://{$conf['host']}:{$conf['port']}", 'nginx' => array('server_section' => file_get_contents(APPPATH . '/templates/services/nginx/server_section.tpl'), 'server_section_ssl' => file_get_contents(APPPATH . '/templates/services/nginx/server_section_ssl.tpl')));
     $moduleParams['tabParams']['scalr.instances_connection_policy'] = \Scalr::config('scalr.instances_connection_policy');
     $moduleParams['tabParams']['scalr.scalarizr_update.default_repo'] = \Scalr::config('scalr.scalarizr_update.default_repo');
     if (Scalr::isHostedScalr()) {
         $moduleParams['tabParams']['scalr.scalarizr_update.repos'] = ['latest' => Utils::getScalarizrUpdateRepoTitle('latest')];
         if ($this->user->getAccount()->priority == 100) {
             $moduleParams['tabParams']['scalr.scalarizr_update.repos']['stable'] = Utils::getScalarizrUpdateRepoTitle('stable');
         }
     } else {
         $repos = array_keys(\Scalr::config('scalr.scalarizr_update.repos'));
         $moduleParams['tabParams']['scalr.scalarizr_update.repos'] = array_combine($repos, $repos);
     }
     $moduleParams['tabParams']['scalr.scalarizr_update.devel_repos'] = is_array(\Scalr::config('scalr.scalarizr_update.devel_repos')) ? array_keys(\Scalr::config('scalr.scalarizr_update.devel_repos')) : [];
     $moduleParams['tabParams']['scalr.aws.ec2.limits.security_groups_per_instance'] = \Scalr::config('scalr.aws.ec2.limits.security_groups_per_instance');
     $moduleParams['metrics'] = Entity\ScalingMetric::getList($this->getEnvironmentId());
     $moduleParams['timezones_list'] = Scalr_Util_DateTime::getTimezones();
     $moduleParams['timezone_default'] = $this->user->getSetting(Scalr_Account_User::SETTING_UI_TIMEZONE);
     if ($moduleParams['farm']['farm']['ownerEditable']) {
         $moduleParams['usersList'] = [];
         foreach (Entity\Account\User::findByAccountId($this->user->getAccountId()) as $user) {
             $moduleParams['usersList'][] = ['id' => $user->id, 'email' => $user->email];
         }
     }
     $defaultFarmRoleSecurityGroups = array('default');
     if (\Scalr::config('scalr.aws.security_group_name')) {
         $defaultFarmRoleSecurityGroups[] = \Scalr::config('scalr.aws.security_group_name');
     }
     $moduleParams['roleDefaultSettings'] = array('base.keep_scripting_logs_time' => \Scalr::config('scalr.system.scripting.default_instance_log_rotation_period'), 'security_groups.list' => json_encode($defaultFarmRoleSecurityGroups), 'base.abort_init_on_script_fail' => \Scalr::config('scalr.system.scripting.default_abort_init_on_script_fail') ? 1 : 0, 'base.disable_firewall_management' => \Scalr::config('scalr.system.default_disable_firewall_management') ? 1 : 0);
     //cost analytics
     if ($this->getContainer()->analytics->enabled && $this->getEnvironment()->getPlatformConfigValue(Scalr_Environment::SETTING_CC_ID)) {
         $farmCostData = $this->getFarmCostData($farmId);
         $moduleParams['analytics'] = $farmCostData['analytics'];
         if ($farmId) {
             $moduleParams['farm']['farm']['projectId'] = $farmCostData['projectId'];
             $moduleParams['analytics']['farmCostMetering'] = $farmCostData['farmCostMetering'];
         }
     }
     $moduleParams['farmLaunchPermission'] = $farmId ? $moduleParams['farm']['farm']['launchPermission'] : $this->request->isAllowed([Acl::RESOURCE_FARMS, Acl::RESOURCE_TEAM_FARMS, Acl::RESOURCE_OWN_FARMS], Acl::PERM_FARMS_LAUNCH_TERMINATE);
     $this->response->data($moduleParams);
 }
Esempio n. 16
0
 public function viewAction()
 {
     $vars = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), 0, Scalr_Scripting_GlobalVariables::SCOPE_ACCOUNT);
     $this->response->page('ui/account2/variables/view.js', array('variables' => json_encode($vars->getValues())), array('ui/core/variablefield.js'));
 }
Esempio n. 17
0
 public function getFarm2($farmId)
 {
     $dbFarm = DBFarm::LoadByID($farmId);
     $this->user->getPermissions()->validate($dbFarm);
     $farmRoles = array();
     $variables = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_FARM);
     $farmRoleVariables = new Scalr_Scripting_GlobalVariables($this->user->getAccountId(), $this->getEnvironmentId(), Scalr_Scripting_GlobalVariables::SCOPE_FARMROLE);
     foreach ($dbFarm->GetFarmRoles() as $dbFarmRole) {
         $scripts = $this->db->GetAll("\n                SELECT farm_role_scripts.*, scripts.name, scripts.os\n                FROM farm_role_scripts\n                LEFT JOIN scripts ON scripts.id = farm_role_scripts.scriptid\n                WHERE farm_roleid=? AND issystem='1'\n            ", array($dbFarmRole->ID));
         $scriptsObject = array();
         foreach ($scripts as $script) {
             if (!empty($script['scriptid']) && $script['script_type'] == Scalr_Scripting_Manager::ORCHESTRATION_SCRIPT_TYPE_SCALR || !empty($script['script_path']) && $script['script_type'] == Scalr_Scripting_Manager::ORCHESTRATION_SCRIPT_TYPE_LOCAL || !empty($script['params']) && $script['script_type'] == Scalr_Scripting_Manager::ORCHESTRATION_SCRIPT_TYPE_CHEF) {
                 $s = array('script_type' => $script['script_type'], 'script_id' => (int) $script['scriptid'], 'script' => $script['name'], 'os' => $script['os'], 'params' => unserialize($script['params']), 'target' => $script['target'], 'version' => (int) $script['version'], 'timeout' => $script['timeout'], 'isSync' => (int) $script['issync'], 'order_index' => $script['order_index'], 'event' => $script['event_name'], 'script_path' => $script['script_path'], 'run_as' => $script['run_as']);
                 if ($script['target'] == Script::TARGET_BEHAVIORS || $script['target'] == Script::TARGET_ROLES || $script['target'] == Script::TARGET_FARMROLES) {
                     switch ($script['target']) {
                         case $script['target'] == Script::TARGET_ROLES:
                             $varName = 'target_roles';
                             break;
                         case $script['target'] == Script::TARGET_FARMROLES:
                             $varName = 'target_farmroles';
                             break;
                         case $script['target'] == Script::TARGET_BEHAVIORS:
                             $varName = 'target_behaviors';
                             break;
                     }
                     $s[$varName] = array();
                     $r = $this->db->GetAll("SELECT `target` FROM farm_role_scripting_targets WHERE farm_role_script_id = ?", array($script['id']));
                     foreach ($r as $v) {
                         array_push($s[$varName], $v['target']);
                     }
                 }
                 $scriptsObject[] = $s;
             }
         }
         //Scripting params
         $scriptingParams = $this->db->Execute("\n                SELECT * FROM farm_role_scripting_params\n                WHERE farm_role_id = ? AND farm_role_script_id = '0'\n            ", array($dbFarmRole->ID));
         $sParams = array();
         while ($p = $scriptingParams->FetchRow()) {
             $sParams[] = array('hash' => $p['hash'], 'role_script_id' => $p['role_script_id'], 'params' => unserialize($p['params']));
         }
         $scalingManager = new Scalr_Scaling_Manager($dbFarmRole);
         $scaling = array();
         foreach ($scalingManager->getFarmRoleMetrics() as $farmRoleMetric) {
             $scaling[$farmRoleMetric->metricId] = $farmRoleMetric->getSettings();
         }
         $dbPresets = $this->db->GetAll("SELECT * FROM farm_role_service_config_presets WHERE farm_roleid=?", array($dbFarmRole->ID));
         $presets = array();
         foreach ($dbPresets as $preset) {
             $presets[$preset['behavior']] = $preset['preset_id'];
         }
         if ($dbFarmRole->NewRoleID) {
             $roleName = DBRole::loadById($dbFarmRole->NewRoleID)->name;
             $isBundling = true;
         } else {
             $roleName = $dbFarmRole->GetRoleObject()->name;
             $isBundling = false;
         }
         $storages = array('configs' => $dbFarmRole->getStorage()->getConfigs());
         foreach ($dbFarmRole->getStorage()->getVolumes() as $configKey => $config) {
             $storages['devices'][$configKey] = array();
             foreach ($config as $device) {
                 $info = array('farmRoleId' => $device->farmRoleId, 'placement' => $device->placement, 'serverIndex' => $device->serverIndex, 'storageId' => $device->storageId, 'storageConfigId' => $device->storageConfigId, 'status' => $device->status);
                 try {
                     $server = DBServer::LoadByFarmRoleIDAndIndex($device->farmRoleId, $device->serverIndex);
                     if ($server->status != SERVER_STATUS::TERMINATED && $server->status != SERVER_STATUS::TROUBLESHOOTING) {
                         $info['serverId'] = $server->serverId;
                         $info['serverInstanceId'] = $server->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID);
                     }
                 } catch (Exception $e) {
                     $this->response->debugException($e);
                 }
                 $storages['devices'][$configKey][] = $info;
             }
         }
         $image = $dbFarmRole->GetRoleObject()->__getNewRoleObject()->getImage($dbFarmRole->Platform, $dbFarmRole->CloudLocation);
         $securityGroups = $this->getInitialSecurityGroupsList($dbFarmRole);
         $farmRoles[] = array('farm_role_id' => $dbFarmRole->ID, 'alias' => $dbFarmRole->Alias ? $dbFarmRole->Alias : $dbFarmRole->GetRoleObject()->name, 'role_id' => $dbFarmRole->RoleID, 'platform' => $dbFarmRole->Platform, 'os' => $dbFarmRole->GetRoleObject()->getOs()->name, 'os_family' => $dbFarmRole->GetRoleObject()->getOs()->family, 'os_generation' => $dbFarmRole->GetRoleObject()->getOs()->generation, 'os_version' => $dbFarmRole->GetRoleObject()->getOs()->version, 'osId' => $dbFarmRole->GetRoleObject()->getOs()->id, 'generation' => $dbFarmRole->GetRoleObject()->generation, 'group' => $dbFarmRole->GetRoleObject()->getCategoryName(), 'cat_id' => $dbFarmRole->GetRoleObject()->catId, 'name' => $roleName, 'is_bundle_running' => $isBundling, 'behaviors' => implode(",", $dbFarmRole->GetRoleObject()->getBehaviors()), 'scripting' => $scriptsObject, 'scripting_params' => $sParams, 'settings' => $dbFarmRole->GetAllSettings(), 'cloud_location' => $dbFarmRole->CloudLocation, 'launch_index' => (int) $dbFarmRole->LaunchIndex, 'scaling' => $scaling, 'config_presets' => $presets, 'image' => $image->getImage(), 'storages' => $storages, 'variables' => $farmRoleVariables->getValues($dbFarmRole->GetRoleID(), $dbFarm->ID, $dbFarmRole->ID), 'running_servers' => $dbFarmRole->GetRunningInstancesCount(), 'suspended_servers' => $dbFarmRole->GetSuspendedInstancesCount(), 'security_groups' => $securityGroups, 'hourly_rate' => $this->getInstanceTypeHourlyRate($dbFarmRole->Platform, $dbFarmRole->CloudLocation, $dbFarmRole->getInstanceType(), $dbFarmRole->GetRoleObject()->osFamily));
     }
     $vpc = array();
     if ($dbFarm->GetSetting(DBFarm::SETTING_EC2_VPC_ID)) {
         $vpc = array('id' => $dbFarm->GetSetting(DBFarm::SETTING_EC2_VPC_ID), 'region' => $dbFarm->GetSetting(DBFarm::SETTING_EC2_VPC_REGION));
     }
     $farmOwnerEditable = $dbFarm->createdByUserId == $this->user->getId() || $this->user->isAccountOwner() || $this->request->isFarmAllowed($dbFarm, Acl::PERM_FARMS_CHANGE_OWNERSHIP);
     return array('farm' => array('name' => $dbFarm->Name, 'description' => $dbFarm->Comments, 'rolesLaunchOrder' => $dbFarm->RolesLaunchOrder, 'timezone' => $dbFarm->GetSetting(DBFarm::SETTING_TIMEZONE), 'variables' => $variables->getValues(0, $dbFarm->ID), 'vpc' => $vpc, 'status' => $dbFarm->Status, 'hash' => $dbFarm->Hash, 'owner' => $farmOwnerEditable ? $dbFarm->createdByUserId : $dbFarm->createdByUserEmail, 'ownerEditable' => $farmOwnerEditable, 'teamOwner' => $farmOwnerEditable ? $dbFarm->teamId : ($dbFarm->teamId ? (new Scalr_Account_Team())->loadById($dbFarm->teamId)->name : ''), 'teamOwnerEditable' => $farmOwnerEditable, 'launchPermission' => $this->request->isFarmAllowed($dbFarm, Acl::PERM_FARMS_LAUNCH_TERMINATE), DBFarm::SETTING_SZR_UPD_REPOSITORY => $dbFarm->GetSetting(DBFarm::SETTING_SZR_UPD_REPOSITORY), DBFarm::SETTING_SZR_UPD_SCHEDULE => $dbFarm->GetSetting(DBFarm::SETTING_SZR_UPD_SCHEDULE)), 'roles' => $farmRoles, 'lock' => $dbFarm->isLocked(false), 'changed' => $dbFarm->changedTime);
 }
Esempio n. 18
0
 /**
  * Gets a specific global variable data
  *
  * @param   int                                 $farmId     Numeric identifier of the Farm
  * @param   string                              $name       Variable name
  * @param   \Scalr_Scripting_GlobalVariables    $globalVar  Instance of Global variable handler
  *
  * @return  mixed
  * @throws  ApiErrorException
  */
 private function getGlobalVariable($farmId, $name, \Scalr_Scripting_GlobalVariables $globalVar)
 {
     $list = $globalVar->getValues(0, $farmId);
     $fetch = [];
     foreach ($list as $var) {
         if (!empty($var['current']['name']) && $var['current']['name'] == $name || !empty($var['default']['name']) && $var['default']['name'] == $name) {
             $fetch = $var;
             break;
         }
     }
     return $fetch;
 }
Esempio n. 19
0
 public function variablesAction()
 {
     $this->request->restrictAccess(Acl::RESOURCE_GENERAL_GLOBAL_VARIABLES);
     $vars = new Scalr_Scripting_GlobalVariables($this->getEnvironmentId());
     $this->response->page('ui/core/variables.js', array('variables' => json_encode($vars->getValues())), array('ui/core/variablefield.js'), array('ui/core/variablefield.css'));
 }