public function setVolumes(\DBServer $server, $volumes) { $vlms = array(); foreach ($volumes as $volume) { $vlms[$volume->scalrStorageId] = $volume; } foreach ($this->getConfigs() as $config) { if ($vlms[$config->id]) { $volume = new FarmRoleStorageDevice(); if (!$volume->loadById($volume->id)) { $volume->farmRoleId = $this->farmRole->ID; $volume->storageConfigId = $config->id; $volume->serverIndex = $server->index; $volume->storageId = $vlms[$config->id]->id; $volume->cloudLocation = $server->GetCloudLocation(); $volume->envId = $server->envId; } switch ($config->type) { case FarmRoleStorageConfig::TYPE_RAID_EBS: $volume->placement = $vlms[$config->id]->disks[0]->availZone; break; case FarmRoleStorageConfig::TYPE_EBS: $volume->placement = $vlms[$config->id]->availZone; break; } $volume->config = $vlms[$config->id]; $volume->status = FarmRoleStorageDevice::STATUS_ACTIVE; $volume->save(); unset($vlms[$config->id]); } } //TODO: Handle zombies }
public static function removeIpFromServer(\DBServer $dbServer) { try { if ($dbServer->GetProperty(\OPENSTACK_SERVER_PROPERTIES::FLOATING_IP)) { if ($dbServer->farmRoleId) { if ($dbServer->GetFarmRoleObject()->GetSetting(\DBFarmRole::SETTING_OPENSTACK_KEEP_FIP_ON_SUSPEND)) { if (in_array($dbServer->status, array(\SERVER_STATUS::PENDING_SUSPEND, \SERVER_STATUS::SUSPENDED)) || $dbServer->GetRealStatus()->isSuspended()) { return false; } } } $environment = $dbServer->GetEnvironmentObject(); $osClient = $environment->openstack($dbServer->platform, $dbServer->GetCloudLocation()); $ipId = $dbServer->GetProperty(\OPENSTACK_SERVER_PROPERTIES::FLOATING_IP_ID); if ($osClient->hasService('network')) { $osClient->network->floatingIps->delete($ipId); } else { $osClient->servers->deleteFloatingIp($ipId); } $dbServer->SetProperties(array(\OPENSTACK_SERVER_PROPERTIES::FLOATING_IP => null, \OPENSTACK_SERVER_PROPERTIES::FLOATING_IP_ID => null)); } } catch (\Exception $e) { \Logger::getLogger("OpenStackObserver")->fatal("OpenStackObserver observer failed: " . $e->getMessage()); } }
private function cleanupFloatingIps(DBServer $dbServer) { try { if ($dbServer->GetProperty(OPENSTACK_SERVER_PROPERTIES::FLOATING_IP)) { $environment = $dbServer->GetEnvironmentObject(); $osClient = $environment->openstack($dbServer->platform, $dbServer->GetCloudLocation()); $ipId = $dbServer->GetProperty(OPENSTACK_SERVER_PROPERTIES::FLOATING_IP_ID); if ($osClient->hasService('network')) { $osClient->network->floatingIps->delete($ipId); } else { $osClient->servers->deleteFloatingIp($ipId); } $dbServer->SetProperties(array(OPENSTACK_SERVER_PROPERTIES::FLOATING_IP => null, OPENSTACK_SERVER_PROPERTIES::FLOATING_IP_ID => null)); } } catch (Exception $e) { Logger::getLogger("OpenStackObserver")->fatal("OpenStackObserver observer failed: " . $e->getMessage()); } }
public function setServerMetaData(DBServer $dbServer) { try { $this->behaviour = $dbServer->GetFarmRoleObject()->GetRoleObject()->getBehaviors(); $this->roleName = $dbServer->GetFarmRoleObject()->GetRoleObject()->name; $this->farmRoleAlias = $dbServer->GetFarmRoleObject()->Alias; if (empty($this->farmRoleAlias)) { $this->farmRoleAlias = $this->roleName; } } catch (Exception $e) { } $this->localIp = $dbServer->localIp; $this->remoteIp = $dbServer->remoteIp; $this->serverIndex = $dbServer->index; $this->serverId = $dbServer->serverId; $this->cloudLocation = $dbServer->GetCloudLocation(); $this->farmRoleId = $dbServer->farmRoleId; }
private function getSzrCmd(DBServer $dbServer) { $baseurl = \Scalr::config('scalr.endpoint.scheme') . "://" . \Scalr::config('scalr.endpoint.host'); $platform = $dbServer->isOpenstack() ? SERVER_PLATFORMS::OPENSTACK : $dbServer->platform; $options = array('server-id' => $dbServer->serverId, 'role-name' => $dbServer->GetProperty(SERVER_PROPERTIES::SZR_IMPORTING_ROLE_NAME), 'crypto-key' => $dbServer->GetProperty(SERVER_PROPERTIES::SZR_KEY), 'platform' => $platform, 'queryenv-url' => $baseurl . "/query-env", 'messaging-p2p.producer-url' => $baseurl . "/messaging", 'env-id' => $dbServer->envId, 'region' => $dbServer->GetCloudLocation(), 'scalr-id' => SCALR_ID); $command = 'scalarizr --import -y'; foreach ($options as $k => $v) { $command .= sprintf(' -o %s=%s', $k, $v); } return $command; }
public function getVolumeConfig(DBFarmRole $dbFarmRole, DBServer $dbServer) { $r = new ReflectionClass($this); if ($r->hasConstant("ROLE_VOLUME_ID")) { if ($dbFarmRole->GetSetting(static::ROLE_VOLUME_ID)) { try { $volume = Scalr_Storage_Volume::init()->loadById($dbFarmRole->GetSetting(static::ROLE_VOLUME_ID)); $volumeConfig = $volume->getConfig(); } catch (Exception $e) { } } if (!$volumeConfig) { $volumeConfig = new stdClass(); $volumeConfig->type = $dbFarmRole->GetSetting(static::ROLE_DATA_STORAGE_ENGINE); if (in_array($dbFarmRole->GetSetting(static::ROLE_DATA_STORAGE_ENGINE), array(MYSQL_STORAGE_ENGINE::EBS, MYSQL_STORAGE_ENGINE::CSVOL))) { $volumeConfig->size = $dbFarmRole->GetSetting(static::ROLE_DATA_STORAGE_EBS_SIZE); } elseif ($dbFarmRole->GetSetting(static::ROLE_DATA_STORAGE_ENGINE) == MYSQL_STORAGE_ENGINE::EPH) { $volumeConfig->snap_backend = sprintf("cf://scalr-%s-%s/data-bundles/%s/%s", $dbServer->envId, $dbServer->GetCloudLocation(), $dbFarmRole->FarmID, $this->behavior); $volumeConfig->vg = $this->behavior; $volumeConfig->disk = new stdClass(); $volumeConfig->disk->type = 'loop'; $volumeConfig->disk->size = '75%root'; } } return $volumeConfig; } else { return false; } }
public static function onCreateBackupResult(Scalr_Messaging_Msg $message, DBServer $dbServer) { $dbFarmRole = $dbServer->GetFarmRoleObject(); $dbFarmRole->SetSetting(Scalr_Db_Msr::DATA_BACKUP_LAST_TS, time(), DBFarmRole::TYPE_LCL); $dbFarmRole->SetSetting(Scalr_Db_Msr::DATA_BACKUP_IS_RUNNING, 0, DBFarmRole::TYPE_LCL); //$dbFarmRole->SetSetting(Scalr_Db_Msr::DATA_BACKUP_SERVER_ID, ""); if (PlatformFactory::isOpenstack($dbServer->platform)) { $provider = 'cf'; } else { switch ($dbServer->platform) { case SERVER_PLATFORMS::EC2: $provider = 's3'; break; case SERVER_PLATFORMS::GCE: $provider = 'gcs'; break; default: $provider = 'unknown'; break; } } $backup = Scalr_Db_Backup::init(); $backup->service = $message->dbType; $backup->platform = $dbServer->platform; $backup->provider = $provider; $backup->envId = $dbServer->envId; $backup->farmId = $dbServer->farmId; $backup->cloudLocation = $dbServer->GetCloudLocation(); $backup->status = Scalr_Db_Backup::STATUS_AVAILABLE; $total = 0; if (isset($message->backupParts) && is_array($message->backupParts)) { foreach ($message->backupParts as $item) { if (is_object($item) && $item->size) { $backup->addPart(str_replace(array("s3://", "cf://", "gcs://", "swift://"), array("", "", "", ""), $item->path), $item->size); $total = $total + (int) $item->size; } else { $backup->addPart(str_replace(array("s3://", "cf://", "gcs://", "swift://"), array("", "", "", ""), $item), 0); } } } $backup->size = $total; $backup->save(); }
public function GetPlatformAccessData($environment, DBServer $DBServer) { $accessData = new stdClass(); $accessData->accountId = $environment->getPlatformConfigValue(self::ACCOUNT_ID, true, $DBServer->GetCloudLocation()); $accessData->keyId = $environment->getPlatformConfigValue(self::ACCESS_KEY, true, $DBServer->GetCloudLocation()); $accessData->key = $environment->getPlatformConfigValue(self::SECRET_KEY, true, $DBServer->GetCloudLocation()); $accessData->cert = $environment->getPlatformConfigValue(self::CERTIFICATE, true, $DBServer->GetCloudLocation()); $accessData->pk = $environment->getPlatformConfigValue(self::PRIVATE_KEY, true, $DBServer->GetCloudLocation()); $accessData->ec2_url = $environment->getPlatformConfigValue(self::EC2_URL, true, $DBServer->GetCloudLocation()); $accessData->s3_url = $environment->getPlatformConfigValue(self::S3_URL, true, $DBServer->GetCloudLocation()); $accessData->cloud_cert = $environment->getPlatformConfigValue(self::CLOUD_CERTIFICATE, true, $DBServer->GetCloudLocation()); return $accessData; }
public function PutAccessData(DBServer $DBServer, Scalr_Messaging_Msg $message) { $put = false; $put |= $message instanceof Scalr_Messaging_Msg_Rebundle; $put |= $message instanceof Scalr_Messaging_Msg_HostInitResponse; $put |= $message instanceof Scalr_Messaging_Msg_Mysql_PromoteToMaster; $put |= $message instanceof Scalr_Messaging_Msg_Mysql_CreateDataBundle; $put |= $message instanceof Scalr_Messaging_Msg_Mysql_CreateBackup; $put |= $message instanceof Scalr_Messaging_Msg_DbMsr_PromoteToMaster; $put |= $message instanceof Scalr_Messaging_Msg_DbMsr_CreateDataBundle; $put |= $message instanceof Scalr_Messaging_Msg_DbMsr_CreateBackup; $environment = $DBServer->GetEnvironmentObject(); if ($put) { $accessData = new stdClass(); $accessData->accountId = $environment->getPlatformConfigValue(self::ACCOUNT_ID, true, $DBServer->GetCloudLocation()); $accessData->keyId = $environment->getPlatformConfigValue(self::ACCESS_KEY, true, $DBServer->GetCloudLocation()); $accessData->key = $environment->getPlatformConfigValue(self::SECRET_KEY, true, $DBServer->GetCloudLocation()); $accessData->cert = $environment->getPlatformConfigValue(self::CERTIFICATE, true, $DBServer->GetCloudLocation()); $accessData->pk = $environment->getPlatformConfigValue(self::PRIVATE_KEY, true, $DBServer->GetCloudLocation()); $accessData->ec2_url = $environment->getPlatformConfigValue(self::EC2_URL, true, $DBServer->GetCloudLocation()); $accessData->s3_url = $environment->getPlatformConfigValue(self::S3_URL, true, $DBServer->GetCloudLocation()); $accessData->cloud_cert = $environment->getPlatformConfigValue(self::CLOUD_CERTIFICATE, true, $DBServer->GetCloudLocation()); $message->platformAccessData = $accessData; } }
public function GetServerExtendedInformation(DBServer $DBServer) { try { try { $gce = $this->getClient($DBServer->GetEnvironmentObject(), $DBServer->GetProperty(GCE_SERVER_PROPERTIES::CLOUD_LOCATION)); $info = $gce->instances->get($DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::PROJECT_ID), $DBServer->GetCloudLocation(), $DBServer->GetProperty(GCE_SERVER_PROPERTIES::SERVER_NAME)); } catch (Exception $e) { } if ($info) { $network = $info->getNetworkInterfaces(); return array('Cloud Server ID' => $info->id, 'Image ID' => $this->getObjectName($info->image), 'Machine Type' => $this->getObjectName($info->machineType), 'Public IP' => $network[0]->accessConfigs[0]->natIP, 'Private IP' => $network[0]->networkIP, 'Status' => $info->status, 'Name' => $info->name, 'Zone' => $this->getObjectName($info->zone)); } } catch (Exception $e) { } return false; }