Update server listing and associated logic to pull from the panel dynamiacally
This commit is contained in:
parent
952dff854e
commit
fb9c106448
26 changed files with 384 additions and 239 deletions
13
resources/scripts/api/getServers.ts
Normal file
13
resources/scripts/api/getServers.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
import { rawDataToServerObject, Server } from '@/api/server/getServer';
|
||||
import http, { getPaginationSet, PaginatedResult } from '@/api/http';
|
||||
|
||||
export default (): Promise<PaginatedResult<Server>> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get(`/api/client`, { params: { include: [ 'allocation' ] } })
|
||||
.then(({ data }) => resolve({
|
||||
items: (data.data || []).map((datum: any) => rawDataToServerObject(datum.attributes)),
|
||||
pagination: getPaginationSet(data.meta.pagination),
|
||||
}))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
|
@ -1,9 +1,5 @@
|
|||
import axios, { AxiosInstance } from 'axios';
|
||||
|
||||
// This token is set in the bootstrap.js file at the beginning of the request
|
||||
// and is carried through from there.
|
||||
// const token: string = '';
|
||||
|
||||
const http: AxiosInstance = axios.create({
|
||||
headers: {
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
|
@ -41,3 +37,26 @@ export function httpErrorToHuman (error: any): string {
|
|||
|
||||
return error.message;
|
||||
}
|
||||
|
||||
export interface PaginatedResult<T> {
|
||||
items: T[];
|
||||
pagination: PaginationDataSet;
|
||||
}
|
||||
|
||||
interface PaginationDataSet {
|
||||
total: number;
|
||||
count: number;
|
||||
perPage: number;
|
||||
currentPage: number;
|
||||
totalPages: number;
|
||||
}
|
||||
|
||||
export function getPaginationSet (data: any): PaginationDataSet {
|
||||
return {
|
||||
total: data.total,
|
||||
count: data.count,
|
||||
perPage: data.per_page,
|
||||
currentPage: data.current_page,
|
||||
totalPages: data.total_pages,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ export interface Allocation {
|
|||
ip: string;
|
||||
alias: string | null;
|
||||
port: number;
|
||||
default: boolean;
|
||||
}
|
||||
|
||||
export interface Server {
|
||||
|
@ -36,6 +37,7 @@ export const rawDataToServerObject = (data: any): Server => ({
|
|||
ip: data.allocation.ip,
|
||||
alias: null,
|
||||
port: data.allocation.port,
|
||||
default: true,
|
||||
}],
|
||||
limits: { ...data.limits },
|
||||
featureLimits: { ...data.feature_limits },
|
||||
|
|
29
resources/scripts/api/server/getServerResourceUsage.ts
Normal file
29
resources/scripts/api/server/getServerResourceUsage.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import http from '@/api/http';
|
||||
|
||||
export type ServerPowerState = 'offline' | 'starting' | 'running' | 'stopping';
|
||||
|
||||
export interface ServerStats {
|
||||
status: ServerPowerState;
|
||||
isSuspended: boolean;
|
||||
memoryUsageInBytes: number;
|
||||
cpuUsagePercent: number;
|
||||
diskUsageInBytes: number;
|
||||
networkRxInBytes: number;
|
||||
networkTxInBytes: number;
|
||||
}
|
||||
|
||||
export default (server: string): Promise<ServerStats> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.get(`/api/client/servers/${server}/resources`)
|
||||
.then(({ data: { attributes } }) => resolve({
|
||||
status: attributes.current_state,
|
||||
isSuspended: attributes.is_suspended,
|
||||
memoryUsageInBytes: attributes.resources.memory_bytes,
|
||||
cpuUsagePercent: attributes.resources.cpu_absolute,
|
||||
diskUsageInBytes: attributes.resources.disk_bytes,
|
||||
networkRxInBytes: attributes.resources.network_rx_bytes,
|
||||
networkTxInBytes: attributes.resources.network_tx_bytes,
|
||||
}))
|
||||
.catch(reject);
|
||||
});
|
||||
};
|
Reference in a new issue