Add datastore_id to OS model and related functionality; update validation and relationships
This commit is contained in:
@@ -7,7 +7,6 @@ use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Http\Client\ConnectionException;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Http\Services\Discord;
|
||||
use App\Models\ModuleDatastore;
|
||||
use App\Services\VirtualMachine\VmProviderSettingsService;
|
||||
use Exception;
|
||||
|
||||
@@ -22,13 +21,16 @@ class VirtualMachineService
|
||||
$this->powerShellService = $powerShellService;
|
||||
}
|
||||
|
||||
public function getAllVirtualMachine($datacenter = '')
|
||||
public function getAllVirtualMachine($datacenter = '', $host = '')
|
||||
{
|
||||
if ($this->client->checkApiExits()) {
|
||||
$params = [];
|
||||
if (!empty($datacenter)) {
|
||||
$params['filter.datacenters'] = $datacenter;
|
||||
}
|
||||
if (!empty($host)) {
|
||||
$params['filter.hosts'] = $host;
|
||||
}
|
||||
|
||||
$response = Http::withoutVerifying()
|
||||
->withHeaders([
|
||||
@@ -81,10 +83,11 @@ class VirtualMachineService
|
||||
/** @var VmProviderSettingsService $providerSettings */
|
||||
$providerSettings = app(VmProviderSettingsService::class);
|
||||
|
||||
$activeDatastore = ModuleDatastore::where('module_host_id', $host->id)
|
||||
->where('status', 1)
|
||||
->first();
|
||||
$datastoreId = $activeDatastore?->datastore ?? $providerSettings->defaultDatastore();
|
||||
$datastore = $product_data['datastore'] ?? null;
|
||||
if (!$datastore) {
|
||||
throw new Exception("Host id={$host->id} chưa có datastore active để tạo VM.");
|
||||
}
|
||||
$datastoreId = $datastore->datastore;
|
||||
|
||||
$body = [
|
||||
'spec' => [
|
||||
|
||||
Reference in New Issue
Block a user