当前位置: 首页>>代码示例>>PHP>>正文


PHP DBServer::GetCloudServerID方法代码示例

本文整理汇总了PHP中DBServer::GetCloudServerID方法的典型用法代码示例。如果您正苦于以下问题:PHP DBServer::GetCloudServerID方法的具体用法?PHP DBServer::GetCloudServerID怎么用?PHP DBServer::GetCloudServerID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DBServer的用法示例。


在下文中一共展示了DBServer::GetCloudServerID方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: associateIpAddress

 /**
  * 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;
 }
开发者ID:recipe,项目名称:scalr,代码行数:47,代码来源:Cloudstack.php

示例2: associateIpAddress

 /**
  * 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;
 }
开发者ID:scalr,项目名称:scalr,代码行数:75,代码来源:CloudstackHelper.php

示例3: GetServerConsoleOutput

 public function GetServerConsoleOutput(DBServer $DBServer)
 {
     if ($DBServer->GetRealStatus()->getName() != 'ACTIVE') {
         return false;
     }
     $client = $this->getOsClient($DBServer->GetEnvironmentObject(), $DBServer->GetProperty(OPENSTACK_SERVER_PROPERTIES::CLOUD_LOCATION));
     if ($client->servers->isExtensionSupported(ServersExtension::consoleOutput())) {
         return $client->servers->getConsoleOutput($DBServer->GetCloudServerID(), 200);
     } else {
         throw new Exception("Not supported by Openstack");
     }
 }
开发者ID:recipe,项目名称:scalr,代码行数:12,代码来源:Openstack.php


注:本文中的DBServer::GetCloudServerID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。