Skip to content

Commit

Permalink
adding draft of the ressource api call
Browse files Browse the repository at this point in the history
  • Loading branch information
ooemperor committed Nov 21, 2024
1 parent 2e86d11 commit e539e02
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/models/proxmox/LXC.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
31 changes: 30 additions & 1 deletion src/services/ProxmoxService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ProxmoxService {
* Get method to get all Nodes of proxmox cluster
*/
async getNodes(): Promise<NodesResponse> {
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`, {
Expand All @@ -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<any> {
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);

0 comments on commit e539e02

Please sign in to comment.