本文整理汇总了PHP中Scalr::GenerateUID方法的典型用法代码示例。如果您正苦于以下问题:PHP Scalr::GenerateUID方法的具体用法?PHP Scalr::GenerateUID怎么用?PHP Scalr::GenerateUID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scalr
的用法示例。
在下文中一共展示了Scalr::GenerateUID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* {@inheritdoc}
* @see Scalr_Model::save()
*/
public function save($forceInsert = false)
{
if (!$this->id) {
$forceInsert = true;
$this->id = Scalr::GenerateUID(true);
}
parent::save($forceInsert);
}
示例2: run1
protected function run1($stage)
{
$envIds = $this->db->Execute("SELECT `id` FROM `client_environments`");
$platformVariables = static::getCloudsCredentialProperties();
foreach ($envIds as $row) {
$environment = \Scalr_Environment::init()->loadById($row['id']);
$platforms = [];
foreach (array_keys(SERVER_PLATFORMS::getList()) as $platform) {
if ($environment->getPlatformConfigValue($platform . '.is_enabled', false)) {
$platforms[] = $platform;
}
}
foreach ($platforms as $platform) {
try {
switch ($platform) {
case SERVER_PLATFORMS::RACKSPACE:
foreach (['rs-ORD1', 'rs-LONx'] as $location) {
$cloudCredentials = new Entity\CloudCredentials();
$cloudCredentials->accountId = $environment->getAccountId();
$cloudCredentials->envId = $environment->id;
$cloudCredentials->cloud = "{$location}.{$platform}";
$cloudCredentials->name = "{$environment->id}-{$environment->getAccountId()}-{$cloudCredentials->cloud}-" . \Scalr::GenerateUID(true);
foreach ($platformVariables[$platform] as $name => $newName) {
$value = $environment->getPlatformConfigValue($name, true, $location);
if ($value === null) {
$value = false;
}
$cloudCredentials->properties[$newName] = $value;
}
$cloudCredentials->save();
$cloudCredentials->bindToEnvironment($environment);
}
break;
default:
$cloudCredentials = new Entity\CloudCredentials();
$cloudCredentials->accountId = $environment->getAccountId();
$cloudCredentials->envId = $environment->id;
$cloudCredentials->cloud = $platform;
$cloudCredentials->name = "{$environment->id}-{$environment->getAccountId()}-{$platform}-" . \Scalr::GenerateUID(true);
$cloudCredentials->status = Entity\CloudCredentials::STATUS_ENABLED;
foreach ($platformVariables[$platform] as $name => $newName) {
$value = $environment->getPlatformConfigValue($name);
if ($value === null) {
$value = false;
}
$cloudCredentials->properties[$newName] = $value;
}
$cloudCredentials->save();
$cloudCredentials->bindToEnvironment($environment);
break;
}
} catch (Exception $e) {
$this->console->error(get_class($e) . " in {$e->getFile()} on line {$e->getLine()}: " . $e->getMessage());
error_log(get_class($e) . " in {$e->getFile()} at line {$e->getLine()}: {$e->getMessage()}\n{$e->getTraceAsString()}");
}
}
}
}
示例3: strtolower
$options->uuid = strtolower(str_replace('-', '', $opt['r']));
}
$options->verbosity = isset($opt['v']);
$options->interactive = isset($opt['i']);
if (isset($opt['help']) || isset($opt['h'])) {
$showusage();
}
if (isset($opt['n']) || isset($opt['new'])) {
$template = UpgradeHandler::getPathToUpdates() . '/Template.php';
if (!is_readable($template)) {
$console->error('Could not open template file for reading ' . $template);
exit;
}
$released = gmdate('YmdHis');
$pathname = UpgradeHandler::getPathToUpdates() . '/Update' . $released . '.php';
$tpl = PhpTemplate::load($template, array('upd_released' => $released, 'upd_uuid' => \Scalr::GenerateUID()));
if ($console->confirm("Are you sure you want to create a new upgrade class?")) {
if (file_put_contents($pathname, $tpl) === false) {
$console->error('Could not write to file "%s"', $pathname);
exit;
}
$console->success('Upgrade class "%s" has been successfully created.', realpath($pathname));
}
exit;
}
if (isset($opt['force'])) {
UpgradeHandler::removePid();
}
$upgrade = new UpgradeHandler($options);
if (!$upgrade->run()) {
exit(1);
示例4: __construct
public function __construct()
{
$this->messageId = Scalr::GenerateUID();
$this->meta[Scalr_Messaging_MsgMeta::SCALR_VERSION] = SCALR_VERSION;
}
示例5: prepareScript
public static function prepareScript($scriptSettings, DBServer $targetServer, AbstractServerEvent $event = null)
{
$template = ['type' => isset($scriptSettings['type']) ? $scriptSettings['type'] : null, 'timeout' => isset($scriptSettings['timeout']) ? $scriptSettings['timeout'] : null, 'issync' => isset($scriptSettings['issync']) ? $scriptSettings['issync'] : null, 'run_as' => isset($scriptSettings['run_as']) ? $scriptSettings['run_as'] : null, 'execution_id' => Scalr::GenerateUID()];
if ($scriptSettings['type'] == self::ORCHESTRATION_SCRIPT_TYPE_SCALR) {
/* @var $script Script */
$script = Script::findPk($scriptSettings['scriptid']);
if (!$script) {
return false;
}
// TODO: validate permission to access script ?
if ($script->os && $targetServer->osType && $script->os != $targetServer->osType) {
return false;
}
if ($scriptSettings['version'] == 'latest' || (int) $scriptSettings['version'] == -1) {
$version = $script->getLatestVersion();
} else {
$version = $script->getVersion((int) $scriptSettings['version']);
}
if (empty($version)) {
return false;
}
$template['name'] = $script->name;
$template['id'] = $script->id;
$template['body'] = $version->content;
$template['scriptVersion'] = $version->version;
// variables could be null
$scriptParams = $script->allowScriptParameters ? (array) $version->variables : [];
foreach ($scriptParams as &$val) {
$val = "";
}
$params = array_merge($scriptParams, $targetServer->GetScriptingVars(), (array) unserialize($scriptSettings['params']));
if ($event) {
$eventServer = $event->DBServer;
foreach ($eventServer->GetScriptingVars() as $k => $v) {
$params["event_{$k}"] = $v;
}
foreach ($event->GetScriptingVars() as $k => $v) {
$params[$k] = $event->{$v};
}
if (isset($event->params) && is_array($event->params)) {
foreach ($event->params as $k => $v) {
$params[$k] = $v;
}
}
$params['event_name'] = $event->GetName();
}
if ($event instanceof CustomEvent && count($event->params) > 0) {
$params = array_merge($params, $event->params);
}
// Prepare keys array and array with values for replacement in script
$keys = array_keys($params);
$keys = array_map(function ($item) {
return '%' . $item . '%';
}, $keys);
$values = array_values($params);
$script_contents = str_replace($keys, $values, $template['body']);
$template['body'] = str_replace('\\%', "%", $script_contents);
// Generate script contents
$template['name'] = preg_replace("/[^A-Za-z0-9]+/", "_", $template['name']);
} elseif ($scriptSettings['type'] == self::ORCHESTRATION_SCRIPT_TYPE_LOCAL) {
$template['path'] = $targetServer->applyGlobalVarsToValue($scriptSettings['script_path']);
} elseif ($scriptSettings['type'] == self::ORCHESTRATION_SCRIPT_TYPE_CHEF) {
$chef = new stdClass();
$chefSettings = (array) unserialize($scriptSettings['params']);
if ($chefSettings['chef.cookbook_url']) {
$chef->cookbookUrl = $chefSettings['chef.cookbook_url'];
}
if ($chefSettings['chef.cookbook_url_type']) {
$chef->cookbookUrlType = $chefSettings['chef.cookbook_url_type'];
}
if ($chefSettings['chef.relative_path']) {
$chef->relativePath = $chefSettings['chef.relative_path'];
}
if ($chefSettings['chef.ssh_private_key']) {
$chef->sshPrivateKey = $chefSettings['chef.ssh_private_key'];
}
if ($chefSettings['chef.role_name']) {
$chef->role = $chefSettings['chef.role_name'];
} else {
$chef->runList = $chefSettings['chef.runlist'];
}
$chef->jsonAttributes = $chefSettings['chef.attributes'];
$template['chef'] = $chef;
}
return $template;
}
示例6: Create
/**
*
* @param ServerCreateInfo $serverCreateInfo
* @param bool $isImport
* @return DBServer
*/
public static function Create(ServerCreateInfo $creInfo, $isImport = false, $setPendingStatus = false)
{
$db = \Scalr::getDb();
$startWithLetter = in_array($creInfo->platform, array(SERVER_PLATFORMS::CLOUDSTACK, SERVER_PLATFORMS::UCLOUD, SERVER_PLATFORMS::IDCF, SERVER_PLATFORMS::GCE));
if ($isImport) {
$startWithLetter = true;
}
$server_id = Scalr::GenerateUID(false, $startWithLetter);
$status = !$isImport ? SERVER_STATUS::PENDING_LAUNCH : SERVER_STATUS::IMPORTING;
if ($setPendingStatus) {
$status = SERVER_STATUS::PENDING;
}
// IF no index defined
if (!$creInfo->index && !$isImport) {
$indexes = $db->GetAll("SELECT `index` FROM servers WHERE farm_roleid=? AND status NOT IN (?,?,?)", array($creInfo->dbFarmRole->ID, SERVER_STATUS::TERMINATED, SERVER_STATUS::PENDING_TERMINATE, SERVER_STATUS::TROUBLESHOOTING));
$used_indexes = array();
if (count($indexes) > 0) {
foreach ($indexes as $index) {
$used_indexes[$index['index']] = true;
}
}
for ($i = 1;; $i++) {
if (!$used_indexes[$i]) {
$creInfo->index = $i;
break;
}
}
} elseif ($isImport) {
$creInfo->index = 0;
}
$client_id = $creInfo->clientId ? $creInfo->clientId : $creInfo->dbFarmRole->GetFarmObject()->ClientID;
$db->Execute("INSERT INTO servers SET\n `server_id`\t\t= ?,\n `farm_id`\t\t= ?,\n `role_id`\t\t= ?,\n `env_id`\t\t= ?,\n `farm_roleid`\t= ?,\n `client_id`\t\t= ?,\n `platform`\t\t= ?,\n `status`\t\t= ?,\n `remote_ip`\t\t= ?,\n `local_ip`\t\t= ?,\n `dtadded`\t\t= NOW(),\n `index`\t\t\t= ?\n ", array($server_id, $creInfo->farmId ? $creInfo->farmId : $creInfo->dbFarmRole->FarmID, $creInfo->roleId, $creInfo->envId, $creInfo->dbFarmRole ? $creInfo->dbFarmRole->ID : 0, $client_id, $creInfo->platform, $status, $creInfo->remoteIp, $creInfo->localIp, $creInfo->index));
$DBServer = DBServer::LoadByID($server_id);
$DBServer->SetProperties($creInfo->GetProperties());
return $DBServer;
}
示例7: OnStartForking
/**
* {@inheritdoc}
* @see \Scalr\System\Pcntl\ProcessInterface::OnStartForking()
*/
public function OnStartForking()
{
if (!\Scalr::getContainer()->analytics->enabled) {
die("Terminating the process as Cost analytics is disabled in the config.\n");
}
if (SettingEntity::getValue(SettingEntity::ID_FORBID_AUTOMATIC_UPDATE_AWS_PRICES)) {
die("Terminating the process because of overriding AWS prices has been forbidden by financial admin.\n");
}
$now = new DateTime('now', new DateTimeZone('UTC'));
$urls = array('https://a0.awsstatic.com/pricing/1/ec2/linux-od.min.js', 'https://a0.awsstatic.com/pricing/1/ec2/mswin-od.min.js');
$mapping = array('us-east' => 'us-east-1', 'us-west' => 'us-west-1', 'us-west-2' => 'us-west-2', 'eu-ireland' => 'eu-west-1', 'sa-east-1' => 'sa-east-1', 'apac-sin' => 'ap-southeast-1', 'apac-tokyo' => 'ap-northeast-1', 'apac-syd' => 'ap-southeast-2');
$availableLocations = Aws::getCloudLocations();
foreach ($urls as $link) {
$json = trim(preg_replace('/^.+?callback\\((.+?)\\);\\s*$/sU', '\\1', file_get_contents($link)));
$data = json_decode(preg_replace('/(\\w+):/', '"\\1":', $json));
if (!empty($data->config->regions)) {
$cadb = Scalr::getContainer()->cadb;
foreach ($data->config->regions as $rd) {
foreach ($rd->instanceTypes as $it) {
if (!isset($mapping[$rd->region])) {
throw new Exception(sprintf("Region %s does not exist in the mapping.", $rd->region));
}
$region = $mapping[$rd->region];
$latest = array();
//Gets latest prices for all instance types from current region.
$res = $cadb->Execute("\n SELECT p.instance_type, ph.applied, p.os, p.name, HEX(p.price_id) `price_id`, p.cost\n FROM price_history ph\n JOIN prices p ON p.price_id = ph.price_id\n LEFT JOIN price_history ph2 ON ph2.platform = ph.platform\n AND ph2.cloud_location = ph.cloud_location\n AND ph2.account_id = ph.account_id\n AND ph2.url = ph.url\n AND ph2.applied > ph.applied AND ph2.applied <= ?\n LEFT JOIN prices p2 ON p2.price_id = ph2.price_id\n AND p2.instance_type = p.instance_type\n AND p2.os = p.os\n WHERE ph.account_id = 0 AND p2.price_id IS NULL\n AND ph.platform = 'ec2'\n AND ph.cloud_location = ?\n AND ph.url = ''\n AND ph.applied <= ?\n ", array($now->format('Y-m-d'), $region, $now->format('Y-m-d')));
while ($rec = $res->FetchRow()) {
$latest[$rec['instance_type']][$rec['os']] = array('applied' => $rec['applied'], 'price_id' => $rec['price_id'], 'cost' => $rec['cost']);
}
$upd = array();
$needUpdate = false;
foreach ($it->sizes as $sz) {
foreach ($sz->valueColumns as $v) {
$os = $v->name == 'linux' ? PriceEntity::OS_LINUX : PriceEntity::OS_WINDOWS;
if (!isset($latest[$sz->size][$os])) {
$needUpdate = true;
} else {
if (abs(($latest[$sz->size][$os]['cost'] - $v->prices->USD) / $v->prices->USD) > 1.0E-6) {
$needUpdate = true;
$latest[$sz->size][$os]['cost'] = $v->prices->USD;
} else {
continue;
}
}
$latest[$sz->size][$os] = array('cost' => $v->prices->USD);
}
}
if ($needUpdate) {
$priceid = $cadb->GetOne("\n SELECT HEX(`price_id`) AS `price_id`\n FROM price_history\n WHERE platform = 'ec2'\n AND url = ''\n AND cloud_location = ?\n AND applied = ?\n AND account_id = 0\n LIMIT 1\n ", array($region, $now->format('Y-m-d')));
if (!$priceid) {
$priceid = str_replace('-', '', Scalr::GenerateUID());
$cadb->Execute("\n INSERT price_history\n SET price_id = UNHEX(?),\n platform = 'ec2',\n url = '',\n cloud_location = ?,\n account_id = 0,\n applied = ?,\n deny_override = 0\n ", array($priceid, $region, $now->format('Y-m-d')));
}
foreach ($latest as $instanceType => $ld) {
foreach ($ld as $os => $v) {
$cadb->Execute("\n REPLACE prices\n SET price_id = UNHEX(?),\n instance_type = ?,\n name = ?,\n os = ?,\n cost = ?\n ", array($priceid, $instanceType, $instanceType, $os, $v['cost']));
}
}
}
}
}
}
}
exit;
}
示例8: Create
/**
*
* @param ServerCreateInfo $serverCreateInfo
* @param bool $isImport
* @return DBServer
*/
public static function Create(ServerCreateInfo $creInfo, $isImport = false, $setPendingStatus = false)
{
$db = \Scalr::getDb();
$startWithLetter = in_array($creInfo->platform, array(SERVER_PLATFORMS::CLOUDSTACK, SERVER_PLATFORMS::IDCF, SERVER_PLATFORMS::GCE));
if ($isImport) {
$startWithLetter = true;
}
$server_id = Scalr::GenerateUID(false, $startWithLetter);
$status = !$isImport ? SERVER_STATUS::PENDING_LAUNCH : SERVER_STATUS::IMPORTING;
if ($setPendingStatus) {
$status = SERVER_STATUS::PENDING;
}
// Assigns Farm index to the server
if (!$isImport) {
// This query select the least lower vacant Farm index from the available.
// If there are no available indexes the query returns NULL so we need cast result to integer
// to make sure it will use Farm index equal to 1 in this case.
// We ingore terminated and pending terminating instances to release their indexes.
$farmIndex = 1 + intval($db->GetOne("\n SELECT s.farm_index\n FROM servers s\n WHERE s.farm_id = ? AND s.status NOT IN (?, ?)\n AND NOT EXISTS (SELECT 1 FROM servers WHERE farm_id = s.farm_id AND farm_index = s.farm_index + 1 AND status NOT IN (?, ?))\n ORDER BY s.farm_index\n LIMIT 1\n ", [$creInfo->farmId ? $creInfo->farmId : $creInfo->dbFarmRole->FarmID, SERVER_STATUS::TERMINATED, SERVER_STATUS::PENDING_TERMINATE, SERVER_STATUS::TERMINATED, SERVER_STATUS::PENDING_TERMINATE]));
} else {
// Default Farm index value is considered to equal 1
$farmIndex = 1;
}
// IF no index defined
if (!$creInfo->index && !$isImport) {
$indexes = $db->GetAll("SELECT `index` FROM servers WHERE farm_roleid = ? AND status NOT IN (?, ?)", [$creInfo->dbFarmRole->ID, SERVER_STATUS::TERMINATED, SERVER_STATUS::PENDING_TERMINATE]);
$usedIndexes = [];
if (!empty($indexes)) {
foreach ($indexes as $index) {
$usedIndexes[$index['index']] = true;
}
}
for ($i = 1;; $i++) {
if (!isset($usedIndexes[$i])) {
$creInfo->index = $i;
break;
}
}
} elseif ($isImport) {
$creInfo->index = 0;
}
$client_id = $creInfo->clientId ? $creInfo->clientId : $creInfo->dbFarmRole->GetFarmObject()->ClientID;
$instanceTypeName = null;
$instanceTypeId = $creInfo->dbFarmRole ? $creInfo->dbFarmRole->getInstanceType() : null;
if (in_array($creInfo->platform, [SERVER_PLATFORMS::EC2, SERVER_PLATFORMS::GCE])) {
$instanceTypeName = $instanceTypeId;
}
$db->Execute("\n INSERT INTO servers\n SET `server_id` = ?,\n `farm_id` = ?,\n `env_id` = ?,\n `farm_roleid` = ?,\n `client_id` = ?,\n `platform` = ?,\n `status` = ?,\n `remote_ip` = ?,\n `local_ip` = ?,\n `dtadded` = NOW(),\n `index` = ?,\n `farm_index` = ?,\n `cloud_location` = ?,\n `type` = ?,\n `instance_type_name`= ?\n ", [$server_id, $creInfo->farmId ? $creInfo->farmId : $creInfo->dbFarmRole->FarmID, $creInfo->envId, $creInfo->dbFarmRole ? $creInfo->dbFarmRole->ID : 0, $client_id, $creInfo->platform, $status, $creInfo->remoteIp, $creInfo->localIp, $creInfo->index, $farmIndex, $creInfo->dbFarmRole ? $creInfo->dbFarmRole->CloudLocation : null, $instanceTypeId, $instanceTypeName]);
$DBServer = DBServer::LoadByID($server_id);
$DBServer->SetProperties($creInfo->GetProperties());
$DBServer->setOsType($DBServer->osType);
try {
if ($DBServer->farmRoleId) {
$db->Execute("\n INSERT INTO servers_launch_timelog\n SET `server_id` = ?,\n `os_family` = ?,\n `os_version` = ?,\n `cloud` = ?,\n `cloud_location` = ?,\n `server_type` = ?,\n `behaviors` = ?,\n `ts_created` = ?\n ", [$server_id, $DBServer->GetFarmRoleObject()->GetRoleObject()->getOs()->family, $DBServer->GetFarmRoleObject()->GetRoleObject()->getOs()->version, $DBServer->platform, $DBServer->cloudLocation, $DBServer->getType(), implode(",", $DBServer->GetFarmRoleObject()->GetRoleObject()->getBehaviors()), time()]);
}
} catch (Exception $e) {
}
return $DBServer;
}
示例9: save
/**
* Saves current entity to database
*
* @throws ModelException
*/
public function save()
{
$iterator = $this->getIterator();
$pk = $iterator->getPrimaryKey();
if (empty($pk)) {
throw new ModelException(sprintf("Primary key has not been defined with @Id tag for %s", get_class($this)));
}
$stmtFields = '';
$stmtUpdate = '';
$arguments1 = array();
$arguments2 = array();
foreach ($iterator->fields() as $field) {
if ($this->{$field->name} === null && isset($field->generatedValue)) {
if ($field->type instanceof UuidType || $field->type instanceof UuidStringType || $field->generatedValue->strategy == 'UUID') {
$this->{$field->name} = \Scalr::GenerateUID();
} else {
if ($field->generatedValue->strategy == 'AUTO') {
//Generated automatically by mysql
if (isset($field->id)) {
$postInsertField = $field;
}
continue;
} else {
throw new ModelException(sprintf("Type %s has not been implemented for GeneratedValue behaviour.", get_class($field->type)));
}
}
}
if (isset($field->id)) {
if (!isset($this->{$field->name}) && $field->column->nullable) {
$stmtFields .= ', ' . $field->getColumnName() . ' = NULL';
} else {
$stmtFields .= ', ' . $field->getColumnName() . ' = ' . $field->type->wh();
$arguments1[] = $field->type->toDb($this->{$field->name});
}
} else {
if (!isset($this->{$field->name}) && $field->column->nullable) {
$stmtFields .= ', ' . $field->getColumnName() . ' = NULL';
$stmtUpdate .= ', ' . $field->getColumnName() . ' = NULL';
} else {
$stmtFields .= ', ' . $field->getColumnName() . ' = ' . $field->type->wh();
$arguments1[] = $field->type->toDb($this->{$field->name});
$stmtUpdate .= ', ' . $field->getColumnName() . ' = ' . $field->type->wh();
$arguments2[] = $field->type->toDb($this->{$field->name});
}
}
}
$stmtFields = substr($stmtFields, 1);
if ($stmtUpdate != '') {
$stmtUpdate = substr($stmtUpdate, 1);
}
$this->db()->Execute("\n INSERT " . ($stmtUpdate == '' ? 'IGNORE' : '') . " {$this->table()} SET " . $stmtFields . "\n " . ($stmtUpdate != '' ? "ON DUPLICATE KEY UPDATE " . $stmtUpdate : '') . "\n ", array_merge($arguments1, $arguments2));
if (isset($postInsertField)) {
$this->{$postInsertField->name} = $postInsertField->type->toPhp($this->db()->Insert_ID());
}
}
示例10: xSaveAction
public function xSaveAction()
{
$this->request->defineParams(array('domainId' => array('type' => 'int'), 'domainName', 'domainType', 'domainFarm' => array('type' => 'int'), 'domainFarmRole' => array('type' => 'int'), 'soaRefresh' => array('type' => 'int'), 'soaExpire' => array('type' => 'int'), 'soaRetry' => array('type' => 'int'), 'records' => array('type' => 'json')));
$errors = array();
// validate farmId, farmRoleId
$farmId = 0;
$farmRoleId = 0;
if ($this->getParam('domainFarm')) {
$DBFarm = DBFarm::LoadByID($this->getParam('domainFarm'));
if (!$this->user->getPermissions()->check($DBFarm)) {
$errors['domainFarm'] = _('Farm not found');
} else {
$farmId = $DBFarm->ID;
if ($this->getParam('domainFarmRole')) {
$DBFarmRole = DBFarmRole::LoadByID($this->getParam('domainFarmRole'));
if ($DBFarmRole->FarmID != $DBFarm->ID) {
$errors['domainFarmRole'] = _('Role not found');
} else {
$farmRoleId = $DBFarmRole->ID;
}
}
}
}
// validate domain name
$domainName = '';
if (!$this->getParam('domainId')) {
if ($this->getParam('domainType') == 'own') {
$Validator = new Validator();
if (!$Validator->IsDomain($this->getParam('domainName'))) {
$errors['domainName'] = _("Invalid domain name");
} else {
$domainChunks = explode(".", $this->getParam('domainName'));
$chkDmn = '';
while (count($domainChunks) > 0) {
$chkDmn = trim(array_pop($domainChunks) . ".{$chkDmn}", ".");
$chkDomainId = $this->db->GetOne("SELECT id FROM dns_zones WHERE zone_name=? AND client_id != ?", array($chkDmn, $this->user->getAccountId()));
if ($chkDomainId) {
if ($chkDmn == $this->getParam('domainName')) {
$errors['domainName'] = sprintf(_("%s already exists on scalr nameservers"), $this->getParam('domainName'));
} else {
$chkDnsZone = DBDNSZone::loadById($chkDomainId);
$access = false;
foreach (explode(";", $chkDnsZone->allowedAccounts) as $email) {
if ($email == $this->user->getEmail()) {
$access = true;
}
}
if (!$access) {
$errors['domainName'] = sprintf(_("You cannot use %s domain name because top level domain %s does not belong to you"), $this->getParam('domainName'), $chkDmn);
}
}
}
}
//if (! $errors['domainName'])
$domainName = $this->getParam('domainName');
}
} else {
$domainName = Scalr::GenerateUID() . '.' . CONFIG::$DNS_TEST_DOMAIN_NAME;
}
// check in DB
$rez = $this->db->GetOne("SELECT id FROM dns_zones WHERE zone_name = ?", array($domainName));
if ($rez) {
$errors['domainName'] = 'Domain name already exist in database';
}
}
$records = array();
foreach ($this->getParam('records') as $key => $r) {
if (($r['name'] || $r['value']) && $r['issystem'] == 0) {
$r['name'] = str_replace("%hostname%", "{$domainName}", $r['name']);
$r['value'] = str_replace("%hostname%", "{$domainName}", $r['value']);
$records[$key] = $r;
}
}
$recordsValidation = Scalr_Net_Dns_Zone::validateRecords($records);
if ($recordsValidation !== true) {
$errors = array_merge($errors, $recordsValidation);
}
if (count($errors) == 0) {
if ($this->getParam('domainId')) {
$DBDNSZone = DBDNSZone::loadById($this->getParam('domainId'));
$this->user->getPermissions()->validate($DBDNSZone);
$DBDNSZone->soaRefresh = $this->getParam('soaRefresh');
$DBDNSZone->soaExpire = $this->getParam('soaExpire');
$DBDNSZone->soaRetry = $this->getParam('soaRetry');
$this->response->success("DNS zone successfully updated. It could take up to 5 minutes to update it on NS servers.");
} else {
$DBDNSZone = DBDNSZone::create($domainName, $this->getParam('soaRefresh'), $this->getParam('soaExpire'), str_replace('@', '.', $this->user->getEmail()), $this->getParam('soaRetry'));
$DBDNSZone->clientId = $this->user->getAccountId();
$DBDNSZone->envId = $this->getEnvironmentId();
$this->response->success("DNS zone successfully added to database. It could take up to 5 minutes to setup it on NS servers.");
}
if ($DBDNSZone->farmRoleId != $farmRoleId || $DBDNSZone->farmId != $farmId) {
$DBDNSZone->farmId = 0;
$DBDNSZone->updateSystemRecords();
}
$DBDNSZone->farmRoleId = $farmRoleId;
$DBDNSZone->farmId = $farmId;
$DBDNSZone->setRecords($records);
$DBDNSZone->save(true);
} else {
//.........这里部分代码省略.........
示例11: __construct
/**
* constructor
* @return void
*/
public function __construct()
{
$this->EventID = Scalr::GenerateUID();
}
示例12: createHostedScalrAccountCostCenter
/**
* Creates default Cost Center for the Hosted Scalr new account
*
* @param Scalr_Account $account The account object
* @param Scalr_Account_User $user optional The account owner user
* @return CostCentreEntity Returns a new Cost Center
*/
public function createHostedScalrAccountCostCenter(Scalr_Account $account, Scalr_Account_User $user = null)
{
if (!$user instanceof Scalr_Account_User) {
$user = $account->getOwner();
}
//New Cost Center should be created in account share mode
$cc = new CostCentreEntity();
$cc->ccId = \Scalr::GenerateUID();
$cc->accountId = $account->id;
$cc->createdByEmail = $user->getEmail();
$cc->name = "Cost Center " . $account->name . " (" . $account->id . ")";
$cc->createdById = $user->id;
$cc->save();
$cc->saveProperty(CostCentrePropertyEntity::NAME_BILLING_CODE, "CC-" . $account->name);
$cc->saveProperty(CostCentrePropertyEntity::NAME_DESCRIPTION, "This Cost Center was added automatically.");
$cc->saveProperty(CostCentrePropertyEntity::NAME_LEAD_EMAIL, $user->getEmail());
$cc->saveProperty(CostCentrePropertyEntity::NAME_LOCKED, false);
//A new Project which corresponds to Cost Center (in account share mode as well)
$project = new ProjectEntity();
$project->projectId = \Scalr::GenerateUID();
$project->ccId = $cc->ccId;
$project->name = "Project " . $account->name . " (" . $account->id . ")";
$project->accountId = $account->id;
$project->createdByEmail = $user->getEmail();
$project->shared = ProjectEntity::SHARED_WITHIN_ACCOUNT;
$project->createdById = $user->id;
$project->save();
$project->saveProperty(ProjectPropertyEntity::NAME_BILLING_CODE, "PR-" . $account->name);
$project->saveProperty(ProjectPropertyEntity::NAME_DESCRIPTION, "This Project was added automatically.");
$project->saveProperty(ProjectPropertyEntity::NAME_LEAD_EMAIL, $user->getEmail());
if (\Scalr::getContainer()->analytics->enabled) {
\Scalr::getContainer()->analytics->tags->syncValue($account->id, TagEntity::TAG_ID_COST_CENTRE, $cc->ccId, $cc->name);
\Scalr::getContainer()->analytics->tags->syncValue($account->id, TagEntity::TAG_ID_PROJECT, $project->projectId, $project->name);
}
return $cc;
}
示例13: extendMessage
/**
* {@inheritdoc}
* @see Scalr_Role_Behavior::extendMessage()
*/
public function extendMessage(Scalr_Messaging_Msg $message, DBServer $dbServer)
{
$message = parent::extendMessage($message, $dbServer);
switch (get_class($message)) {
case 'Scalr_Messaging_Msg_HostInitResponse':
$config = $this->getConfiguration($dbServer);
if (!empty($config->serverUrl) || !empty($config->cookbookUrl)) {
$message->chef = $config;
$message->chef->scriptName = '[Scalr built-in] Chef bootstrap';
$message->chef->executionId = Scalr::GenerateUID();
$message->chef->eventName = 'HostInit';
}
break;
}
return $message;
}
示例14: create
/**
* Create new FarmRoleStorageConfig based on input config
*
* @param FarmRoleStorageConfig $config
*/
public function create(FarmRoleStorageConfig $config)
{
$deleteFlag = false;
if ($config->id) {
$this->loadById($config->id);
if ($this->status == self::STATE_PENDING_CREATE) {
if ($config->status == self::STATE_PENDING_DELETE) {
// mark for delete on save
$deleteFlag = true;
} else {
$this->type = $config->type;
$this->fs = $config->fs;
$this->reUse = $config->reUse;
$this->rebuild = $config->rebuild;
$this->mount = $config->mount;
$this->mountPoint = $config->mountPoint;
$this->mountOptions = $config->mountOptions;
$this->label = $config->label;
}
} elseif ($config->status == self::STATE_PENDING_DELETE) {
$this->status = self::STATE_PENDING_DELETE;
}
} else {
$this->id = \Scalr::GenerateUID();
$this->type = $config->type;
$this->fs = $config->fs;
$this->reUse = $config->reUse;
$this->rebuild = $config->rebuild;
$this->mount = $config->mount;
$this->mountPoint = $config->mountPoint;
$this->mountOptions = $config->mountOptions;
$this->label = $config->label;
$this->status = self::STATE_PENDING_CREATE;
}
if ($deleteFlag) {
$this->delete();
return;
}
$this->settings = $config->settings;
$this->save();
}
示例15: __construct
/**
* Constuctor
*/
public function __construct()
{
$this->requestId = \Scalr::GenerateUID();
}