isCloudstack() public method

public isCloudstack ( )
Ejemplo n.º 1
0
 private function onHostInit($message, DBServer $dbserver)
 {
     if ($dbserver->status == SERVER_STATUS::PENDING) {
         $platform = PlatformFactory::NewPlatform($dbserver->platform);
         // 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;
         }
         $srv_props[SERVER_PROPERTIES::SZR_SNMP_PORT] = $message->snmpPort;
         if ($dbserver->isCloudstack()) {
             $ips = $platform->GetServerIPAddresses($dbserver);
             if ($ips['remoteIp']) {
                 $remoteIp = $ips['remoteIp'];
                 $dbserver->GetFarmRoleObject()->SetSetting(DBFarmRole::SETTING_CLOUDSTACK_NETWORK_TYPE, 'Direct', DBFarmRole::TYPE_LCL);
             } else {
                 if ($dbserver->farmRoleId) {
                     $dbFarmRole = $dbserver->GetFarmRoleObject();
                     $networkType = $dbFarmRole->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_NETWORK_TYPE);
                     if ($networkType == 'Direct') {
                         $remoteIp = $message->localIp;
                     } else {
                         $useStaticNat = $dbFarmRole->GetSetting(DBFarmRole::SETIING_CLOUDSTACK_USE_STATIC_NAT);
                         if (!$useStaticNat) {
                             $sharedIp = $dbFarmRole->GetSetting(DBFarmRole::SETTING_CLOUDSTACK_SHARED_IP_ADDRESS);
                             if (!$sharedIp) {
                                 $env = $dbserver->GetEnvironmentObject();
                                 $remoteIp = $platform->getConfigVariable(CloudstackPlatformModule::SHARED_IP . "." . $dbserver->GetProperty(CLOUDSTACK_SERVER_PROPERTIES::CLOUD_LOCATION), $env, false);
                             } else {
                                 $remoteIp = $sharedIp;
                             }
                         }
                     }
                 }
             }
         }
         if ($dbserver->isOpenstack()) {
             if ($dbserver->farmRoleId) {
                 $ipPool = $dbserver->GetFarmRoleObject()->GetSetting(DBFarmRole::SETTING_OPENSTACK_IP_POOL);
                 if ($ipPool && empty($dbserver->remoteIp)) {
                     return false;
                 } else {
                     $remoteIp = $dbserver->remoteIp;
                 }
             }
         }
         if (!$remoteIp) {
             $ips = $platform->GetServerIPAddresses($dbserver);
             if ($ips['remoteIp']) {
                 $remoteIp = $ips['remoteIp'];
             } else {
                 $remoteIp = $message->remoteIp ? $ips['remoteIp'] : '';
             }
         }
         $dbserver->remoteIp = $remoteIp;
         $dbserver->Save();
         //Update auto-update settings
         //TODO: Check auto-update client version
         if ($dbserver->IsSupported('0.7.225') && !$dbserver->IsSupported('2.7.10')) {
             $dbserver->SetProperties($srv_props);
             try {
                 $repo = $dbserver->GetFarmRoleObject()->GetSetting(Scalr_Role_Behavior::ROLE_BASE_SZR_UPD_REPOSITORY);
                 if (!$repo) {
                     $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, DBFarmRole::TYPE_LCL);
                 $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}!");
         */
         //TOOD: Check if instance terminating we probably can cancel termination and continue initialization
     }
 }