GetEnvironmentObject() public method

public GetEnvironmentObject ( ) : Scalr_Environment
return Scalr_Environment
Ejemplo n.º 1
0
 private function DeregisterInstanceFromLB(DBServer $DBServer)
 {
     try {
         $DBFarmRole = $DBServer->GetFarmRoleObject();
         if ($DBFarmRole->GetSetting(DBFarmRole::SETTING_BALANCING_USE_ELB) == 1) {
             $Client = $DBServer->GetClient();
             $AmazonELBClient = Scalr_Service_Cloud_Aws::newElb($DBServer->GetProperty(EC2_SERVER_PROPERTIES::REGION), $DBServer->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::ACCESS_KEY), $DBServer->GetEnvironmentObject()->getPlatformConfigValue(Modules_Platforms_Ec2::SECRET_KEY));
             $AmazonELBClient->DeregisterInstancesFromLoadBalancer($DBFarmRole->GetSetting(DBFarmRole::SETTING_BALANCING_NAME), array($DBServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID)));
             Logger::getLogger(LOG_CATEGORY::FARM)->info(new FarmLogMessage($this->FarmID, sprintf(_("Instance '%s' deregistered from '%s' load balancer"), $DBServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID), $DBFarmRole->GetSetting(DBFarmRole::SETTING_BALANCING_NAME))));
         }
     } catch (Exception $e) {
         Logger::getLogger(LOG_CATEGORY::FARM)->info(new FarmLogMessage($this->FarmID, sprintf(_("Cannot deregister instance from the load balancer: %s"), $e->getMessage())));
     }
 }
Ejemplo n.º 2
0
 public function GetServerIPAddresses(DBServer $DBServer)
 {
     $client = $this->getOsClient($DBServer->GetEnvironmentObject(), $DBServer->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION));
     $result = $client->servers->getServerDetails($DBServer->GetProperty(OPENSTACK_SERVER_PROPERTIES::SERVER_ID));
     if ($result->accessIPv4) {
         $remoteIp = $result->accessIPv4;
     }
     if (!$remoteIp) {
         if (is_array($result->addresses->public)) {
             foreach ($result->addresses->public as $addr) {
                 if ($addr->version == 4) {
                     $remoteIp = $addr->addr;
                     break;
                 }
             }
         }
     }
     if (is_array($result->addresses->private)) {
         foreach ($result->addresses->private as $addr) {
             if ($addr->version == 4) {
                 $localIp = $addr->addr;
                 break;
             }
         }
     }
     if (!$localIp) {
         $localIp = $remoteIp;
     }
     return array('localIp' => $localIp, 'remoteIp' => $remoteIp);
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  * @see \Scalr\Modules\Platforms\Openstack\OpenstackPlatformModule::GetServerIPAddresses()
  */
 public function GetServerIPAddresses(\DBServer $DBServer)
 {
     $config = \Scalr::getContainer()->config;
     $client = $this->getOsClient($DBServer->GetEnvironmentObject(), $DBServer->GetProperty(\OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION));
     $result = $client->servers->getServerDetails($DBServer->GetProperty(\OPENSTACK_SERVER_PROPERTIES::SERVER_ID));
     $publicNetworkName = 'public';
     $privateNetworkName = 'private';
     if (is_array($result->addresses->{$publicNetworkName})) {
         foreach ($result->addresses->{$publicNetworkName} as $addr) {
             if ($addr->version == 4) {
                 $remoteIp = $addr->addr;
                 break;
             }
         }
     }
     if (!$remoteIp && $result->accessIPv4) {
         $remoteIp = $result->accessIPv4;
     }
     if (is_array($result->addresses->{$privateNetworkName})) {
         foreach ($result->addresses->{$privateNetworkName} as $addr) {
             if ($addr->version == 4) {
                 $localIp = $addr->addr;
                 break;
             }
         }
     }
     if (!$localIp) {
         $localIp = $remoteIp;
     }
     return array('localIp' => $localIp, 'remoteIp' => $remoteIp);
 }
Ejemplo n.º 4
0
 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());
     }
 }
Ejemplo n.º 5
0
 public function PutAccessData(\DBServer $DBServer, \Scalr_Messaging_Msg $message)
 {
     $put = false;
     $put |= $message instanceof \Scalr_Messaging_Msg_Rebundle;
     $put |= $message instanceof \Scalr_Messaging_Msg_BeforeHostUp;
     $put |= $message instanceof \Scalr_Messaging_Msg_HostInitResponse;
     $put |= $message instanceof \Scalr_Messaging_Msg_Mysql_PromoteToMaster;
     $put |= $message instanceof \Scalr_Messaging_Msg_Mysql_NewMasterUp;
     $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;
     $put |= $message instanceof \Scalr_Messaging_Msg_DbMsr_NewMasterUp;
     if ($put) {
         $ccProps = $DBServer->GetEnvironmentObject()->keychain($DBServer->platform)->properties;
         $accessData = new \stdClass();
         $accessData->apiKey = $ccProps[CloudCredentialsProperty::CLOUDSTACK_API_KEY];
         $accessData->secretKey = $ccProps[CloudCredentialsProperty::CLOUDSTACK_SECRET_KEY];
         $apiUrl = $ccProps[CloudCredentialsProperty::CLOUDSTACK_API_URL];
         if ($apiUrl == 'https://apis.i.noahcloud.jp/portal/client/api') {
             $accessData->apiUrl = "https://api.noahcloud.jp/portal/client/api";
         } else {
             $accessData->apiUrl = $apiUrl;
         }
         $message->platformAccessData = $accessData;
     }
 }
Ejemplo n.º 6
0
 public static function setupScalrAgent(\DBServer $dbServer)
 {
     $baseurl = \Scalr::config('scalr.endpoint.scheme') . "://" . \Scalr::config('scalr.endpoint.host');
     $env = $dbServer->GetEnvironmentObject();
     $azure = $env->azure();
     $branch = $dbServer->getScalarizrRepository()['repository'];
     $develRepos = \Scalr::getContainer()->config->get('scalr.scalarizr_update.devel_repos');
     $scmBranch = $dbServer->GetFarmRoleObject()->GetSetting('user-data.scm_branch');
     if ($scmBranch != '' && $develRepos) {
         $branch = $dbServer->GetFarmRoleObject()->GetSetting('base.devel_repository');
         $scmBranch = "{$scmBranch}/";
     } else {
         $scmBranch = '';
     }
     if ($dbServer->osType == 'linux') {
         $extensionProperties = new ResourceExtensionProperties('Microsoft.OSTCExtensions', 'CustomScriptForLinux', '1.2');
         $extensionProperties->setSettings(['commandToExecute' => "bash -c 'curl -k -L \"{$baseurl}/public/linux/{$branch}/azure/{$scmBranch}install_scalarizr.sh\" | bash && service scalr-upd-client start'"]);
     } else {
         $extensionProperties = new ResourceExtensionProperties('Microsoft.Compute', 'CustomScriptExtension', '1.4');
         $extensionProperties->setSettings(["commandToExecute" => "powershell -NoProfile -ExecutionPolicy Bypass -Command \"iex ((new-object net.webclient).DownloadString('{$baseurl}/public/windows/{$branch}/{$scmBranch}install_scalarizr.ps1')); start-service ScalrUpdClient\""]);
     }
     $createExtension = new CreateResourceExtension('scalarizr', $dbServer->cloudLocation, $extensionProperties);
     try {
         $response = $azure->compute->resourceExtension->create($env->keychain(SERVER_PLATFORMS::AZURE)->properties[Entity\CloudCredentialsProperty::AZURE_SUBSCRIPTION_ID], $dbServer->GetProperty(\AZURE_SERVER_PROPERTIES::RESOURCE_GROUP), $dbServer->GetProperty(\AZURE_SERVER_PROPERTIES::SERVER_NAME), $createExtension);
         \Scalr::getContainer()->logger(\LOG_CATEGORY::FARM)->info(new \FarmLogMessage($dbServer, sprintf(_("Created azure resource extension to install and launch scalr agent"))));
         $dbServer->SetProperty(\AZURE_SERVER_PROPERTIES::SZR_EXTENSION_DEPLOYED, 1);
     } catch (\Exception $e) {
         \Scalr::getContainer()->logger(\LOG_CATEGORY::FARM)->fatal(new \FarmLogMessage($dbServer, sprintf(_("Unable to create azure resource extension to install and launch scalr agent: %s"), $e->getMessage())));
     }
 }
Ejemplo n.º 7
0
 public function PutAccessData(\DBServer $DBServer, \Scalr_Messaging_Msg $message)
 {
     $put = false;
     $put |= $message instanceof \Scalr_Messaging_Msg_Rebundle;
     $put |= $message instanceof \Scalr_Messaging_Msg_BeforeHostUp;
     $put |= $message instanceof \Scalr_Messaging_Msg_HostInitResponse;
     $put |= $message instanceof \Scalr_Messaging_Msg_Mysql_PromoteToMaster;
     $put |= $message instanceof \Scalr_Messaging_Msg_Mysql_NewMasterUp;
     $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;
     $put |= $message instanceof \Scalr_Messaging_Msg_DbMsr_NewMasterUp;
     if ($put) {
         $environment = $DBServer->GetEnvironmentObject();
         $accessData = new \stdClass();
         $accessData->apiKey = $this->getConfigVariable(self::API_KEY, $environment);
         $accessData->secretKey = $this->getConfigVariable(self::SECRET_KEY, $environment);
         $apiUrl = $this->getConfigVariable(self::API_URL, $environment);
         if ($apiUrl == 'https://apis.i.noahcloud.jp/portal/client/api') {
             $accessData->apiUrl = "https://api.noahcloud.jp/portal/client/api";
         } else {
             $accessData->apiUrl = $apiUrl;
         }
         $message->platformAccessData = $accessData;
     }
 }
Ejemplo n.º 8
0
 public function TerminateServer(DBServer $DBServer)
 {
     $cs = $this->getCloudStackClient($DBServer->GetEnvironmentObject(), $this->GetServerCloudLocation($DBServer));
     if (!$DBServer->GetProperty(CLOUDSTACK_SERVER_PROPERTIES::IS_STOPPED_BEFORE_TERMINATE)) {
         $cs->stopVirtualMachine($DBServer->GetProperty(CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID), true);
         $DBServer->SetProperty(CLOUDSTACK_SERVER_PROPERTIES::IS_STOPPED_BEFORE_TERMINATE, 1);
     }
     return parent::TerminateServer($DBServer);
 }
Ejemplo n.º 9
0
 /**
  * {@inheritdoc}
  * @see \Scalr\Modules\Platforms\Cloudstack\CloudstackPlatformModule::TerminateServer()
  */
 public function TerminateServer(\DBServer $DBServer)
 {
     $cs = $DBServer->GetEnvironmentObject()->cloudstack($this->platform);
     if (!$DBServer->GetProperty(\CLOUDSTACK_SERVER_PROPERTIES::IS_STOPPED_BEFORE_TERMINATE)) {
         $cs->instance->stop($DBServer->GetProperty(\CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID), true);
         $DBServer->SetProperty(\CLOUDSTACK_SERVER_PROPERTIES::IS_STOPPED_BEFORE_TERMINATE, 1);
     }
     return parent::TerminateServer($DBServer);
 }
Ejemplo n.º 10
0
 /**
  * Associates IP Address to the server
  *
  * @param   DBServer           $dbServer  DBServer object
  * @param   string             $ipAddress Public IP address to associate with server.
  * @throws  Exception
  */
 private static function associateIpAddress(DBServer $dbServer, $ipAddress, $allocationId = null)
 {
     $platform = PlatformFactory::NewPlatform($dbServer->platform);
     $cs = Scalr_Service_Cloud_Cloudstack::newCloudstack($platform->getConfigVariable(Modules_Platforms_Cloudstack::API_URL, $dbServer->GetEnvironmentObject()), $platform->getConfigVariable(Modules_Platforms_Cloudstack::API_KEY, $dbServer->GetEnvironmentObject()), $platform->getConfigVariable(Modules_Platforms_Cloudstack::SECRET_KEY, $dbServer->GetEnvironmentObject()), $dbServer->platform);
     $assign_retries = 1;
     $retval = false;
     // Remove OLD static NAT
     if ($dbServer->remoteIp) {
         try {
             $info = $cs->listPublicIpAddresses(null, null, null, null, null, $dbServer->remoteIp);
             $info = $info->publicipaddress[0];
             if ($info->issystem && $info->isstaticnat) {
                 $cs->disableStaticNat($info->id);
             }
         } catch (Exception $e) {
             Logger::getLogger('Cloudstack_Helper')->error("Unable to disable old static NAT: {$e->getMessage()}");
         }
     }
     try {
         $cs->disableStaticNat($allocationId);
     } catch (Exception $e) {
     }
     $assignRetries = 0;
     while (true) {
         try {
             $assignRetries++;
             $cs->enableStaticNat($allocationId, $dbServer->GetCloudServerID());
             $retval = true;
             break;
         } catch (Exception $e) {
             if (!stristr($e->getMessage(), "already assigned to antoher vm") || $assignRetries == 3) {
                 throw new Exception($e->getMessage());
             } else {
                 sleep(1);
             }
         }
         //break;
     }
     return $retval;
 }
Ejemplo n.º 11
0
 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());
     }
 }
Ejemplo n.º 12
0
 public static function listServerGlobalVariables(DBServer $dbServer, $includeSystem = false, AbstractServerEvent $event = null)
 {
     $retval = array();
     if ($includeSystem) {
         $variables = $dbServer->GetScriptingVars();
         if ($event) {
             if ($event->DBServer) {
                 foreach ($event->DBServer->GetScriptingVars() as $k => $v) {
                     $variables["event_{$k}"] = $v;
                 }
             }
             foreach ($event->GetScriptingVars() as $k => $v) {
                 $variables[$k] = $event->{$v};
             }
             if (isset($event->params) && is_array($event->params)) {
                 foreach ($event->params as $k => $v) {
                     $variables[$k] = $v;
                 }
             }
             $variables['event_name'] = $event->GetName();
         }
         $formats = \Scalr::config("scalr.system.global_variables.format");
         foreach ($variables as $name => $value) {
             $name = "SCALR_" . strtoupper($name);
             $value = trim($value);
             if (isset($formats[$name])) {
                 $value = @sprintf($formats[$name], $value);
             }
             $private = strpos($name, 'SCALR_EVENT_') === 0 ? 1 : 0;
             $retval[] = (object) array('name' => $name, 'value' => $value, 'private' => $private, 'system' => 1);
         }
     }
     try {
         $globalVariables = new Scalr_Scripting_GlobalVariables($dbServer->GetEnvironmentObject()->clientId, $dbServer->envId, ScopeInterface::SCOPE_SERVER);
         $vars = $globalVariables->listVariables($dbServer->GetFarmRoleObject()->RoleID, $dbServer->farmId, $dbServer->farmRoleId, $dbServer->serverId);
         foreach ($vars as $v) {
             $retval[] = (object) $v;
         }
     } catch (Exception $e) {
     }
     return $retval;
 }
Ejemplo n.º 13
0
 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_NewMasterUp;
     $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;
     if ($put) {
         $environment = $DBServer->GetEnvironmentObject();
         $accessData = new stdClass();
         $accessData->username = $environment->getPlatformConfigValue(self::USERNAME, true, $DBServer->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION));
         $accessData->password = $environment->getPlatformConfigValue(self::API_KEY, true, $DBServer->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION));
         $accessData->authUrl = $environment->getPlatformConfigValue(self::API_URL, true, $DBServer->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION));
         $accessData->projectId = $environment->getPlatformConfigValue(self::PROJECT_NAME, true, $DBServer->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION));
         $accessData->cloudLocation = $DBServer->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION);
         $message->platformAccessData = $accessData;
     }
 }
Ejemplo n.º 14
0
 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_NewMasterUp;
     $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;
     if ($put) {
         $environment = $DBServer->GetEnvironmentObject();
         $accessData = new stdClass();
         $accessData->username = $environment->getPlatformConfigValue(self::USERNAME, true, $DBServer->GetProperty(RACKSPACE_SERVER_PROPERTIES::DATACENTER));
         $accessData->apiKey = $environment->getPlatformConfigValue(self::API_KEY, true, $DBServer->GetProperty(RACKSPACE_SERVER_PROPERTIES::DATACENTER));
         switch ($DBServer->GetProperty(RACKSPACE_SERVER_PROPERTIES::DATACENTER)) {
             case 'rs-ORD1':
                 $accessData->authHost = 'auth.api.rackspacecloud.com';
                 break;
             case 'rs-LONx':
                 $accessData->authHost = 'lon.auth.api.rackspacecloud.com';
                 break;
         }
         $message->platformAccessData = $accessData;
     }
 }
Ejemplo n.º 15
0
 public function PutAccessData(DBServer $DBServer, Scalr_Messaging_Msg $message)
 {
     $put = false;
     $put |= $message instanceof Scalr_Messaging_Msg_Rebundle;
     $put |= $message instanceof Scalr_Messaging_Msg_BeforeHostUp;
     $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_BeforeHostTerminate;
     $put |= $message instanceof Scalr_Messaging_Msg_DbMsr_PromoteToMaster;
     $put |= $message instanceof Scalr_Messaging_Msg_DbMsr_CreateDataBundle;
     $put |= $message instanceof Scalr_Messaging_Msg_DbMsr_CreateBackup;
     $put |= $message instanceof Scalr_Messaging_Msg_DbMsr_NewMasterUp;
     if ($put) {
         $environment = $DBServer->GetEnvironmentObject();
         $message->platformAccessData = $this->GetPlatformAccessData($environment, $DBServer);
     }
 }
Ejemplo n.º 16
0
 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;
     }
 }
Ejemplo n.º 17
0
 private function onHello($message, DBServer $dbserver)
 {
     if ($dbserver->status == SERVER_STATUS::TEMPORARY) {
         $bundleTask = BundleTask::LoadById($dbserver->GetProperty(SERVER_PROPERTIES::SZR_IMPORTING_BUNDLE_TASK_ID));
         $bundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::PENDING;
         $bundleTask->Log("Received Hello message from scalarizr on server. Creating image");
         $bundleTask->osFamily = $message->dist->distributor;
         $bundleTask->osName = $message->dist->codename;
         $bundleTask->osVersion = $message->dist->release;
         if (in_array($message->dist->distributor, array('redhat', 'oel', 'scientific')) && $dbserver->platform == SERVER_PLATFORMS::EC2) {
             $bundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
         }
         $bundleTask->save();
     }
     if ($dbserver->status == SERVER_STATUS::IMPORTING) {
         if (!$dbserver->remoteIp || !$dbserver->localIp) {
             if (!$dbserver->remoteIp && $message->remoteIp && $dbserver->platform != SERVER_PLATFORMS::IDCF) {
                 $dbserver->remoteIp = $message->remoteIp;
             }
             if (!$dbserver->localIp && $message->localIp) {
                 $dbserver->localIp = $message->localIp;
             }
             if (!$message->behaviour) {
                 $message->behaviour = array('base');
             }
             if ((!$dbserver->remoteIp || $dbserver->localIp == $dbserver->remoteIp) && $message->messageIpAddress != $dbserver->remoteIp) {
                 $dbserver->remoteIp = $message->messageIpAddress;
             }
         }
         if (count($message->behaviour) == 1 && $message->behaviour[0] == ROLE_BEHAVIORS::CHEF) {
             $message->behaviour[] = ROLE_BEHAVIORS::BASE;
         }
         $dbserver->SetProperty(SERVER_PROPERTIES::SZR_IMPORTING_BEHAVIOR, @implode(",", $message->behaviour));
         $dbserver->save();
         $importVersion = $dbserver->GetProperty(SERVER_PROPERTIES::SZR_IMPORTING_VERSION);
         if ($importVersion == 2) {
             $dbserver->SetProperties(array(SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
         } else {
             if ($dbserver->isOpenstack()) {
                 $env = $dbserver->GetEnvironmentObject();
                 $os = $env->openstack($dbserver->platform, $dbserver->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION));
                 $csServer = null;
                 $list = $os->servers->list(true);
                 do {
                     foreach ($list as $_tmp) {
                         $ipaddresses = array();
                         if (!is_array($_tmp->addresses)) {
                             $_tmp->addresses = (array) $_tmp->addresses;
                         }
                         foreach ($_tmp->addresses as $net => $addresses) {
                             foreach ($addresses as $addr) {
                                 if ($addr->version == 4) {
                                     array_push($ipaddresses, $addr->addr);
                                 }
                             }
                         }
                         if ($_tmp->accessIPv4) {
                             array_push($ipaddresses, $_tmp->accessIPv4);
                         }
                         if (in_array($dbserver->localIp, $ipaddresses) || in_array($dbserver->remoteIp, $ipaddresses)) {
                             $osServer = $_tmp;
                         }
                     }
                 } while (false !== ($list = $list->getNextPage()));
                 if (!$osServer) {
                     $this->logger->error(sprintf("Server not found on Openstack (server_id: %s, remote_ip: %s, local_ip: %s)", $dbserver->serverId, $dbserver->remoteIp, $dbserver->localIp));
                     return;
                 }
                 $dbserver->SetProperties(array(OPENSTACK_SERVER_PROPERTIES::SERVER_ID => $osServer->id, OPENSTACK_SERVER_PROPERTIES::NAME => $osServer->name, OPENSTACK_SERVER_PROPERTIES::IMAGE_ID => $osServer->image->id, OPENSTACK_SERVER_PROPERTIES::FLAVOR_ID => $osServer->flavor->id, OPENSTACK_SERVER_PROPERTIES::HOST_ID => $osServer->hostId, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
             } elseif ($dbserver->isCloudstack()) {
                 $dbserver->SetProperties(array(CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID => $message->cloudstack->instanceId, CLOUDSTACK_SERVER_PROPERTIES::CLOUD_LOCATION => $message->cloudstack->availZone, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
             } else {
                 switch ($dbserver->platform) {
                     case SERVER_PLATFORMS::EC2:
                         $dbserver->SetProperties(array(EC2_SERVER_PROPERTIES::AMIID => $message->awsAmiId, EC2_SERVER_PROPERTIES::INSTANCE_ID => $message->awsInstanceId, EC2_SERVER_PROPERTIES::INSTANCE_TYPE => $message->awsInstanceType, EC2_SERVER_PROPERTIES::AVAIL_ZONE => $message->awsAvailZone, EC2_SERVER_PROPERTIES::REGION => substr($message->awsAvailZone, 0, -1), SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                         break;
                     case SERVER_PLATFORMS::EUCALYPTUS:
                         $dbserver->SetProperties(array(EUCA_SERVER_PROPERTIES::EMIID => $message->awsAmiId, EUCA_SERVER_PROPERTIES::INSTANCE_ID => $message->awsInstanceId, EUCA_SERVER_PROPERTIES::INSTANCE_TYPE => $message->awsInstanceType, EUCA_SERVER_PROPERTIES::AVAIL_ZONE => $message->awsAvailZone, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                         break;
                     case SERVER_PLATFORMS::GCE:
                         $dbserver->SetProperties(array(GCE_SERVER_PROPERTIES::CLOUD_LOCATION => $message->{$dbserver->platform}->cloudLocation, GCE_SERVER_PROPERTIES::SERVER_ID => $message->{$dbserver->platform}->serverId, GCE_SERVER_PROPERTIES::SERVER_NAME => $message->{$dbserver->platform}->serverName, GCE_SERVER_PROPERTIES::MACHINE_TYPE => $message->{$dbserver->platform}->machineType, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                         break;
                     case SERVER_PLATFORMS::NIMBULA:
                         $dbserver->SetProperties(array(NIMBULA_SERVER_PROPERTIES::NAME => $message->serverName, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                         break;
                     case SERVER_PLATFORMS::RACKSPACE:
                         $env = $dbserver->GetEnvironmentObject();
                         $cs = Scalr_Service_Cloud_Rackspace::newRackspaceCS($env->getPlatformConfigValue(RackspacePlatformModule::USERNAME, true, $dbserver->GetProperty(RACKSPACE_SERVER_PROPERTIES::DATACENTER)), $env->getPlatformConfigValue(RackspacePlatformModule::API_KEY, true, $dbserver->GetProperty(RACKSPACE_SERVER_PROPERTIES::DATACENTER)), $dbserver->GetProperty(RACKSPACE_SERVER_PROPERTIES::DATACENTER));
                         $csServer = null;
                         $list = $cs->listServers(true);
                         if ($list) {
                             foreach ($list->servers as $_tmp) {
                                 if ($_tmp->addresses->public && in_array($message->remoteIp, $_tmp->addresses->public)) {
                                     $csServer = $_tmp;
                                 }
                             }
                         }
                         if (!$csServer) {
                             $this->logger->error(sprintf("Server not found on CloudServers (server_id: %s, remote_ip: %s, local_ip: %s)", $dbserver->serverId, $message->remoteIp, $message->localIp));
                             return;
                         }
                         $dbserver->SetProperties(array(RACKSPACE_SERVER_PROPERTIES::SERVER_ID => $csServer->id, RACKSPACE_SERVER_PROPERTIES::NAME => $csServer->name, RACKSPACE_SERVER_PROPERTIES::IMAGE_ID => $csServer->imageId, RACKSPACE_SERVER_PROPERTIES::FLAVOR_ID => $csServer->flavorId, RACKSPACE_SERVER_PROPERTIES::HOST_ID => $csServer->hostId, SERVER_PROPERTIES::ARCHITECTURE => $message->architecture));
                         break;
                 }
             }
         }
         //TODO: search for existing bundle task
         // Bundle image
         $creInfo = new ServerSnapshotCreateInfo($dbserver, $dbserver->GetProperty(SERVER_PROPERTIES::SZR_IMPORTING_ROLE_NAME), SERVER_REPLACEMENT_TYPE::NO_REPLACE);
         $bundleTask = BundleTask::Create($creInfo);
         $bundleTask->osFamily = $message->dist->distributor;
         $bundleTask->osName = $message->dist->codename;
         $bundleTask->osVersion = $message->dist->release;
         if (in_array($message->dist->distributor, array('oel', 'redhat', 'scientific')) && $dbserver->platform == SERVER_PLATFORMS::EC2) {
             $bundleTask->bundleType = SERVER_SNAPSHOT_CREATION_TYPE::EC2_EBS_HVM;
         }
         $bundleTask->setDate("started");
         $bundleTask->createdByEmail = $dbserver->GetProperty(SERVER_PROPERTIES::LAUNCHED_BY_EMAIL);
         $bundleTask->createdById = $dbserver->GetProperty(SERVER_PROPERTIES::LAUNCHED_BY_ID);
         if ($importVersion == 2) {
             $bundleTask->status = SERVER_SNAPSHOT_CREATION_STATUS::ESTABLISHING_COMMUNICATION;
         }
         $bundleTask->Save();
         $dbserver->SetProperty(SERVER_PROPERTIES::SZR_IMPORTING_BUNDLE_TASK_ID, $bundleTask->id);
     }
 }
Ejemplo n.º 18
0
 private function openstackSetFloatingIp(DBServer $DBServer)
 {
     $ipPool = $DBServer->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_OPENSTACK_IP_POOL);
     if (!$DBServer->remoteIp && in_array($DBServer->status, array(SERVER_STATUS::PENDING, SERVER_STATUS::INIT, SERVER_STATUS::SUSPENDED)) && $ipPool) {
         //$ipAddress = \Scalr\Modules\Platforms\Openstack\Helpers\OpenstackHelper::setFloatingIpForServer($DBServer);
         $osClient = $DBServer->GetEnvironmentObject()->openstack($DBServer->platform, $DBServer->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION));
         if ($osClient->hasService('network')) {
             $platform = PlatformFactory::NewPlatform($DBServer->platform);
             $serverIps = $platform->GetServerIPAddresses($DBServer);
             /********* USE Quantum (Neuron) NETWORK *******/
             $ips = $osClient->network->floatingIps->list();
             //Check free existing IP
             $ipAssigned = false;
             $ipAddress = false;
             $ipInfo = false;
             foreach ($ips as $ip) {
                 if ($ip->fixed_ip_address == $serverIps['localIp'] && $ip->port_id) {
                     $ipAssigned = true;
                     $ipInfo = $ip;
                     break;
                 }
                 if (!$ip->fixed_ip_address && $ip->floating_ip_address && !$ip->port_id) {
                     $ipInfo = $ip;
                 }
             }
             if ($ipInfo) {
                 Logger::getLogger("Openstack")->warn(new FarmLogMessage($DBServer->farmId, "Found free floating IP: {$ipInfo->floating_ip_address} for use (" . json_encode($ipInfo) . ")"));
             }
             if (!$ipInfo || !$ipAssigned) {
                 // Get instance port
                 $ports = $osClient->network->ports->list();
                 foreach ($ports as $port) {
                     /* */
                     if ($port->device_id == $DBServer->GetProperty(OPENSTACK_SERVER_PROPERTIES::SERVER_ID)) {
                         $serverNetworkPort[] = $port;
                     }
                 }
                 if (count($serverNetworkPort) == 0) {
                     Logger::getLogger("Openstack")->error(new FarmLogMessage($DBServer->farmId, "Unable to identify network port of instance"));
                 } else {
                     $publicNetworkId = $ipPool;
                     while (count($serverNetworkPort) > 0) {
                         try {
                             $port = array_shift($serverNetworkPort);
                             if (!$ipInfo) {
                                 $ipInfo = $osClient->network->floatingIps->create($publicNetworkId, $port->id);
                                 Logger::getLogger("Openstack")->warn(new FarmLogMessage($DBServer->farmId, "Allocated new IP {$ipInfo->floating_ip_address} for port: {$port->id}"));
                             } else {
                                 $osClient->network->floatingIps->update($ipInfo->id, $port->id);
                                 Logger::getLogger("Openstack")->warn(new FarmLogMessage($DBServer->farmId, "Existing floating IP {$ipInfo->floating_ip_address} was used for port: {$port->id}"));
                             }
                             $DBServer->SetProperties(array(OPENSTACK_SERVER_PROPERTIES::FLOATING_IP => $ipInfo->floating_ip_address, OPENSTACK_SERVER_PROPERTIES::FLOATING_IP_ID => $ipInfo->id));
                             $ipAddress = $ipInfo->floating_ip_address;
                             break;
                         } catch (Exception $e) {
                             $this->logger->error("Scalr unable to allocate new floating IP from pool: " . $e->getMessage());
                         }
                     }
                 }
             } else {
                 Logger::getLogger("Openstack")->warn(new FarmLogMessage($DBServer->farmId, "IP: {$ipInfo->floating_ip_address} already assigned"));
                 $ipAddress = $ipInfo->floating_ip_address;
             }
         } else {
             /********* USE NOVA NETWORK *******/
             //Check free existing IP
             $ipAssigned = false;
             $ipAddress = false;
             $ips = $osClient->servers->floatingIps->list($ipPool);
             foreach ($ips as $ip) {
                 //if (!$ip->instance_id) {
                 //	$ipAddress = $ip->ip;
                 //}
                 if ($ip->instance_id == $DBServer->GetProperty(OPENSTACK_SERVER_PROPERTIES::SERVER_ID)) {
                     $ipAddress = $ip->ip;
                     $ipAssigned = true;
                 }
             }
             //If no free IP allocate new from pool
             if (!$ipAddress) {
                 $ip = $osClient->servers->floatingIps->create($ipPool);
                 $ipAddress = $ip->ip;
                 $DBServer->SetProperties(array(OPENSTACK_SERVER_PROPERTIES::FLOATING_IP => $ip->ip, OPENSTACK_SERVER_PROPERTIES::FLOATING_IP_ID => $ip->id));
             }
             if (!$ipAssigned) {
                 //Associate floating IP with Instance
                 $osClient->servers->addFloatingIp($DBServer->GetCloudServerID(), $ipAddress);
             }
         }
         if ($ipAddress) {
             $DBServer->remoteIp = $ipAddress;
             $DBServer->Save();
             $DBServer->SetProperty(SERVER_PROPERTIES::SYSTEM_IGNORE_INBOUND_MESSAGES, null);
         }
     }
 }
Ejemplo n.º 19
0
 public function LaunchServer(DBServer $DBServer, Scalr_Server_LaunchOptions $launchOptions = null)
 {
     $RDSClient = $this->getRdsClient($DBServer->GetEnvironmentObject(), $DBServer->GetProperty(RDS_SERVER_PROPERTIES::REGION));
     $DBRole = DBRole::loadById($DBServer->roleId);
     $server_id = "scalr-{$DBServer->serverId}";
     $avail_zone = $DBServer->GetProperty(RDS_SERVER_PROPERTIES::AVAIL_ZONE) ? $DBServer->GetProperty(RDS_SERVER_PROPERTIES::AVAIL_ZONE) : $DBServer->GetProperty(RDS_SERVER_PROPERTIES::REGION) . "a";
     try {
         if ($DBRole->getImageId(SERVER_PLATFORMS::RDS, $DBServer->GetProperty(RDS_SERVER_PROPERTIES::REGION)) == 'ScalrEmpty') {
             $RDSClient->CreateDBInstance($server_id, $DBServer->GetProperty(RDS_SERVER_PROPERTIES::STORAGE), $DBServer->GetProperty(RDS_SERVER_PROPERTIES::INSTANCE_CLASS), $DBServer->GetProperty(RDS_SERVER_PROPERTIES::INSTANCE_ENGINE), $DBServer->GetProperty(RDS_SERVER_PROPERTIES::MASTER_USER), $DBServer->GetProperty(RDS_SERVER_PROPERTIES::MASTER_PASS), $DBServer->GetProperty(RDS_SERVER_PROPERTIES::PORT), null, null, null, $avail_zone, null, null, null);
         } else {
             $RDSClient->RestoreDBInstanceFromDBSnapshot($DBRole->getImageId(SERVER_PLATFORMS::RDS, $DBServer->GetProperty(RDS_SERVER_PROPERTIES::REGION)), $server_id, $DBServer->GetProperty(RDS_SERVER_PROPERTIES::INSTANCE_CLASS), $DBServer->GetProperty(RDS_SERVER_PROPERTIES::PORT), $DBServer->GetProperty(RDS_SERVER_PROPERTIES::AVAIL_ZONE));
         }
         $DBServer->SetProperty(RDS_SERVER_PROPERTIES::INSTANCE_ID, $server_id);
         $DBServer->SetProperty(RDS_SERVER_PROPERTIES::SNAPSHOT_ID, $DBRole->getImageId(SERVER_PLATFORMS::RDS, $DBServer->GetProperty(RDS_SERVER_PROPERTIES::REGION)));
         return $DBServer;
     } catch (Exception $e) {
         throw new Exception(sprintf(_("Cannot launch new instance. %s"), $e->getMessage()));
     }
 }
Ejemplo n.º 20
0
 private function onHostInit($message, DBServer $dbserver)
 {
     if ($dbserver->status == SERVER_STATUS::PENDING) {
         // Update server crypto key
         $srv_props = array();
         if ($message->cryptoKey) {
             $srv_props[SERVER_PROPERTIES::SZR_KEY] = trim($message->cryptoKey);
             $srv_props[SERVER_PROPERTIES::SZR_KEY_TYPE] = SZR_KEY_TYPE::PERMANENT;
         }
         if ($dbserver->platform != SERVER_PLATFORMS::CLOUDSTACK) {
             $srv_props[SERVER_PROPERTIES::SZR_SNMP_PORT] = $message->snmpPort;
             $remoteIp = $message->remoteIp;
         } else {
             if ($dbserver->farmRoleId) {
                 $dbFarmRole = $dbserver->GetFarmRoleObject();
                 $networkType = $dbFarmRole->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_NETWORK_TYPE);
                 if ($networkType == 'Direct') {
                     $remoteIp = $message->localIp;
                     $srv_props[SERVER_PROPERTIES::SZR_SNMP_PORT] = $message->snmpPort;
                 } else {
                     $env = $dbserver->GetEnvironmentObject();
                     $remoteIp = $env->getPlatformConfigValue(Modules_Platforms_Cloudstack::SHARED_IP . "." . $dbserver->GetProperty(CLOUDSTACK_SERVER_PROPERTIES::CLOUD_LOCATION), false);
                 }
             } else {
                 $remoteIp = $message->localIp;
                 $srv_props[SERVER_PROPERTIES::SZR_SNMP_PORT] = $message->snmpPort;
             }
         }
         //Update auto-update settings
         //TODO: Check auto-update client version
         if ($dbserver->IsSupported('0.7.225')) {
             $dbserver->SetProperties($srv_props);
             try {
                 $repo = $dbserver->GetFarmObject()->GetSetting(DBFarm::SETTING_SZR_UPD_REPOSITORY);
                 $schedule = $dbserver->GetFarmObject()->GetSetting(DBFarm::SETTING_SZR_UPD_SCHEDULE);
                 if ($repo && $schedule) {
                     $updateClient = new Scalr_Net_Scalarizr_UpdateClient($dbserver);
                     $updateClient->configure($repo, $schedule);
                 }
             } catch (Exception $e) {
             }
         }
         // MySQL specific
         $dbFarmRole = $dbserver->GetFarmRoleObject();
         if ($dbFarmRole->GetRoleObject()->hasBehavior(ROLE_BEHAVIORS::MYSQL)) {
             $master = $dbFarmRole->GetFarmObject()->GetMySQLInstances(true);
             // If no masters in role this server becomes it
             if (!$master[0] && !(int) $dbFarmRole->GetSetting(DbFarmRole::SETTING_MYSQL_SLAVE_TO_MASTER)) {
                 $srv_props[SERVER_PROPERTIES::DB_MYSQL_MASTER] = 1;
             }
         }
         //MSR Replication Master
         //TODO: MySQL
         if ($dbFarmRole->GetRoleObject()->getDbMsrBehavior()) {
             $servers = $dbFarmRole->GetServersByFilter(array('status' => array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING)));
             if (!$dbFarmRole->GetSetting(Scalr_Db_Msr::SLAVE_TO_MASTER)) {
                 $masterFound = false;
                 foreach ($servers as $server) {
                     if ($server->GetProperty(Scalr_Db_Msr::REPLICATION_MASTER)) {
                         $masterFound = true;
                     }
                 }
                 if (!$masterFound) {
                     $srv_props[Scalr_Db_Msr::REPLICATION_MASTER] = 1;
                 }
             } elseif ($dbFarmRole->GetSetting(Scalr_Db_Msr::SLAVE_TO_MASTER) && count($servers) == 0) {
                 $dbFarmRole->SetSetting(Scalr_Db_Msr::SLAVE_TO_MASTER, 0);
                 $srv_props[Scalr_Db_Msr::REPLICATION_MASTER] = 1;
             }
         }
         $dbserver->SetProperties($srv_props);
         return new HostInitEvent($dbserver, $message->localIp, $remoteIp, $message->sshPubKey);
     } else {
         $this->logger->error("Strange situation. Received HostInit message" . " from server '{$dbserver->serverId}' ({$message->remoteIp})" . " with state {$dbserver->status}!");
     }
 }
Ejemplo n.º 21
0
 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_NewMasterUp;
     $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;
     if ($put) {
         $environment = $DBServer->GetEnvironmentObject();
         $accessData = new stdClass();
         $accessData->username = $environment->getPlatformConfigValue(self::USERNAME);
         $accessData->apiUrl = $environment->getPlatformConfigValue(self::API_URL);
         $accessData->password = $environment->getPlatformConfigValue(self::PASSWORD);
         $message->platformAccessData = $accessData;
     }
 }
Ejemplo n.º 22
0
 /**
  * Associates IP Address to the server
  *
  * @param   \DBServer           $dbServer  \DBServer object
  * @param   string             $ipAddress Public IP address to associate with server.
  * @throws  Exception
  */
 private static function associateIpAddress(\DBServer $dbServer, $ipAddress, $allocationId = null)
 {
     $platform = PlatformFactory::NewPlatform($dbServer->platform);
     $cs = $dbServer->GetEnvironmentObject()->cloudstack($dbServer->platform);
     $assign_retries = 1;
     $retval = false;
     // Remove OLD static NAT
     if ($dbServer->remoteIp) {
         try {
             $requestObject = new ListIpAddressesData();
             $requestObject->ipaddress = $dbServer->remoteIp;
             $info = $cs->listPublicIpAddresses($requestObject);
             $info = $info[0];
             if ($info->issystem && $info->isstaticnat) {
                 $cs->firewall->disableStaticNat($info->id);
                 \Scalr::getContainer()->logger('Cloudstack_Helper')->warn("[STATIC_NAT] Removed old IP static NAT from IP: {$info->id}");
             }
         } catch (Exception $e) {
             \Scalr::getContainer()->logger('Cloudstack_Helper')->error("[STATIC_NAT] Unable to disable old static NAT: {$e->getMessage()}");
         }
     }
     $requestObject = new ListIpAddressesData();
     $requestObject->ipaddress = $ipAddress;
     $info = $cs->listPublicIpAddresses($requestObject);
     $info = $info[0];
     $oldVM = $info->virtualmachinedisplayname;
     if ($info->isstaticnat) {
         \Scalr::getContainer()->logger('Cloudstack_Helper')->warn("[STATIC_NAT] IP {$ipAddress} associated with another VM. Disabling Static NAT.");
         try {
             $result = $cs->firewall->disableStaticNat($allocationId);
             for ($i = 0; $i <= 20; $i++) {
                 $res = $cs->queryAsyncJobResult($result->jobid);
                 if ($res->jobstatus != 0) {
                     \Scalr::getContainer()->logger('Cloudstack_Helper')->warn("[STATIC_NAT] After {$i}x2 seconds, IP {$ipAddress} is free and ready to use.");
                     //UPDATING OLD SERVER
                     try {
                         $oldDbServer = \DBServer::LoadByID($oldVM);
                         $ips = $platform->GetServerIPAddresses($oldDbServer);
                         $oldDbServer->remoteIp = $ips['remoteIp'];
                         $oldDbServer->save();
                     } catch (Exception $e) {
                     }
                     break;
                 }
                 sleep(2);
             }
         } catch (Exception $e) {
             \Scalr::getContainer()->logger('Cloudstack_Helper')->error("[STATIC_NAT] Unable to disable static NAT: {$e->getMessage()}");
         }
     }
     $assignRetries = 0;
     while (true) {
         try {
             $assignRetries++;
             $cs->firewall->enableStaticNat(array('ipaddressid' => $allocationId, 'virtualmachineid' => $dbServer->GetCloudServerID()));
             $retval = true;
             break;
         } catch (Exception $e) {
             if (!stristr($e->getMessage(), "already assigned to antoher vm") || $assignRetries == 3) {
                 \Scalr::getContainer()->logger('Cloudstack_Helper')->error("[STATIC_NAT] Unable to enable static NAT ({$assignRetries}): {$e->getMessage()}");
                 throw new Exception($e->getMessage());
             } else {
                 sleep(1);
             }
         }
     }
     return $retval;
 }
Ejemplo n.º 23
0
 public function PutAccessData(DBServer $DBServer, Scalr_Messaging_Msg $message)
 {
     $put = false;
     $put |= $message instanceof Scalr_Messaging_Msg_Rebundle;
     $put |= $message instanceof Scalr_Messaging_Msg_BeforeHostUp;
     $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_BeforeHostTerminate;
     $put |= $message instanceof Scalr_Messaging_Msg_DbMsr_PromoteToMaster;
     $put |= $message instanceof Scalr_Messaging_Msg_DbMsr_CreateDataBundle;
     $put |= $message instanceof Scalr_Messaging_Msg_DbMsr_CreateBackup;
     if ($put) {
         $environment = $DBServer->GetEnvironmentObject();
         $accessData = new stdClass();
         $accessData->accountId = $environment->getPlatformConfigValue(self::ACCOUNT_ID);
         $accessData->keyId = $environment->getPlatformConfigValue(self::ACCESS_KEY);
         $accessData->key = $environment->getPlatformConfigValue(self::SECRET_KEY);
         $accessData->cert = $environment->getPlatformConfigValue(self::CERTIFICATE);
         $accessData->pk = $environment->getPlatformConfigValue(self::PRIVATE_KEY);
         $message->platformAccessData = $accessData;
     }
 }