feat: Implement VM restart, auto-renew invoice functionality, and client invoice detail API, alongside admin UI improvements.
This commit is contained in:
@@ -1522,6 +1522,62 @@ PS;
|
||||
return "Login_Again";
|
||||
}
|
||||
|
||||
public function restartVM($product, $vmware_id = ''): array|string
|
||||
{
|
||||
try {
|
||||
$vmId = $vmware_id ?: ($product->vmware_id ?? null);
|
||||
if (!$vmId) {
|
||||
return [
|
||||
'error' => true,
|
||||
'data' => 'Không tìm thấy vmware_id',
|
||||
];
|
||||
}
|
||||
|
||||
// Ưu tiên quan hệ trực tiếp trên ModuleVmware
|
||||
$vcenter = $product->vCenter ?? null;
|
||||
|
||||
// Fallback cho dữ liệu cũ chưa có vcenter_id
|
||||
if (!$vcenter && isset($product->ipAddress) && $product->ipAddress?->host?->datacenter?->vCenter) {
|
||||
$vcenter = $product->ipAddress->host->datacenter->vCenter;
|
||||
}
|
||||
|
||||
if (!$vcenter) {
|
||||
return [
|
||||
'error' => true,
|
||||
'data' => 'Không tìm thấy thông tin vCenter cho VM',
|
||||
];
|
||||
}
|
||||
|
||||
$check = $this->loginServer($vcenter);
|
||||
if (!$check) {
|
||||
return "Login_Again";
|
||||
}
|
||||
|
||||
$response = Http::withoutVerifying()
|
||||
->withHeaders([
|
||||
'vmware-api-session-id' => $this->token
|
||||
])
|
||||
->post("https://$this->apiUri/rest/vcenter/vm/$vmId/guest/power?action=reboot");
|
||||
|
||||
if ($response->status() === 200) {
|
||||
return [
|
||||
'error' => false,
|
||||
'data' => 'success'
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'error' => true,
|
||||
'data' => $response->json('value') ?? $response->body(),
|
||||
];
|
||||
} catch (\Throwable $e) {
|
||||
return [
|
||||
'error' => true,
|
||||
'data' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function StartVirtualMachine($product, $vmware_id = ''): array|string
|
||||
{
|
||||
|
||||
@@ -1617,7 +1673,7 @@ PS;
|
||||
return "Login_Again";
|
||||
}
|
||||
|
||||
public function CreateSnapShot($product): string|array
|
||||
public function CreateSnapShot($product, ?string $snapshotName = null): string|array
|
||||
{
|
||||
try {
|
||||
$this->username = $product->ipaddress->host->datacenter->vCenter->user;
|
||||
@@ -1632,7 +1688,7 @@ PS;
|
||||
|
||||
if ($check) {
|
||||
try {
|
||||
$Snapshot = $vmware_name . "_" . date('d_m_Y_H_i_s');
|
||||
$Snapshot = $snapshotName ?: ($vmware_name . "_" . date('d_m_Y_H_i_s'));
|
||||
|
||||
Log::channel('Custom')->info("===================================================================");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user