Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

virtualbox.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. 'use strict';
  2. // @ts-check
  3. // ==================================================================================
  4. // virtualbox.js
  5. // ----------------------------------------------------------------------------------
  6. // Description: System Information - library
  7. // for Node.js
  8. // Copyright: (c) 2014 - 2020
  9. // Author: Sebastian Hildebrandt
  10. // ----------------------------------------------------------------------------------
  11. // License: MIT
  12. // ==================================================================================
  13. // 14. Docker
  14. // ----------------------------------------------------------------------------------
  15. const os = require('os');
  16. const exec = require('child_process').exec;
  17. const util = require('./util');
  18. function vboxInfo(callback) {
  19. // fallback - if only callback is given
  20. let result = [];
  21. return new Promise((resolve) => {
  22. process.nextTick(() => {
  23. try {
  24. exec(util.getVboxmanage() + ' list vms --long', function (error, stdout) {
  25. let parts = (os.EOL + stdout.toString()).split(os.EOL + 'Name:');
  26. parts.shift();
  27. parts.forEach(part => {
  28. const lines = ('Name:' + part).split(os.EOL);
  29. const state = util.getValue(lines, 'State');
  30. const running = state.startsWith('running');
  31. const runningSinceString = running ? state.replace('running (since ', '').replace(')', '').trim() : '';
  32. let runningSince = 0;
  33. try {
  34. if (running) {
  35. const sinceDateObj = new Date(runningSinceString);
  36. const offset = sinceDateObj.getTimezoneOffset();
  37. runningSince = Math.round((Date.now() - Date.parse(sinceDateObj)) / 1000) + offset * 60;
  38. }
  39. } catch (e) {
  40. util.noop();
  41. }
  42. const stoppedSinceString = !running ? state.replace('powered off (since', '').replace(')', '').trim() : '';
  43. let stoppedSince = 0;
  44. try {
  45. if (!running) {
  46. const sinceDateObj = new Date(stoppedSinceString);
  47. const offset = sinceDateObj.getTimezoneOffset();
  48. stoppedSince = Math.round((Date.now() - Date.parse(sinceDateObj)) / 1000) + offset * 60;
  49. }
  50. } catch (e) {
  51. util.noop();
  52. }
  53. result.push({
  54. id: util.getValue(lines, 'UUID'),
  55. name: util.getValue(lines, 'Name'),
  56. running,
  57. started: runningSinceString,
  58. runningSince,
  59. stopped: stoppedSinceString,
  60. stoppedSince,
  61. guestOS: util.getValue(lines, 'Guest OS'),
  62. hardwareUUID: util.getValue(lines, 'Hardware UUID'),
  63. memory: parseInt(util.getValue(lines, 'Memory size', ' '), 10),
  64. vram: parseInt(util.getValue(lines, 'VRAM size'), 10),
  65. cpus: parseInt(util.getValue(lines, 'Number of CPUs'), 10),
  66. cpuExepCap: util.getValue(lines, 'CPU exec cap'),
  67. cpuProfile: util.getValue(lines, 'CPUProfile'),
  68. chipset: util.getValue(lines, 'Chipset'),
  69. firmware: util.getValue(lines, 'Firmware'),
  70. pageFusion: util.getValue(lines, 'Page Fusion') === 'enabled',
  71. configFile: util.getValue(lines, 'Config file'),
  72. snapshotFolder: util.getValue(lines, 'Snapshot folder'),
  73. logFolder: util.getValue(lines, 'Log folder'),
  74. HPET: util.getValue(lines, 'HPET') === 'enabled',
  75. PAE: util.getValue(lines, 'PAE') === 'enabled',
  76. longMode: util.getValue(lines, 'Long Mode') === 'enabled',
  77. tripleFaultReset: util.getValue(lines, 'Triple Fault Reset') === 'enabled',
  78. APIC: util.getValue(lines, 'APIC') === 'enabled',
  79. X2APIC: util.getValue(lines, 'X2APIC') === 'enabled',
  80. ACPI: util.getValue(lines, 'ACPI') === 'enabled',
  81. IOAPIC: util.getValue(lines, 'IOAPIC') === 'enabled',
  82. biosAPICmode: util.getValue(lines, 'BIOS APIC mode'),
  83. bootMenuMode: util.getValue(lines, 'Boot menu mode'),
  84. bootDevice1: util.getValue(lines, 'Boot Device 1'),
  85. bootDevice2: util.getValue(lines, 'Boot Device 2'),
  86. bootDevice3: util.getValue(lines, 'Boot Device 3'),
  87. bootDevice4: util.getValue(lines, 'Boot Device 4'),
  88. timeOffset: util.getValue(lines, 'Time offset'),
  89. RTC: util.getValue(lines, 'RTC'),
  90. });
  91. });
  92. if (callback) { callback(result); }
  93. resolve(result);
  94. });
  95. } catch (e) {
  96. if (callback) { callback(result); }
  97. resolve(result);
  98. }
  99. });
  100. });
  101. }
  102. exports.vboxInfo = vboxInfo;