public static function cleanupServerObjects(\DBServer $dbServer)
{
$env = $dbServer->GetEnvironmentObject();
$azure = $env->azure();
// Remove NIC
$nic = $dbServer->GetProperty(\AZURE_SERVER_PROPERTIES::NETWORK_INTERFACE);
if ($nic) {
try {
$res1 = $azure->network->interface->delete($env->keychain(SERVER_PLATFORMS::AZURE)->properties[Entity\CloudCredentialsProperty::AZURE_SUBSCRIPTION_ID], $dbServer->GetProperty(\AZURE_SERVER_PROPERTIES::RESOURCE_GROUP), $nic);
} catch (\Exception $e) {
\Scalr::getContainer()->logger(\LOG_CATEGORY::FARM)->error(new \FarmLogMessage($dbServer, sprintf(_("Unable to remove NIC object on server termination: %s"), $e->getMessage())));
}
}
// Remove Public IP
$publicIpName = $dbServer->GetProperty(\AZURE_SERVER_PROPERTIES::PUBLIC_IP_NAME);
if ($publicIpName) {
try {
$res2 = $azure->network->publicIPAddress->delete($env->keychain(SERVER_PLATFORMS::AZURE)->properties[Entity\CloudCredentialsProperty::AZURE_SUBSCRIPTION_ID], $dbServer->GetProperty(\AZURE_SERVER_PROPERTIES::RESOURCE_GROUP), $publicIpName);
} catch (\Exception $e) {
\Scalr::getContainer()->logger(\LOG_CATEGORY::FARM)->error(new \FarmLogMessage($dbServer, sprintf(_("Unable to remove PublicIP object on server termination: %s"), $e->getMessage())));
}
}
}