update rm deadcode
This commit is contained in:
@@ -8,7 +8,7 @@ use App\DTOs\VirtualMachine\Rebuild\RebuildContext;
|
||||
use App\Http\Services\vCenter as VCenterService;
|
||||
use App\Models\ModuleDatastore;
|
||||
use App\Models\vCenter as VCenterModel;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Support\TlsHttpClientFactory;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use RuntimeException;
|
||||
|
||||
@@ -74,7 +74,7 @@ final class VmRebuildCloneService
|
||||
'template' => $ctx->template,
|
||||
]);
|
||||
|
||||
$response = Http::withoutVerifying()
|
||||
$response = TlsHttpClientFactory::vCenter()
|
||||
->timeout(self::CLONE_TIMEOUT)
|
||||
->connectTimeout(30)
|
||||
->withHeaders([
|
||||
@@ -121,7 +121,7 @@ final class VmRebuildCloneService
|
||||
throw new RuntimeException("Rebuild powerOn: cannot login to vCenter #{$ctx->vcenterId}");
|
||||
}
|
||||
|
||||
$powerResp = Http::withoutVerifying()
|
||||
$powerResp = TlsHttpClientFactory::vCenter()
|
||||
->timeout(self::POWER_ON_TIMEOUT)
|
||||
->withHeaders(['vmware-api-session-id' => $this->vCenter->token])
|
||||
->post("https://{$this->vCenter->apiUri}/rest/vcenter/vm/{$ctx->newVmId}/power/start");
|
||||
@@ -138,7 +138,7 @@ final class VmRebuildCloneService
|
||||
]);
|
||||
|
||||
for ($i = 1; $i <= self::TOOLS_MAX_ATTEMPTS; $i++) {
|
||||
$info = Http::withoutVerifying()
|
||||
$info = TlsHttpClientFactory::vCenter()
|
||||
->timeout(10)
|
||||
->withHeaders(['vmware-api-session-id' => $this->vCenter->token])
|
||||
->get("https://{$this->vCenter->apiUri}/rest/vcenter/vm/{$ctx->newVmId}/guest/identity")
|
||||
@@ -185,7 +185,7 @@ final class VmRebuildCloneService
|
||||
}
|
||||
|
||||
try {
|
||||
Http::withoutVerifying()
|
||||
TlsHttpClientFactory::vCenter()
|
||||
->timeout(30)
|
||||
->withHeaders(['vmware-api-session-id' => $this->vCenter->token])
|
||||
->post("https://{$this->vCenter->apiUri}/rest/vcenter/vm/{$ctx->oldVmId}/power/stop");
|
||||
|
||||
@@ -74,6 +74,53 @@ class VmIpReservationService
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reserve a specific, still-free IP within a network (customer-picked change-IP flow).
|
||||
*
|
||||
* @return array{ip_pool_id:int, gateway:string}|null
|
||||
*/
|
||||
public function reserveInNetwork(int $networkId, string $ipAddress, int $serviceId): ?array
|
||||
{
|
||||
return DB::transaction(function () use ($networkId, $ipAddress, $serviceId) {
|
||||
$ipPool = IpPool::where('module_network_id', $networkId)
|
||||
->where('ip_address', $ipAddress)
|
||||
->where('status', 'free')
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
|
||||
if (!$ipPool) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$ipPool->update(['status' => 'assigned', 'service_id' => $serviceId]);
|
||||
|
||||
return [
|
||||
'ip_pool_id' => $ipPool->id,
|
||||
'gateway' => (string) ($ipPool->gateway ?? ''),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function freeIpsInNetwork(int $networkId)
|
||||
{
|
||||
return IpPool::where('module_network_id', $networkId)
|
||||
->where('status', 'free')
|
||||
->orderBy('ip_address')
|
||||
->get(['id', 'ip_address', 'gateway']);
|
||||
}
|
||||
|
||||
public function releaseByPoolId(int $ipPoolId): void
|
||||
{
|
||||
try {
|
||||
IpPool::where('id', $ipPoolId)->update(['status' => 'free', 'service_id' => null]);
|
||||
} catch (\Throwable $e) {
|
||||
Log::warning('VmIpReservationService: releaseByPoolId failed', [
|
||||
'ip_pool_id' => $ipPoolId,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function release(ModuleIpAddress $reservation, ?int $ipPoolId): void
|
||||
{
|
||||
try {
|
||||
|
||||
@@ -5,7 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Services\VirtualMachine;
|
||||
|
||||
use App\Http\Services\vCenter;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Support\TlsHttpClientFactory;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
@@ -18,7 +18,7 @@ class VmPowerService
|
||||
return 'Login_Again';
|
||||
}
|
||||
|
||||
$response = Http::withoutVerifying()
|
||||
$response = TlsHttpClientFactory::vCenter()
|
||||
->withHeaders(['vmware-api-session-id' => $vCenter->token])
|
||||
->post("https://{$vCenter->apiUri}/rest/vcenter/vm/{$vmId}/power/start");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user