78 lines
2.1 KiB
PHP
78 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs\VirtualMachine\Upgrade;
|
|
|
|
use App\Http\Services\Telegram;
|
|
use App\Http\Services\vCenter as ServiceVCenter;
|
|
use App\Jobs\Exception;
|
|
use App\Jobs\Throwable;
|
|
use App\Models\ModuleVmware;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class UpgradeDisk implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
protected int $disk;
|
|
protected int $product = 0;
|
|
protected $telegram;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct($product = 0, $disk = 0)
|
|
{
|
|
$this->disk = $disk;
|
|
$this->product = $product;
|
|
$this->telegram = new Telegram;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle(ServiceVCenter $serviceVCenter)
|
|
{
|
|
$product = ModuleVmware::with([
|
|
'IpAddress.Host.Datacenter.vCenter'
|
|
])->find($this->product);
|
|
|
|
$serviceVCenter->token = $product->IpAddress->Host->Datacenter->vCenter->token;
|
|
|
|
$serviceVCenter->apiUri = $product->IpAddress->Host->Datacenter->vCenter->host;
|
|
|
|
$StatusVirtualMachine = $serviceVCenter->UpgradeDiskVirtualMachine($product, $this->disk);
|
|
|
|
if ($StatusVirtualMachine === "Login_Again") {
|
|
|
|
$token = $serviceVCenter->loginServer($product->IpAddress->Host->Datacenter->vCenter);
|
|
|
|
if ($token) {
|
|
|
|
$product->IpAddress->Host->Datacenter->vCenter->update(['token' => $token]);
|
|
|
|
$serviceVCenter->token = $token;
|
|
}
|
|
|
|
$StatusVirtualMachine = $serviceVCenter->UpgradeDiskVirtualMachine($product, $this->disk);
|
|
|
|
}
|
|
if ($StatusVirtualMachine['error']) {
|
|
throw new Exception(json_encode($StatusVirtualMachine['data']));
|
|
}
|
|
|
|
}
|
|
|
|
public function failed(Throwable $exception)
|
|
{
|
|
$this->telegram->SendErrorMessage($exception->getMessage());
|
|
}
|
|
}
|