"use strict"; const Promise = require("bluebird"); const dlayer = require("../packages/dlayer"); const All = require("../packages/graphql-interface/symbols/all"); const loaders = require("./loaders"); const types = require("./types"); function typeFromSource(source, ids, factoryFunction) { return Promise.try(() => { if (ids != null) { return source.loadMany(ids); } else { return source.load(All); // FIXME: Symbol } }).then((items) => { return items.map((item) => factoryFunction(item)); }); } module.exports = function () { return dlayer({ makeContext: function () { return { sources: loaders() }; }, schema: { hardware: { drives: ({ paths }, { sources }) => { return typeFromSource(sources.smartctlScan, paths, (device) => types.Drive({ path: device.path })); } }, resources: { blockDevices: ({ names }, { sources }) => { return typeFromSource(sources.lsblk, names, (device) => types.BlockDevice({ name: device.name })); }, lvm: { physicalVolumes: { $get: ({ paths }, { sources }) => { return typeFromSource(sources.lvmPhysicalVolumes, paths, (volume) => types.LVMPhysicalVolume({ path: volume.path })); }, $methods: {} }, volumeGroups: ({ names }, { sources }) => { return typeFromSource(sources.lvmVolumeGroups, names, (group) => types.LVMVolumeGroup({ name: group.name })); } }, images: { installationMedia: [], vmImages: [] } }, } }); }; // let schemaTodo = { // system: { // hardware: { ... }, // lvm: { // ... // } // }, // resources: { // storagePools: { // name: "...", // type: "lvm|folder", // isLocal: true, // folderPath: "...", // lvmVolumeGroup: LVMVolumeGroup, // $$update: { // $arguments: { // name: "..." // } // }, // $$delete: {}, // $collection: { // $$create: { // $arguments: { // name: "poolName", // volumeGroup: "name", // // or: // folderPath: "path" // } // // standard fields for a storage pool entry go here, including LVMVolumeGroup resolution! // } // }, // }, // networkPools: { ... }, // storageVolumes: { // id: 0, // userID: 0, // pool: StoragePool, // poolID: 0, // the index/ID within the pool // size: 0, // bytes-iec // }, // instances: { // id: 0, // userID: 0, // state: "running|stopped|creating", // storageVolumes: StorageVolume, // in boot order // } // } // };