// // Volumes. // const { Element } = require("./Element"); const format = require("../../Utilities/Format"); class VolumeModel extends Element { constructor(json) { let configuration = (json && json.configuration) || {}; super(`volume:${configuration.name || json.id}`); this.name = configuration.name || json.id; this.driver = configuration.driver || ""; this.filesystem = configuration.format || ""; this.source = configuration.source || ""; // The volume image is sparse: sizeInBytes is the maximum it can grow // to, not what it occupies, so it is reported as capacity. this.capacity = configuration.sizeInBytes || 0; this.created = configuration.creationDate || null; this.labels = configuration.labels || {}; } get revision() { return `${this.capacity}:${this.filesystem}`; } get tooltip() { let lines = [`Volume:\t${this.name}`, `Driver:\t${this.driver}`]; if (this.filesystem) { lines.push(`Format:\t${this.filesystem}`); } if (this.capacity) { lines.push(`Capacity:\t${format.bytes(this.capacity)}`); } if (this.created) { lines.push(`Created:\t${format.age(this.created)}`); } if (this.source) { lines.push(`Source:\t${this.source}`); } return lines.join("\n"); } } function build(list) { return (list || []) .map((entry) => new VolumeModel(entry)) .sort((left, right) => left.name.localeCompare(right.name)); } module.exports = { VolumeModel, build };