public function GetScriptingVars()
{
$dbFarmRole = $this->GetFarmRoleObject();
$roleId = $dbFarmRole->RoleID;
$dbRole = DBRole::loadById($roleId);
$isDbMsr = $dbRole->getDbMsrBehavior();
if ($isDbMsr) {
$isMaster = $this->GetProperty(Scalr_Db_Msr::REPLICATION_MASTER);
} else {
$isMaster = $this->GetProperty(\SERVER_PROPERTIES::DB_MYSQL_MASTER);
}
$at = new Entity\Account\Team();
$ft = new Entity\FarmTeam();
$teams = join(",", Entity\Account\Team::find([\Scalr\Model\AbstractEntity::STMT_FROM => "{$at->table()} JOIN {$ft->table()} ON {$ft->columnTeamId} = {$at->columnId}", \Scalr\Model\AbstractEntity::STMT_WHERE => "{$ft->columnFarmId} = '{$this->farmId}'"])->map(function ($t) {
return $t->name;
}));
$retval = array('image_id' => $dbRole->__getNewRoleObject()->getImage($this->platform, $dbFarmRole->CloudLocation)->imageId, 'external_ip' => $this->remoteIp, 'internal_ip' => $this->localIp, 'role_name' => $dbRole->name, 'isdbmaster' => $isMaster, 'instance_index' => $this->index, 'instance_farm_index' => $this->farmIndex, 'server_type' => $this->type, 'server_hostname' => $this->GetProperty(Scalr_Role_Behavior::SERVER_BASE_HOSTNAME), 'server_id' => $this->serverId, 'farm_id' => $this->farmId, 'farm_role_id' => $this->farmRoleId, 'farm_role_alias' => $this->GetFarmRoleObject()->Alias, 'farm_name' => $this->GetFarmObject()->Name, 'farm_hash' => $this->GetFarmObject()->Hash, 'farm_owner_email' => $this->GetFarmObject()->createdByUserEmail, 'farm_team' => $teams, 'behaviors' => implode(",", $dbRole->getBehaviors()), 'env_id' => $this->GetEnvironmentObject()->id, 'env_name' => $this->GetEnvironmentObject()->name, 'cloud_location' => $this->GetCloudLocation(), 'cloud_server_id' => $this->GetCloudServerID());
if ($this->cloudLocationZone) {
$retval['cloud_location_zone'] = $this->cloudLocationZone;
}
if ($this->platform == SERVER_PLATFORMS::EC2) {
$retval['instance_id'] = $this->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID);
$retval['ami_id'] = $this->GetProperty(EC2_SERVER_PROPERTIES::AMIID);
$retval['region'] = $this->GetProperty(EC2_SERVER_PROPERTIES::REGION);
$retval['avail_zone'] = $this->GetProperty(EC2_SERVER_PROPERTIES::AVAIL_ZONE);
if ($dbFarmRole->GetSetting(Entity\FarmRoleSetting::AWS_ELB_ENABLED)) {
$elbId = $dbFarmRole->GetSetting(Entity\FarmRoleSetting::AWS_ELB_ID);
$retval['aws_elb_name'] = $elbId;
}
}
if (\Scalr::getContainer()->analytics->enabled) {
$ccId = $this->GetProperty(\SERVER_PROPERTIES::ENV_CC_ID);
if ($ccId) {
$cc = CostCentreEntity::findPk($ccId);
if ($cc) {
/* @var $cc CostCentreEntity */
$retval['cost_center_id'] = $ccId;
$retval['cost_center_bc'] = $cc->getProperty(CostCentrePropertyEntity::NAME_BILLING_CODE);
$retval['cost_center_name'] = $cc->name;
} else {
throw new Exception("Cost center {$ccId} not found");
}
}
$projectId = $this->GetProperty(\SERVER_PROPERTIES::FARM_PROJECT_ID);
if ($projectId) {
$project = ProjectEntity::findPk($projectId);
/* @var $project ProjectEntity */
$retval['project_id'] = $projectId;
$retval['project_bc'] = $project->getProperty(ProjectPropertyEntity::NAME_BILLING_CODE);
$retval['project_name'] = $project->name;
}
}
return $retval;
}