Update source into github
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\VirtualMachine\Upgrade;
|
||||
|
||||
use App\Http\Services\Telegram;
|
||||
use App\Http\Services\vCenter as ServiceVCenter;
|
||||
use App\Jobs\Throwable;
|
||||
use App\Models\ModuleVmware;
|
||||
use Exception;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class UpgradeCPU implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected int $cpu;
|
||||
protected int $product = 0;
|
||||
protected $telegram;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($product = 0, $cpu = 0)
|
||||
{
|
||||
$this->cpu = $cpu;
|
||||
$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->UpgradeCPUVirtualMachine($product->vmware_id, $this->cpu);
|
||||
|
||||
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->UpgradeCPUVirtualMachine($product->vmware_id, $this->cpu);
|
||||
|
||||
}
|
||||
if ($StatusVirtualMachine['error']) {
|
||||
throw new Exception(json_encode($StatusVirtualMachine['data']));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function failed(Throwable $exception)
|
||||
{
|
||||
$this->telegram->SendErrorMessage($exception->getMessage());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user