本文整理汇总了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;
}
示例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;
}
示例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");
}
}