@@ -123,6 +123,32 @@ public function toArray() {
123123 }
124124}
125125
126+ class LXC {
127+ public $ vmid ;
128+ public $ name ;
129+ public $ node ;
130+ public $ status ;
131+ public $ cores ;
132+ public $ memory ;
133+ public $ disk ;
134+ public $ uptime ;
135+ public $ cpu_usage ;
136+ public $ memory_usage ;
137+
138+ public function __construct ($ data = []) {
139+ foreach ($ data as $ key => $ value ) {
140+ if (property_exists ($ this , $ key )) {
141+ $ this ->$ key = $ value ;
142+ }
143+ }
144+ }
145+
146+ public function toArray () {
147+ return get_object_vars ($ this );
148+ }
149+ }
150+
151+
126152// VIRTUAL MAC DATA MODEL
127153class VirtualMac {
128154 public $ macAddress ;
@@ -332,6 +358,21 @@ public static function mapToVM($data) {
332358 ]);
333359 }
334360
361+ public static function mapToLXC ($ data ) {
362+ return new LXC ([
363+ 'vmid ' => $ data ['vmid ' ] ?? null ,
364+ 'name ' => $ data ['name ' ] ?? null ,
365+ 'node ' => $ data ['node ' ] ?? null ,
366+ 'status ' => $ data ['status ' ] ?? null ,
367+ 'cores ' => $ data ['cores ' ] ?? $ data ['cpus ' ] ?? null ,
368+ 'memory ' => $ data ['memory ' ] ?? $ data ['maxmem ' ] ?? null ,
369+ 'disk ' => $ data ['disk ' ] ?? $ data ['maxdisk ' ] ?? null ,
370+ 'uptime ' => $ data ['uptime ' ] ?? null ,
371+ 'cpu_usage ' => $ data ['cpu ' ] ?? null ,
372+ 'memory_usage ' => $ data ['mem ' ] ?? null
373+ ]);
374+ }
375+
335376 public static function mapToVirtualMac ($ data , $ serviceName = null , $ macAddress = null ) {
336377 return new VirtualMac ([
337378 'macAddress ' => $ macAddress ?? $ data ['macAddress ' ] ?? null ,
@@ -499,6 +540,26 @@ public function getVMs($node = null) {
499540 ////$this->logRequest('/nodes/*/qemu', 'GET', !empty($vms));
500541 return $ vms ;
501542 }
543+ public function getLXCs ($ node = null ) {
544+ $ lxcs = [];
545+ $ nodes = $ node ? [$ node ] : $ this ->getNodes ();
546+
547+ foreach ($ nodes as $ nodeData ) {
548+ $ nodeName = is_array ($ nodeData ) ? $ nodeData ['node ' ] : $ nodeData ;
549+ $ url = $ this ->host . "/api2/json/nodes/ $ nodeName/lxc " ;
550+ $ response = $ this ->makeRequest ('GET ' , $ url );
551+
552+ if ($ response && isset ($ response ['data ' ])) {
553+ foreach ($ response ['data ' ] as $ lxcData ) {
554+ $ lxcData ['node ' ] = $ nodeName ;
555+ $ lxcs [] = DataMapper::mapToLXC ($ lxcData );
556+ }
557+ }
558+ }
559+
560+ ////$this->logRequest('/nodes/*/qemu', 'GET', !empty($vms));
561+ return $ lxcs ;
562+ }
502563
503564 public function getVM ($ node , $ vmid ) {
504565 $ url = $ this ->host . "/api2/json/nodes/ $ node/qemu/ $ vmid/config " ;
@@ -664,6 +725,13 @@ public function resumeVM($node, $vmid) {
664725 return $ response ;
665726 }
666727
728+ public function rebootVM ($ node , $ vmid ) {
729+ $ url = $ this ->host . "/api2/json/nodes/ $ node/qemu/ $ vmid/status/reboot " ;
730+ $ response = $ this ->makeRequest ('POST ' , $ url );
731+ //$this->logRequest("/nodes/$node/qemu/$vmid/status/reboot", 'POST', $response !== false);
732+ return $ response ;
733+ }
734+
667735 public function cloneVM ($ node , $ vmid , $ newVmid , $ name = null ) {
668736 $ url = $ this ->host . "/api2/json/nodes/ $ node/qemu/ $ vmid/clone " ;
669737 $ data = [
@@ -676,6 +744,63 @@ public function cloneVM($node, $vmid, $newVmid, $name = null) {
676744 return $ response ;
677745 }
678746
747+ //Proxmox LXC
748+ public function createLXC ($ node , $ lxcData ) {
749+ $ url = $ this ->host . "/api2/json/nodes/ $ node/lxc " ;
750+ $ response = $ this ->makeRequest ('POST ' , $ url , $ lxcData );
751+ //$this->logRequest("/nodes/$node/lxc", 'POST', $response !== false);
752+ return $ response ;
753+ }
754+ public function editLXC ($ node , $ vmid , $ lxcData ) {
755+ $ url = $ this ->host . "/api2/json/nodes/ $ node/lxc/ $ vmid/config " ;
756+ $ response = $ this ->makeRequest ('PUT ' , $ url , $ lxcData );
757+ //$this->logRequest("/nodes/$node/lxc/$vmid/config", 'PUT', $response !== false);
758+ return $ response ;
759+ }
760+ public function deleteLXC ($ node , $ vmid ) {
761+ $ url = $ this ->host . "/api2/json/nodes/ $ node/lxc/ $ vmid " ;
762+ $ response = $ this ->makeRequest ('DELETE ' , $ url );
763+ //$this->logRequest("/nodes/$node/lxc/$vmid", 'DELETE', $response !== false);
764+ return $ response ;
765+ }
766+ public function startLXC ($ node , $ vmid ) {
767+ $ url = $ this ->host . "/api2/json/nodes/ $ node/lxc/ $ vmid/status/start " ;
768+ $ response = $ this ->makeRequest ('POST ' , $ url );
769+ //$this->logRequest("/nodes/$node/lxc/$vmid/status/start", 'POST', $response !== false);
770+ return $ response ;
771+ }
772+ public function stopLXC ($ node , $ vmid ) {
773+ $ url = $ this ->host . "/api2/json/nodes/ $ node/lxc/ $ vmid/status/stop " ;
774+ $ response = $ this ->makeRequest ('POST ' , $ url );
775+ //$this->logRequest("/nodes/$node/lxc/$vmid/status/stop", 'POST', $response !== false);
776+ return $ response ;
777+ }
778+ public function resetLXC ($ node , $ vmid ) {
779+ $ url = $ this ->host . "/api2/json/nodes/ $ node/lxc/ $ vmid/status/reset " ;
780+ $ response = $ this ->makeRequest ('POST ' , $ url );
781+ //$this->logRequest("/nodes/$node/lxc/$vmid/status/reset", 'POST', $response !== false);
782+ return $ response ;
783+ }
784+ public function suspendLXC ($ node , $ vmid ) {
785+ $ url = $ this ->host . "/api2/json/nodes/ $ node/lxc/ $ vmid/status/suspend " ;
786+ $ response = $ this ->makeRequest ('POST ' , $ url );
787+ //$this->logRequest("/nodes/$node/lxc/$vmid/status/suspend", 'POST', $response !== false);
788+ return $ response ;
789+ }
790+ public function resumeLXC ($ node , $ vmid ) {
791+ $ url = $ this ->host . "/api2/json/nodes/ $ node/lxc/ $ vmid/status/resume " ;
792+ $ response = $ this ->makeRequest ('POST ' , $ url );
793+ //$this->logRequest("/nodes/$node/lxc/$vmid/status/resume", 'POST', $response !== false);
794+ return $ response ;
795+ }
796+
797+ public function rebootLXC ($ node , $ vmid ) {
798+ $ url = $ this ->host . "/api2/json/nodes/ $ node/lxc/ $ vmid/status/reboot " ;
799+ $ response = $ this ->makeRequest ('POST ' , $ url );
800+ //$this->logRequest("/nodes/$node/lxc/$vmid/status/reboot", 'POST', $response !== false);
801+ return $ response ;
802+ }
803+
679804 // PROXMOX USER MANAGEMENt
680805 public function createProxmoxUser ($ userData ) {
681806 $ url = $ this ->host . "/api2/json/access/users " ;
@@ -3390,6 +3515,25 @@ public function getProxmoxVMs() {
33903515
33913516 return $ this ->proxmoxGet ->getVMs ();
33923517 }
3518+
3519+ public function getProxmoxLXCs () {
3520+ $ apiCheck = $ this ->checkAPIEnabled ('proxmox ' );
3521+ if ($ apiCheck !== true ) {
3522+ return $ apiCheck ;
3523+ }
3524+
3525+ // Expliziter Null-Check für zusätzliche Sicherheit
3526+ if (!$ this ->proxmoxGet ) {
3527+ return [
3528+ 'success ' => false ,
3529+ 'error ' => 'API_NOT_INITIALIZED ' ,
3530+ 'message ' => 'Proxmox API nicht initialisiert ' ,
3531+ 'api ' => 'proxmox '
3532+ ];
3533+ }
3534+
3535+ return $ this ->proxmoxGet ->getLXCs ();
3536+ }
33933537 public function getProxmoxNodes () {
33943538 $ apiCheck = $ this ->checkAPIEnabled ('proxmox ' );
33953539 if ($ apiCheck !== true ) {
@@ -3732,41 +3876,57 @@ public function createProxmoxVM($vmData) {
37323876 return $ this ->proxmoxPost ->createVM ($ vmData );
37333877 }
37343878
3735- public function controlProxmoxVM ($ node , $ vmid , $ action ) {
3879+ public function controlProxmoxVM ($ node , $ vmid , $ action, $ type = ' qemu ' ) {
37363880 $ apiCheck = $ this ->checkAPIEnabled ('proxmox ' );
37373881 if ($ apiCheck !== true ) {
37383882 return $ apiCheck ;
37393883 }
37403884
3885+ // Wähle die richtige Funktion basierend auf dem Typ
3886+ $ functionPrefix = $ type === 'lxc ' ? 'LXC ' : 'VM ' ;
3887+
37413888 switch ($ action ) {
37423889 case 'start ' :
3743- return $ this ->safeAPICall ('proxmox ' , $ this ->proxmoxPost , 'startVM ' , [$ node , $ vmid ]);
3890+ return $ this ->safeAPICall ('proxmox ' , $ this ->proxmoxPost , 'start ' . $ functionPrefix , [$ node , $ vmid ]);
37443891 case 'stop ' :
3745- return $ this ->safeAPICall ('proxmox ' , $ this ->proxmoxPost , 'stopVM ' , [$ node , $ vmid ]);
3892+ return $ this ->safeAPICall ('proxmox ' , $ this ->proxmoxPost , 'stop ' . $ functionPrefix , [$ node , $ vmid ]);
3893+ case 'reboot ' :
3894+ return $ this ->safeAPICall ('proxmox ' , $ this ->proxmoxPost , 'reboot ' . $ functionPrefix , [$ node , $ vmid ]);
37463895 case 'reset ' :
3896+ // Reset funktioniert nur für QEMU, nicht für LXC
3897+ if ($ type === 'lxc ' ) {
3898+ return [
3899+ 'success ' => false ,
3900+ 'error ' => 'UNSUPPORTED_ACTION ' ,
3901+ 'message ' => 'Reset wird für LXC-Container nicht unterstützt '
3902+ ];
3903+ }
37473904 return $ this ->safeAPICall ('proxmox ' , $ this ->proxmoxPost , 'resetVM ' , [$ node , $ vmid ]);
37483905 case 'suspend ' :
3749- return $ this ->safeAPICall ('proxmox ' , $ this ->proxmoxPost , 'suspendVM ' , [$ node , $ vmid ]);
3906+ return $ this ->safeAPICall ('proxmox ' , $ this ->proxmoxPost , 'suspend ' . $ functionPrefix , [$ node , $ vmid ]);
37503907 case 'resume ' :
3751- return $ this ->safeAPICall ('proxmox ' , $ this ->proxmoxPost , 'resumeVM ' , [$ node , $ vmid ]);
3908+ return $ this ->safeAPICall ('proxmox ' , $ this ->proxmoxPost , 'resume ' . $ functionPrefix , [$ node , $ vmid ]);
37523909 default :
37533910 return [
37543911 'success ' => false ,
37553912 'error ' => 'INVALID_ACTION ' ,
3756- 'message ' => 'Ungültige Aktion: ' . $ action ,
3913+ 'message ' => 'Ungültige Aktion: ' . $ action ,
37573914 'api ' => 'proxmox ' ,
3758- 'valid_actions ' => ['start ' , 'stop ' , 'reset ' , 'suspend ' , 'resume ' ]
3915+ 'valid_actions ' => ['start ' , 'stop ' , 'reboot ' , ' reset ' , 'suspend ' , 'resume ' ]
37593916 ];
37603917 }
37613918 }
37623919
3763- public function deleteProxmoxVM ($ node , $ vmid ) {
3920+ public function deleteProxmoxVM ($ node , $ vmid, $ type = ' qemu ' ) {
37643921 $ apiCheck = $ this ->checkAPIEnabled ('proxmox ' );
37653922 if ($ apiCheck !== true ) {
37663923 return $ apiCheck ;
37673924 }
37683925
3769- return $ this ->safeAPICall ('proxmox ' , $ this ->proxmoxPost , 'deleteVM ' , [$ node , $ vmid ]);
3926+ // Wähle die richtige Funktion basierend auf dem Typ
3927+ $ functionName = $ type === 'lxc ' ? 'deleteLXC ' : 'deleteVM ' ;
3928+
3929+ return $ this ->safeAPICall ('proxmox ' , $ this ->proxmoxPost , $ functionName , [$ node , $ vmid ]);
37703930 }
37713931
37723932 // ISPConfig Methods
0 commit comments