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