62 lines
1.8 KiB
PHP
62 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs\VirtualMachine\Create;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class GetNetworkVirtualMachine implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
protected string $vmware_id;
|
|
protected $serviceVCenter;
|
|
protected $data;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct($vmware_id, $data, $service)
|
|
{
|
|
$this->vmware_id = $vmware_id;
|
|
$this->serviceVCenter = $service;
|
|
$this->data = $data;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle()
|
|
{
|
|
|
|
$NetworkForVirtualMachine = $this->serviceVCenter->GetNetworkVirtualMachine($this->vmware_id);
|
|
|
|
if ($NetworkForVirtualMachine['error']) {
|
|
throw new \Exception(json_encode($NetworkForVirtualMachine['message']));
|
|
}
|
|
$Network = $this->data->IpAddress->Network->network;
|
|
if ($Network !== $NetworkForVirtualMachine['data']['network']) {
|
|
$ConfigNetwork = [
|
|
"spec" => [
|
|
"backing" => [
|
|
"type" => $this->data->IpAddress->Network->type,
|
|
"network" => $this->data->IpAddress->Network->network
|
|
]
|
|
]
|
|
];
|
|
$this->serviceVCenter->ConfigNetworkVirtualMachine($this->vmware_id,$ConfigNetwork);
|
|
|
|
}
|
|
|
|
$jobs_configCLI = new ConfigCLICommand($this->vmware_id,$this->data,$this->serviceVCenter);
|
|
dispatch($jobs_configCLI)->delay(now()->addSeconds(5));
|
|
}
|
|
}
|