diff --git a/src/models/proxmox/LXC.tsx b/src/models/proxmox/LXC.tsx index eb668a4..113a1b4 100644 --- a/src/models/proxmox/LXC.tsx +++ b/src/models/proxmox/LXC.tsx @@ -31,4 +31,22 @@ export interface LXC { tags: string | null, template: boolean | null, uptime: number | null +} + +/** + * Response type for multiple nodes + */ +export interface LXCsResponse { + lxcs: LXC[]; + success: boolean; + message: string; +} + +/** + * Response type for single node + */ +export interface LXCResponse { + lxc: LXC; + success: boolean; + message: string; } \ No newline at end of file diff --git a/src/services/ProxmoxService.tsx b/src/services/ProxmoxService.tsx index 29f17e4..8b39f62 100644 --- a/src/services/ProxmoxService.tsx +++ b/src/services/ProxmoxService.tsx @@ -26,7 +26,7 @@ class ProxmoxService { * Get method to get all Nodes of proxmox cluster */ async getNodes(): Promise { - let nodeResponse: any = {success: false, nodes: [], message: ''}; + let nodeResponse: NodesResponse = {success: false, nodes: [], message: ''}; try { const response: Response = await fetch(`${this.baseUrl}/api2/json/nodes`, { @@ -46,6 +46,35 @@ class ProxmoxService { } return nodeResponse; } + + /** + * Gets all the ressources from the cluster + * Will later be used to split it up more. + * @param type the type of ressource we want to filter for + */ + async getResources(type: string | null = null): Promise { + let resourceResponse: any = {success: false, nodes: [], message: ''}; + + try { + const response: Response = await fetch(`${this.baseUrl}/api2/json/cluster/resources`, { + method: 'GET', + headers: {'Content-Type': 'application/json', 'Authorization': this.apiToken || ""}, + }); + + if (!response.ok) { + resourceResponse.message = response.statusText; + return resourceResponse; + } + const raw_json = await response.json(); + let process_json = await raw_json['data']; + let process_json = process_json.filter(resource: any => resource.type.equal(type)) + resourceResponse.nodes = await raw_json['data']; + resourceResponse.success = true; + } catch (error: any) { + resourceResponse.message = error; + } + return resourceResponse; + } } export const proxmoxService = new ProxmoxService(config.proxmoxApiKey, config.proxmoxApi); \ No newline at end of file