Skip to content

Commit a263c31

Browse files
committed
api update
1 parent eaebd36 commit a263c31

File tree

1 file changed

+183
-1
lines changed

1 file changed

+183
-1
lines changed

src/ProxmoxNodeVm.php

Lines changed: 183 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1843,6 +1843,168 @@ public function lxcVncwebsocket(string $node, int $vmid, int $port = null, strin
18431843
return ResponseHelper::generate(true,'Opens a weksocket for VNC traffic', $response['data']);
18441844
}
18451845

1846+
/**
1847+
* get List available networks
1848+
* GET /api2/json/nodes/{node}/network
1849+
* @param string $node The cluster node name.
1850+
* @param enum|null $type Only list specific interface types.
1851+
* @throws Exception
1852+
*/
1853+
public function network(string $node, $type = null)
1854+
{
1855+
$optional['type'] = !empty($type) ? $type : null;
1856+
$response = $this->makeRequest("GET","nodes/$node/network", $optional);
1857+
1858+
if (!isset($response['data'])){
1859+
return ResponseHelper::generate(false,'get List available networks fail!');
1860+
}
1861+
1862+
return ResponseHelper::generate(true,'get List available networks', $response['data']);
1863+
}
1864+
1865+
/**
1866+
* Create network device configuration
1867+
* POST /api2/json/nodes/{node}/network
1868+
* @param string $node The cluster node name.
1869+
* @param array $data
1870+
* @throws Exception
1871+
*/
1872+
public function createNetwork(string $node, array $data)
1873+
{
1874+
$response = $this->makeRequest("POST","nodes/$node/network", $data);
1875+
1876+
if (!isset($response['data'])){
1877+
return ResponseHelper::generate(false,'Create network device configuration fail!');
1878+
}
1879+
1880+
return ResponseHelper::generate(true,'Created network device configurations', $response['data']);
1881+
}
1882+
1883+
/**
1884+
* Revert network configuration changes.
1885+
* DELETE /api2/json/nodes/{node}/network
1886+
* @param string $node The cluster node name.
1887+
* @throws Exception
1888+
*/
1889+
public function revertNetwork(string $node)
1890+
{
1891+
$response = $this->makeRequest("DELETE","nodes/$node/network");
1892+
1893+
if (!isset($response['data'])){
1894+
return ResponseHelper::generate(false,'Revert network configuration changes fail!');
1895+
}
1896+
1897+
return ResponseHelper::generate(true,'Revert network configuration changes', $response['data']);
1898+
}
1899+
1900+
/**
1901+
* Network interface name.
1902+
* GET /api2/json/nodes/{node}/network/{iface}
1903+
* @param string $node The cluster node name.
1904+
* @param string $iface
1905+
* @throws Exception
1906+
*/
1907+
public function networkIface(string $node, string $iface)
1908+
{
1909+
$response = $this->makeRequest("GET","/nodes/$node/network/$iface");
1910+
1911+
if (!isset($response['data'])){
1912+
return ResponseHelper::generate(false,'Network interface name fail!');
1913+
}
1914+
1915+
return ResponseHelper::generate(true,'Network interface name', $response['data']);
1916+
}
1917+
1918+
/**
1919+
* Update network device configuration
1920+
* PUT /api2/json/nodes/{node}/network/{iface}
1921+
* @param string $node The cluster node name.
1922+
* @param string $iface
1923+
* @param array $data
1924+
* @throws Exception
1925+
*/
1926+
public function updateNetworkIface(string $node, string $iface, array $data)
1927+
{
1928+
$response = $this->makeRequest("PUT","/nodes/$node/network/$iface", $data);
1929+
1930+
if (!isset($response['data'])){
1931+
return ResponseHelper::generate(false,'Update network device configuration fail!');
1932+
}
1933+
1934+
return ResponseHelper::generate(true,'Updated network device configuration', $response['data']);
1935+
}
1936+
1937+
/**
1938+
* Delete network device configuration
1939+
* DELETE /api2/json/nodes/{node}/network/{iface}
1940+
* @param string $node The cluster node name.
1941+
* @param string $iface
1942+
* @throws Exception
1943+
*/
1944+
public function deleteNetworkIface($node, $iface)
1945+
{
1946+
$response = $this->makeRequest("DELETE","/nodes/$node/network/$iface");
1947+
1948+
if (!isset($response['data'])){
1949+
return ResponseHelper::generate(false,'Delete network device configuration fail!');
1950+
}
1951+
1952+
return ResponseHelper::generate(true,'Deleted network device configuration', $response['data']);
1953+
}
1954+
1955+
/**
1956+
* Virtual machine index (per node).
1957+
* GET /api2/json/nodes/{node}/qemu
1958+
* @param string $node The cluster node name.
1959+
* @throws Exception
1960+
*/
1961+
public function qemu(string $node)
1962+
{
1963+
$response = $this->makeRequest("GET","nodes/$node/qemu");
1964+
1965+
if (!isset($response['data'])){
1966+
return ResponseHelper::generate(false,'Virtual machine fail!');
1967+
}
1968+
1969+
return ResponseHelper::generate(true,'Virtual machine', $response['data']);
1970+
}
1971+
1972+
/**
1973+
* Create or restore a virtual machine.
1974+
* POST /api2/json/nodes/{node}/qemu
1975+
* @param string $node The cluster node name.
1976+
* @param array $data
1977+
* @throws Exception
1978+
*/
1979+
public function createQemu(string $node, array $data)
1980+
{
1981+
$response = $this->makeRequest("POST","nodes/$node/qemu", $data);
1982+
1983+
if (!isset($response['data'])){
1984+
return ResponseHelper::generate(false,'Create or restore a virtual machine fail!');
1985+
}
1986+
1987+
return ResponseHelper::generate(true,'Create or restore a virtual machine', $response['data']);
1988+
}
1989+
1990+
/**
1991+
* Directory index
1992+
* GET /api2/json/nodes/{node}/qemu/{vmid}
1993+
* @param string $node The cluster node name.
1994+
* @param integer $vmid The (unique) ID of the VM.
1995+
* @throws Exception
1996+
*/
1997+
public function qemuVmid(string $node, int $vmid)
1998+
{
1999+
$response = $this->makeRequest("GET","nodes/$node/qemu/$vmid");
2000+
2001+
if (!isset($response['data'])){
2002+
return ResponseHelper::generate(false,'VM details fail!');
2003+
}
2004+
2005+
return ResponseHelper::generate(true,'VM details', $response['data']);
2006+
}
2007+
18462008
/**
18472009
* Get list of VMs on a specific node
18482010
*
@@ -2825,6 +2987,9 @@ public function configureVMCloudInitNetwork(string $node, int $vmid, $ip, $gatew
28252987
return ResponseHelper::generate(false,'Network configure fail!', $response['data']);
28262988
}
28272989

2990+
/**
2991+
* @throws Exception
2992+
*/
28282993
public function fetchAvailableIPs($node)
28292994
{
28302995
// $params = ['type' => 'bridge'];
@@ -2842,6 +3007,23 @@ public function applyCloudInitVM($node, $vmid)
28423007
return $this->makeRequest('POST', "nodes/{$node}/qemu/{$vmid}/cloudinit");
28433008
}
28443009

3010+
/**
3011+
* Destroy the vm (also delete all used/owned volumes)
3012+
* DELETE /api2/json/nodes/{node}/qemu/{vmid}
3013+
* @param string $node The cluster node name.
3014+
* @param integer $vmid The (unique) ID of the VM.
3015+
* @param array $data
3016+
*/
3017+
public function destroyVm($node, $vmid, $data = array())
3018+
{
3019+
$response = $this->makeRequest('DELETE',"nodes/$node/qemu/$vmid", $data);
3020+
3021+
if (!isset($response['data'])){
3022+
return ResponseHelper::generate(false,'Destroy the vm fail!', $response['data']);
3023+
}
3024+
return ResponseHelper::generate(true,'Destroyed the vm', $response['data']);
3025+
}
3026+
28453027
/**
28463028
* Delete a Virtual Machine
28473029
*
@@ -2894,7 +3076,7 @@ public function deleteVM(string $node, int $vmid, bool $force = false, bool $pur
28943076
}
28953077

28963078
try {
2897-
$response = $this->makeRequest('DELETE', "nodes/{$node}/qemu/{$vmid}", $params);
3079+
$response = $this->makeRequest('DELETE', "nodes/$node/qemu/$vmid", $params);
28983080
$successResponse = [
28993081
'data' => $response['data'],
29003082
'node' => $node,

0 commit comments

Comments
 (0)