public function getContent($params = array()) { try { $dbFarm = DBFarm::LoadByID($params['farmId']); $this->user->getPermissions()->validate($dbFarm); $farmRoles = array(); foreach ($dbFarm->GetFarmRoles() as $dbFarmRole) { $servCount = $this->db->GetOne("SELECT COUNT(*) FROM servers WHERE farm_roleid = ? AND status IN ('Pending', 'Initializing', 'Running', 'Temporary')", array($dbFarmRole->ID)); if ($servCount) { $farmRoles[] = array('farmId' => $params['farmId'], 'roleId' => $this->db->GetOne("SELECT role_id FROM farm_roles WHERE id=? AND farmid=?", array($dbFarmRole->ID, $params['farmId'])), 'farmRoleId' => $dbFarmRole->ID, 'group' => ROLE_GROUPS::GetConstByBehavior($dbFarmRole->GetRoleObject()->getBehaviors()), 'behaviors' => implode(",", $dbFarmRole->GetRoleObject()->getBehaviors()), 'servCount' => $servCount); } } return array('servers' => $farmRoles, 'name' => $dbFarm->Name); } catch (Exception $e) { return ''; } }
public function xGetRolesAction() { $roles = array(); $platforms = $this->getEnvironment()->getEnabledPlatforms(); $rolesSql = "SELECT id FROM roles WHERE (env_id = 0 OR env_id=?) AND id IN (SELECT role_id FROM role_images WHERE platform IN ('" . implode("','", array_keys($platforms)) . "'))"; $dbroles = $this->db->Execute($rolesSql, array($this->getEnvironmentId())); while ($role = $dbroles->FetchRow()) { if ($this->db->GetOne("SELECT id FROM roles_queue WHERE role_id=?", array($role['id']))) { continue; } $dbRole = DBRole::loadById($role['id']); $rolePlatforms = $dbRole->getPlatforms(); $roleLocations = array(); foreach ($rolePlatforms as $platform) { $roleLocations[$platform] = $dbRole->getCloudLocations($platform); } $roles[] = array('role_id' => $dbRole->id, 'arch' => $dbRole->architecture, 'group' => ROLE_GROUPS::GetConstByBehavior($dbRole->getBehaviors()), 'name' => $dbRole->name, 'generation' => $dbRole->generation, 'behaviors' => implode(",", $dbRole->getBehaviors()), 'origin' => $dbRole->origin, 'isstable' => (bool) $dbRole->isStable, 'platforms' => implode(",", $rolePlatforms), 'locations' => $roleLocations, 'os' => $dbRole->os == 'Unknown' ? 'Unknown OS' : $dbRole->os, 'tags' => $dbRole->getTags()); } $this->response->success(); $this->response->data(array('roles' => $roles)); }
public function FarmGetDetails($FarmID) { $response = $this->CreateInitialResponse(); try { $DBFarm = DBFarm::LoadByID($FarmID); if ($DBFarm->EnvID != $this->Environment->id) { throw new Exception("N"); } } catch (Exception $e) { throw new Exception(sprintf("Farm #%s not found", $FarmID)); } $response->FarmRoleSet = new stdClass(); $response->FarmRoleSet->Item = array(); foreach ($DBFarm->GetFarmRoles() as $DBFarmRole) { $itm = new stdClass(); $itm->{"ID"} = $DBFarmRole->ID; $itm->{"RoleID"} = $DBFarmRole->RoleID; $itm->{"Name"} = $DBFarmRole->GetRoleObject()->name; $itm->{"Platform"} = $DBFarmRole->Platform; $itm->{"Category"} = ROLE_GROUPS::GetNameByBehavior($DBFarmRole->GetRoleObject()->getBehaviors()); $itm->{"ScalingProperties"} = new stdClass(); $itm->{"ScalingProperties"}->{"MinInstances"} = $DBFarmRole->GetSetting(DBFarmRole::SETTING_SCALING_MIN_INSTANCES); $itm->{"ScalingProperties"}->{"MaxInstances"} = $DBFarmRole->GetSetting(DBFarmRole::SETTING_SCALING_MAX_INSTANCES); //TODO: if ($DBFarmRole->Platform == SERVER_PLATFORMS::EC2) { $itm->{"PlatformProperties"} = new stdClass(); $itm->{"PlatformProperties"}->{"InstanceType"} = $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_INSTANCE_TYPE); $itm->{"PlatformProperties"}->{"AvailabilityZone"} = $DBFarmRole->GetSetting(DBFarmRole::SETTING_AWS_AVAIL_ZONE); } elseif ($DBFarmRole->Platform == SERVER_PLATFORMS::RDS) { $itm->{"PlatformProperties"} = new stdClass(); $itm->{"PlatformProperties"}->{"InstanceClass"} = $DBFarmRole->GetSetting(DBFarmRole::SETTING_RDS_INSTANCE_CLASS); $itm->{"PlatformProperties"}->{"AvailabilityZone"} = $DBFarmRole->GetSetting(DBFarmRole::SETTING_RDS_AVAIL_ZONE); $itm->{"PlatformProperties"}->{"InstanceEngine"} = $DBFarmRole->GetSetting(DBFarmRole::SETTING_RDS_INSTANCE_ENGINE); } $itm->{"ServerSet"} = new stdClass(); $itm->{"ServerSet"}->Item = array(); foreach ($DBFarmRole->GetServersByFilter() as $DBServer) { $iitm = new stdClass(); $iitm->{"ServerID"} = $DBServer->serverId; $iitm->{"ExternalIP"} = $DBServer->remoteIp; $iitm->{"InternalIP"} = $DBServer->localIp; $iitm->{"Status"} = $DBServer->status; $iitm->{"ScalarizrVersion"} = $DBServer->GetProperty(SERVER_PROPERTIES::SZR_VESION); $iitm->{"Uptime"} = round((time() - strtotime($DBServer->dateAdded)) / 60, 2); //seconds -> minutes $iitm->{"IsDbMaster"} = $DBServer->GetProperty(SERVER_PROPERTIES::DB_MYSQL_MASTER) == 1 || $DBServer->GetProperty(Scalr_Db_Msr::REPLICATION_MASTER) == 1 ? '1' : '0'; if ($DBFarmRole->Platform == SERVER_PLATFORMS::EC2) { $iitm->{"PlatformProperties"} = new stdClass(); $iitm->{"PlatformProperties"}->{"InstanceType"} = $DBServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_TYPE); $iitm->{"PlatformProperties"}->{"AvailabilityZone"} = $DBServer->GetProperty(EC2_SERVER_PROPERTIES::AVAIL_ZONE); $iitm->{"PlatformProperties"}->{"AMIID"} = $DBServer->GetProperty(EC2_SERVER_PROPERTIES::AMIID); $iitm->{"PlatformProperties"}->{"InstanceID"} = $DBServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID); } elseif ($DBFarmRole->Platform == SERVER_PLATFORMS::RDS) { $iitm->{"PlatformProperties"} = new stdClass(); $iitm->{"PlatformProperties"}->{"InstanceClass"} = $DBServer->GetProperty(RDS_SERVER_PROPERTIES::INSTANCE_CLASS); $iitm->{"PlatformProperties"}->{"AvailabilityZone"} = $DBServer->GetProperty(RDS_SERVER_PROPERTIES::AVAIL_ZONE); $iitm->{"PlatformProperties"}->{"InstanceEngine"} = $DBServer->GetProperty(RDS_SERVER_PROPERTIES::INSTANCE_ENGINE); $iitm->{"PlatformProperties"}->{"InstanceID"} = $DBServer->GetProperty(RDS_SERVER_PROPERTIES::INSTANCE_ID); } $itm->{"ServerSet"}->Item[] = $iitm; } $response->FarmRoleSet->Item[] = $itm; } return $response; }
/** * Get information about role */ public function infoAction() { $this->request->defineParams(array('roleId' => array('type' => 'int'))); $roleId = $this->getParam('roleId'); $dbRole = DBRole::loadById($roleId); if ($dbRole->envId != 0) { $this->user->getPermissions()->validate($dbRole); } $dbRole->groupName = ROLE_GROUPS::GetNameByBehavior($dbRole->getBehaviors()); $dbRole->behaviorsList = implode(", ", $dbRole->getBehaviors()); foreach ($dbRole->getSoftwareList() as $soft) { $dbRole->softwareList[] = "{$soft['name']} {$soft['version']}"; } $dbRole->softwareList = implode(", ", $dbRole->softwareList); $dbRole->tagsString = implode(", ", $dbRole->getTags()); $dbRole->platformsList = array(); foreach ($dbRole->getPlatforms() as $platform) { $dbRole->platformsList[] = array('name' => SERVER_PLATFORMS::GetName($platform), 'locations' => implode(", ", $dbRole->getCloudLocations($platform))); } $this->response->page('ui/roles/info.js', array('name' => $dbRole->name, 'info' => get_object_vars($dbRole))); }
public function buildAction() { $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, 'currentTimeZone' => $this->getEnvironment()->getPlatformConfigValue(Scalr_Environment::SETTING_TIMEZONE), 'currentTime' => Scalr_Util_DateTime::convertTz(time()), 'currentEnvId' => $this->getEnvironmentId(), 'groups' => ROLE_GROUPS::GetName(null, true)); $platforms = $this->getEnvironment()->getEnabledPlatforms(); if (empty($platforms)) { throw new Exception('Before building new farm you need to configure environment and setup cloud credentials'); } if ($farmId) { $c = self::loadController('Builder', 'Scalr_UI_Controller_Farms'); $moduleParams['farm'] = $c->getFarm($farmId); } $moduleParams['tabs'] = array('scaling', 'mysql', 'dbmsr', 'cloudfoundry', 'rabbitmq', 'mongodb', 'haproxy', 'balancing', 'placement', 'openstack', 'cloudstack', 'rsplacement', 'params', 'rds', 'eips', 'ebs', 'ebs2', 'dns', 'scripting', 'timeouts', 'cloudwatch', 'euca', 'nimbula', 'ec2', 'servicesconfig', 'deployments', 'devel'); if ($this->user->getAccount()->isFeatureEnabled(Scalr_Limits::FEATURE_CHEF)) { $moduleParams['tabs'][] = 'chef'; } $moduleParams['tabParams'] = array('farmId' => $farmId, 'currentTimeZone' => $this->getEnvironment()->getPlatformConfigValue(Scalr_Environment::SETTING_TIMEZONE), 'currentTime' => Scalr_Util_DateTime::convertTz(time()), 'currentEnvId' => $this->getEnvironmentId()); $this->response->page('ui/farms/builder.js', $moduleParams, array('ui/farms/builder/selroles.js', 'ui/farms/builder/roleedit.js', 'ui/farms/builder/allroles.js', 'ui/farms/builder/tab.js', 'ui/farms/builder/tabs/balancing.js', 'ui/farms/builder/tabs/cloudwatch.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/dns.js', 'ui/farms/builder/tabs/ebs.js', 'ui/farms/builder/tabs/ebs2.js', 'ui/farms/builder/tabs/eips.js', 'ui/farms/builder/tabs/euca.js', 'ui/farms/builder/tabs/mysql.js', 'ui/farms/builder/tabs/nimbula.js', 'ui/farms/builder/tabs/params.js', 'ui/farms/builder/tabs/placement.js', 'ui/farms/builder/tabs/rsplacement.js', 'ui/farms/builder/tabs/cloudstack.js', 'ui/farms/builder/tabs/openstack.js', 'ui/farms/builder/tabs/rds.js', 'ui/farms/builder/tabs/scaling.js', 'ui/farms/builder/tabs/scripting.js', 'ui/farms/builder/tabs/servicesconfig.js', 'ui/farms/builder/tabs/timeouts.js', 'ui/farms/builder/tabs/vpc.js', 'ui/farms/builder/tabs/ec2.js', 'ui/farms/builder/tabs/chef.js', 'ui/farms/builder/tabs/deployments.js', 'ui/farms/builder/tabs/devel.js', 'ui/scripts/scriptfield.js'), array('ui/farms/builder/tabs/scripting.css', 'ui/farms/builder/selroles.css', 'ui/farms/builder/allroles.css')); }