mirror of
https://github.com/unraid/api.git
synced 2025-12-31 13:39:52 -06:00
fix: code review feedback
This commit is contained in:
@@ -17,7 +17,9 @@ const getUnraidApiLocation = async () => {
|
|||||||
throw new Error('unraid-api not found');
|
throw new Error('unraid-api not found');
|
||||||
}
|
}
|
||||||
return shellToUse.stdout.trim();
|
return shellToUse.stdout.trim();
|
||||||
} finally {
|
} catch (err) {
|
||||||
|
logger.debug('Could not find unraid-api in PATH, using default location');
|
||||||
|
|
||||||
return '/usr/bin/unraid-api';
|
return '/usr/bin/unraid-api';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,50 +10,51 @@ export type DomainLookupType = 'id' | 'uuid' | 'name';
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
export const parseDomain = async (type: DomainLookupType, id: string): Promise<Domain> => {
|
export const parseDomain = async (type: DomainLookupType, id: string): Promise<Domain> => {
|
||||||
const types = {
|
const types = {
|
||||||
id: 'lookupDomainByIdAsync',
|
id: 'lookupDomainByIdAsync',
|
||||||
uuid: 'lookupDomainByUUIDAsync',
|
uuid: 'lookupDomainByUUIDAsync',
|
||||||
name: 'lookupDomainByNameAsync',
|
name: 'lookupDomainByNameAsync',
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!type || !Object.keys(types).includes(type)) {
|
if (!type || !Object.keys(types).includes(type)) {
|
||||||
throw new Error(`Type must be one of [${Object.keys(types).join(', ')}], ${type} given.`);
|
throw new Error(`Type must be one of [${Object.keys(types).join(', ')}], ${type} given.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { UnraidHypervisor } = await import('@app/core/utils/vms/get-hypervisor');
|
const { UnraidHypervisor } = await import('@app/core/utils/vms/get-hypervisor');
|
||||||
const client = await UnraidHypervisor.getInstance().getHypervisor();
|
const client = await UnraidHypervisor.getInstance().getHypervisor();
|
||||||
const method = types[type];
|
const method = types[type];
|
||||||
const domain = await client[method](id);
|
const domain = await client[method](id);
|
||||||
const info = await domain.getInfoAsync();
|
const info = await domain.getInfoAsync();
|
||||||
|
|
||||||
const [uuid, osType, autostart, maxMemory, schedulerType, schedulerParameters, securityLabel, name] = await Promise.all([
|
const [uuid, osType, autostart, maxMemory, schedulerType, schedulerParameters, securityLabel, name] =
|
||||||
domain.getUUIDAsync(),
|
await Promise.all([
|
||||||
domain.getOSTypeAsync(),
|
domain.getUUIDAsync(),
|
||||||
domain.getAutostartAsync(),
|
domain.getOSTypeAsync(),
|
||||||
domain.getMaxMemoryAsync(),
|
domain.getAutostartAsync(),
|
||||||
domain.getSchedulerTypeAsync(),
|
domain.getMaxMemoryAsync(),
|
||||||
domain.getSchedulerParametersAsync(),
|
domain.getSchedulerTypeAsync(),
|
||||||
domain.getSecurityLabelAsync(),
|
domain.getSchedulerParametersAsync(),
|
||||||
domain.getNameAsync(),
|
domain.getSecurityLabelAsync(),
|
||||||
]);
|
domain.getNameAsync(),
|
||||||
|
]);
|
||||||
|
|
||||||
const results = {
|
const results = {
|
||||||
uuid,
|
uuid,
|
||||||
osType,
|
osType,
|
||||||
autostart,
|
autostart,
|
||||||
maxMemory,
|
maxMemory,
|
||||||
schedulerType,
|
schedulerType,
|
||||||
schedulerParameters,
|
schedulerParameters,
|
||||||
securityLabel,
|
securityLabel,
|
||||||
name,
|
name,
|
||||||
...info,
|
...info,
|
||||||
state: info.state.replace(' ', '_'),
|
state: info.state.replace(' ', '_'),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (info.state === 'running') {
|
if (info.state === 'running') {
|
||||||
results.vcpus = await domain.getVcpusAsync();
|
results.vcpus = await domain.getVcpusAsync();
|
||||||
results.memoryStats = await domain.getMemoryStatsAsync();
|
results.memoryStats = await domain.getMemoryStatsAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ export class VmsResolver {
|
|||||||
possession: AuthPossession.ANY,
|
possession: AuthPossession.ANY,
|
||||||
})
|
})
|
||||||
public async vms() {
|
public async vms() {
|
||||||
console.log('Resolving Domains');
|
|
||||||
return {
|
return {
|
||||||
id: 'vms',
|
id: 'vms',
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user