feat: Implement VM console access, display VM power state, and add VM statistics retrieval.

This commit is contained in:
pbao9
2026-02-14 16:28:13 +07:00
parent 449502e290
commit 498a57b499
6 changed files with 610 additions and 23 deletions
@@ -1,6 +1,68 @@
<div class="d-flex gap-2">
<x-button-crm type="button" variant="primary" size="sm" route="package.vm.edit" :params="['id' => $row->id]"
icon="pencil">Edit</x-button-crm>
<x-button-crm type="button" variant="danger" size="sm" route="package.vm.destroy" :params="['id' => $row->id]"
icon="trash">Delete</x-button-crm>
<div class="dt-action-dropdown dropdown">
<button class="btn btn-sm btn-light d-flex align-items-center gap-1" type="button" data-bs-toggle="dropdown"
aria-expanded="false">
<i data-lucide="more-vertical" width="14" height="14"></i>
</button>
<ul class="dropdown-menu dropdown-menu-end">
<li>
<a class="dropdown-item" href="{{ route('package.vm.edit', ['id' => $row->id]) }}">
<i data-lucide="eye" width="14" height="14" class="me-2"></i>
View
</a>
</li>
<li>
<a class="dropdown-item" href="{{ route('package.vm.edit', ['id' => $row->id]) }}">
<i data-lucide="pencil" width="14" height="14" class="me-2"></i>
Edit
</a>
</li>
@if($row->power_state == 'POWERED_ON')
<li>
<a class="dropdown-item" href="{{ route('admin.vm.console', ['vm_id' => $row->vm_id]) }}" target="_blank">
<i data-lucide="monitor" width="14" height="14" class="me-2"></i>
Console
</a>
</li>
@else
<li>
<span class="dropdown-item disabled">
<i data-lucide="monitor" width="14" height="14" class="me-2"></i>
Console (Off)
</span>
</li>
@endif
<li>
<hr class="dropdown-divider">
</li>
<li>
<button type="button" class="dropdown-item text-danger" data-bs-toggle="modal" data-bs-target="#deleteModal{{ $row->id }}">
<i data-lucide="trash-2" width="14" height="14" class="me-2 text-danger"></i>
Delete
</button>
</li>
</ul>
</div>
<div class="modal fade" id="deleteModal{{ $row->id }}" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<form action="{{ route('package.vm.destroy', ['id' => $row->id]) }}" method="POST" class="d-inline">
@csrf
@method('DELETE')
<input type="hidden" name="id" value="{{ $row->id }}">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Delete VM</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
Are you sure you want to delete this VM?
<strong>{{ $row->name ?? $row->vm_id }}</strong>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-danger">Delete</button>
</div>
</div>
</form>
</div>
</div>
@@ -1,46 +1,92 @@
@extends("administrator.layout.master")
@section('breadcrumb')
@php
$breadcrumbItems = [
['label' => 'Modules'],
['label' => 'Package vCenter'],
['label' => 'Virtual Machine', 'route' => 'package.vm.index'],
['label' => $vm->name ?? $vm->vm_id ?? 'Edit', 'active' => true],
];
@endphp
<x-admin-breadcrumb :items="$breadcrumbItems" />
@endsection
@section("content")
@if(auth()->guard('admins')->user()->can("add module vcenter"))
<div class="card card-outline card-primary">
<form action="{{ route('package.host.update',['id' => $host->id]) }}" method="post">
<form action="{{ route('package.vm.update',['id' => $vm->id]) }}" method="post">
@csrf
@method('put')
<div class="card-body">
<x-module.v-center :model="$host->datacenter" />
<x-module.datacenter :model="$host" />
{{--Name--}}
<div class="row form-group align-items-center mb-0">
<label for="name" class="col-md-3 text-right">Name</label>
<div class="col-md-9 p-1 bg-customer">
<input type="text" id="name" name="name" placeholder="" value="{{ $host->name}}" class="form-control">
<input type="text" id="name" name="name" placeholder="" value="{{ $vm->name}}" class="form-control">
</div>
</div>
{{--Host ID--}}
{{--VM ID--}}
<div class="row form-group align-items-center mb-0">
<label for="host_id" class="col-md-3 text-right">Host ID</label>
<label for="vm_id" class="col-md-3 text-right">VM ID</label>
<div class="col-md-9 p-1 bg-customer">
<input type="text" id="host_id" name="host_id" placeholder="" value="{{ $host->host_id}}" class="form-control">
<input type="text" id="vm_id" name="vm_id" placeholder="" value="{{ $vm->vm_id}}" class="form-control">
</div>
</div>
{{--Template ID--}}
{{--Power State--}}
<div class="row form-group align-items-center mb-0">
<label for="template" class="col-md-3 text-right">Template ID</label>
<label for="power_state" class="col-md-3 text-right">Power State</label>
<div class="col-md-9 p-1 bg-customer">
<input type="text" id="template" name="template" placeholder="" value="{{ $host->template}}" class="form-control">
@if($vm->power_state == 'POWERED_ON')
<span class="badge bg-success">Đang bật</span>
@elseif($vm->power_state == 'POWERED_OFF')
<span class="badge bg-secondary">Đang tắt</span>
@else
{{ $vm->power_state }}
@endif
</div>
</div>
{{--Console ID--}}
{{--CPU--}}
<div class="row form-group align-items-center mb-0">
<label for="console" class="col-md-3 text-right">Console Name</label>
<label for="cpu" class="col-md-3 text-right">CPU</label>
<div class="col-md-9 p-1 bg-customer">
<input type="text" id="console" name="console" placeholder="consolenode129.tgs.com.vn" value="{{ $host->console}}" class="form-control">
<input type="text" id="cpu" name="cpu" placeholder="" value="{{ $vm->cpu}}" class="form-control">
</div>
</div>
{{--RAM (MB)--}}
<div class="row form-group align-items-center mb-0">
<label for="ram_mb" class="col-md-3 text-right">RAM (MB)</label>
<div class="col-md-9 p-1 bg-customer">
<input type="text" id="ram_mb" name="ram_mb" placeholder="" value="{{ $vm->ram_mb}}" class="form-control">
</div>
</div>
{{--Datacenter--}}
<div class="row form-group align-items-center mb-0">
<label for="datacenter_id" class="col-md-3 text-right">Datacenter</label>
<div class="col-md-9 p-1 bg-customer">
<input type="text" id="datacenter_id" name="datacenter_id" placeholder="" value="{{ $vm->datacenter_id}}" class="form-control">
</div>
</div>
{{--Host--}}
<div class="row form-group align-items-center mb-0">
<label for="host_id" class="col-md-3 text-right">Host</label>
<div class="col-md-9 p-1 bg-customer">
<input type="text" id="host_id" name="host_id" placeholder="" value="{{ $vm->host_id}}" class="form-control">
</div>
</div>
</div>
<div class="card-footer">
<a href="{{ route('package.host.index') }}" class="btn btn-outline-secondary">Trở về</a>
<button type="submit" class="btn btn-outline-primary">Lưu dữ liệu</button>
<a href="{{ route('package.vm.index') }}" class="btn btn-secondary">Back</a>
<button type="submit" class="btn btn-primary">Save</button>
@if($vm->vm_id && $vm->power_state == 'POWERED_ON')
<a href="{{ route('admin.vm.console', ['vm_id' => $vm->vm_id]) }}" target="_blank" class="btn btn-info">
<i class="fas fa-terminal"></i> Console
</a>
@elseif($vm->vm_id)
<span class="btn btn-secondary disabled">
<i class="fas fa-terminal"></i> Console (Off)
</span>
@endif
</div>
</form>
</div>