@@ -712,7 +712,7 @@ public function firewallRules(string $node)
712712 * @param array $data
713713 * @throws Exception
714714 */
715- public function createFirewallRule ($ node , $ data = array () )
715+ public function createFirewallRule ($ node , array $ data )
716716 {
717717 $ response = $ this ->makeRequest ( "POST " ,"nodes/ $ node/firewall/rules " , $ data );
718718
@@ -831,6 +831,52 @@ public function setFirewallRuleOptions(string $node, array $data)
831831 return ResponseHelper::generate (true ,'Set firewall options ' , $ response ['data ' ]);
832832 }
833833
834+ /**
835+ * Create new rule
836+ * from the Proxmox node's public interface to a VM/Container IP:Port.
837+ * @throws Exception
838+ */
839+ public function createQemuFirewallRule (string $ node , int $ vmid , array $ data )
840+ {
841+ $ response = $ this ->makeRequest ('POST ' , "nodes/ $ node/qemu/ $ vmid/firewall/rules " , $ data );
842+
843+ if (!isset ($ response ['data ' ])){
844+ return ResponseHelper::generate (true ,'Created Firewall ' , $ response ['data ' ]);
845+ }
846+ return ResponseHelper::generate (false ,'Create Firewall fail! ' );
847+ }
848+
849+ /**
850+ * List of rule.
851+ * from the Proxmox node's public interface to a VM/Container IP:Port.
852+ * @throws Exception
853+ */
854+ public function listQemuFirewallRule (string $ node , int $ vmid )
855+ {
856+ $ response = $ this ->makeRequest ('GET ' , "nodes/ $ node/qemu/ $ vmid/firewall/rules " );
857+
858+ if (!isset ($ response ['data ' ])){
859+ return ResponseHelper::generate (false ,'List Firewall fail! ' );
860+ }
861+
862+ return ResponseHelper::generate (true ,'List Firewall ' , $ response ['data ' ]);
863+ }
864+
865+ /**
866+ * Removing of rule.
867+ * from the Proxmox node's public interface to a VM/Container IP:Port.
868+ * @throws Exception
869+ */
870+ public function removeQemuFirewallRule (string $ node , int $ vmid , $ pos )
871+ {
872+ $ response = $ this ->makeRequest ('DELETE ' , "nodes/ $ node/qemu/ $ vmid/firewall/rules/ $ pos " );
873+
874+ if (!isset ($ response ['data ' ])){
875+ return ResponseHelper::generate (true ,'Removed Firewall ' , $ response ['data ' ]);
876+ }
877+ return ResponseHelper::generate (false ,'Remove Firewall fail! ' );
878+ }
879+
834880 /**
835881 * LXC container index (per node).
836882 * GET /api2/json/nodes/{node}/lxc
@@ -1843,6 +1889,168 @@ public function lxcVncwebsocket(string $node, int $vmid, int $port = null, strin
18431889 return ResponseHelper::generate (true ,'Opens a weksocket for VNC traffic ' , $ response ['data ' ]);
18441890 }
18451891
1892+ /**
1893+ * get List available networks
1894+ * GET /api2/json/nodes/{node}/network
1895+ * @param string $node The cluster node name.
1896+ * @param enum|null $type Only list specific interface types.
1897+ * @throws Exception
1898+ */
1899+ public function network (string $ node , $ type = null )
1900+ {
1901+ $ optional ['type ' ] = !empty ($ type ) ? $ type : null ;
1902+ $ response = $ this ->makeRequest ("GET " ,"nodes/ $ node/network " , $ optional );
1903+
1904+ if (!isset ($ response ['data ' ])){
1905+ return ResponseHelper::generate (false ,'get List available networks fail! ' );
1906+ }
1907+
1908+ return ResponseHelper::generate (true ,'get List available networks ' , $ response ['data ' ]);
1909+ }
1910+
1911+ /**
1912+ * Create network device configuration
1913+ * POST /api2/json/nodes/{node}/network
1914+ * @param string $node The cluster node name.
1915+ * @param array $data
1916+ * @throws Exception
1917+ */
1918+ public function createNetwork (string $ node , array $ data )
1919+ {
1920+ $ response = $ this ->makeRequest ("POST " ,"nodes/ $ node/network " , $ data );
1921+
1922+ if (!isset ($ response ['data ' ])){
1923+ return ResponseHelper::generate (false ,'Create network device configuration fail! ' );
1924+ }
1925+
1926+ return ResponseHelper::generate (true ,'Created network device configurations ' , $ response ['data ' ]);
1927+ }
1928+
1929+ /**
1930+ * Revert network configuration changes.
1931+ * DELETE /api2/json/nodes/{node}/network
1932+ * @param string $node The cluster node name.
1933+ * @throws Exception
1934+ */
1935+ public function revertNetwork (string $ node )
1936+ {
1937+ $ response = $ this ->makeRequest ("DELETE " ,"nodes/ $ node/network " );
1938+
1939+ if (!isset ($ response ['data ' ])){
1940+ return ResponseHelper::generate (false ,'Revert network configuration changes fail! ' );
1941+ }
1942+
1943+ return ResponseHelper::generate (true ,'Revert network configuration changes ' , $ response ['data ' ]);
1944+ }
1945+
1946+ /**
1947+ * Network interface name.
1948+ * GET /api2/json/nodes/{node}/network/{iface}
1949+ * @param string $node The cluster node name.
1950+ * @param string $iface
1951+ * @throws Exception
1952+ */
1953+ public function networkIface (string $ node , string $ iface )
1954+ {
1955+ $ response = $ this ->makeRequest ("GET " ,"/nodes/ $ node/network/ $ iface " );
1956+
1957+ if (!isset ($ response ['data ' ])){
1958+ return ResponseHelper::generate (false ,'Network interface name fail! ' );
1959+ }
1960+
1961+ return ResponseHelper::generate (true ,'Network interface name ' , $ response ['data ' ]);
1962+ }
1963+
1964+ /**
1965+ * Update network device configuration
1966+ * PUT /api2/json/nodes/{node}/network/{iface}
1967+ * @param string $node The cluster node name.
1968+ * @param string $iface
1969+ * @param array $data
1970+ * @throws Exception
1971+ */
1972+ public function updateNetworkIface (string $ node , string $ iface , array $ data )
1973+ {
1974+ $ response = $ this ->makeRequest ("PUT " ,"/nodes/ $ node/network/ $ iface " , $ data );
1975+
1976+ if (!isset ($ response ['data ' ])){
1977+ return ResponseHelper::generate (false ,'Update network device configuration fail! ' );
1978+ }
1979+
1980+ return ResponseHelper::generate (true ,'Updated network device configuration ' , $ response ['data ' ]);
1981+ }
1982+
1983+ /**
1984+ * Delete network device configuration
1985+ * DELETE /api2/json/nodes/{node}/network/{iface}
1986+ * @param string $node The cluster node name.
1987+ * @param string $iface
1988+ * @throws Exception
1989+ */
1990+ public function deleteNetworkIface ($ node , $ iface )
1991+ {
1992+ $ response = $ this ->makeRequest ("DELETE " ,"/nodes/ $ node/network/ $ iface " );
1993+
1994+ if (!isset ($ response ['data ' ])){
1995+ return ResponseHelper::generate (false ,'Delete network device configuration fail! ' );
1996+ }
1997+
1998+ return ResponseHelper::generate (true ,'Deleted network device configuration ' , $ response ['data ' ]);
1999+ }
2000+
2001+ /**
2002+ * Virtual machine index (per node).
2003+ * GET /api2/json/nodes/{node}/qemu
2004+ * @param string $node The cluster node name.
2005+ * @throws Exception
2006+ */
2007+ public function qemu (string $ node )
2008+ {
2009+ $ response = $ this ->makeRequest ("GET " ,"nodes/ $ node/qemu " );
2010+
2011+ if (!isset ($ response ['data ' ])){
2012+ return ResponseHelper::generate (false ,'Virtual machine fail! ' );
2013+ }
2014+
2015+ return ResponseHelper::generate (true ,'Virtual machine ' , $ response ['data ' ]);
2016+ }
2017+
2018+ /**
2019+ * Create or restore a virtual machine.
2020+ * POST /api2/json/nodes/{node}/qemu
2021+ * @param string $node The cluster node name.
2022+ * @param array $data
2023+ * @throws Exception
2024+ */
2025+ public function createQemu (string $ node , array $ data )
2026+ {
2027+ $ response = $ this ->makeRequest ("POST " ,"nodes/ $ node/qemu " , $ data );
2028+
2029+ if (!isset ($ response ['data ' ])){
2030+ return ResponseHelper::generate (false ,'Create or restore a virtual machine fail! ' );
2031+ }
2032+
2033+ return ResponseHelper::generate (true ,'Create or restore a virtual machine ' , $ response ['data ' ]);
2034+ }
2035+
2036+ /**
2037+ * Directory index
2038+ * GET /api2/json/nodes/{node}/qemu/{vmid}
2039+ * @param string $node The cluster node name.
2040+ * @param integer $vmid The (unique) ID of the VM.
2041+ * @throws Exception
2042+ */
2043+ public function qemuVmid (string $ node , int $ vmid )
2044+ {
2045+ $ response = $ this ->makeRequest ("GET " ,"nodes/ $ node/qemu/ $ vmid " );
2046+
2047+ if (!isset ($ response ['data ' ])){
2048+ return ResponseHelper::generate (false ,'VM details fail! ' );
2049+ }
2050+
2051+ return ResponseHelper::generate (true ,'VM details ' , $ response ['data ' ]);
2052+ }
2053+
18462054 /**
18472055 * Get list of VMs on a specific node
18482056 *
@@ -2825,6 +3033,9 @@ public function configureVMCloudInitNetwork(string $node, int $vmid, $ip, $gatew
28253033 return ResponseHelper::generate (false ,'Network configure fail! ' , $ response ['data ' ]);
28263034 }
28273035
3036+ /**
3037+ * @throws Exception
3038+ */
28283039 public function fetchAvailableIPs ($ node )
28293040 {
28303041// $params = ['type' => 'bridge'];
@@ -2842,6 +3053,23 @@ public function applyCloudInitVM($node, $vmid)
28423053 return $ this ->makeRequest ('POST ' , "nodes/ {$ node }/qemu/ {$ vmid }/cloudinit " );
28433054 }
28443055
3056+ /**
3057+ * Destroy the vm (also delete all used/owned volumes)
3058+ * DELETE /api2/json/nodes/{node}/qemu/{vmid}
3059+ * @param string $node The cluster node name.
3060+ * @param integer $vmid The (unique) ID of the VM.
3061+ * @param array $data
3062+ */
3063+ public function destroyVm ($ node , $ vmid , $ data = array ())
3064+ {
3065+ $ response = $ this ->makeRequest ('DELETE ' ,"nodes/ $ node/qemu/ $ vmid " , $ data );
3066+
3067+ if (!isset ($ response ['data ' ])){
3068+ return ResponseHelper::generate (false ,'Destroy the vm fail! ' , $ response ['data ' ]);
3069+ }
3070+ return ResponseHelper::generate (true ,'Destroyed the vm ' , $ response ['data ' ]);
3071+ }
3072+
28453073 /**
28463074 * Delete a Virtual Machine
28473075 *
@@ -2894,7 +3122,7 @@ public function deleteVM(string $node, int $vmid, bool $force = false, bool $pur
28943122 }
28953123
28963124 try {
2897- $ response = $ this ->makeRequest ('DELETE ' , "nodes/ { $ node} /qemu/ { $ vmid} " , $ params );
3125+ $ response = $ this ->makeRequest ('DELETE ' , "nodes/ $ node/qemu/ $ vmid " , $ params );
28983126 $ successResponse = [
28993127 'data ' => $ response ['data ' ],
29003128 'node ' => $ node ,
0 commit comments