1 | {"version":3,"file":"ova-generate.js","names":["_tarStream","_interopRequireDefault","require","_","_promiseToolbox","_stream","obj","__esModule","default","writeOvaOn","outStream","vmName","vmDescription","disks","firmware","nics","vmMemoryMB","cpuCount","ovf","createOvf","tarStream","tar","pack","pipeline","fromCallback","call","entry","name","Buffer","from","pushDisk","disk","iterator","size","vhdToVMDKIterator","getStream","undefined","computeVmdkLength","fileSize","Promise","resolve","reject","entryWriteStream","type","err","finalize","createDiskSections","fileReferences","diskFragments","diskItems","i","length","diskId","push","fileName","capacityMB","join","createNicsSection","networks","Set","nicItems","nic","add","networkName","text","networksElements","network","nicsSection","networksSection","diskSection","networkSection","id","nextId"],"sources":["../src/ova-generate.js"],"sourcesContent":["import tar from 'tar-stream'\nimport { computeVmdkLength, vhdToVMDKIterator } from '.'\nimport { fromCallback } from 'promise-toolbox'\nimport { pipeline } from 'stream'\n\n// WE MIGHT WANT TO HAVE A LOOK HERE: https://opennodecloud.com/howto/2013/12/25/howto-ON-ovf-reference.html\n\n/**\n *\n * @param outStream\n * @param vmName\n * @param vmDescription\n * @param disks [{name, fileName, capacityMB, getStream}]\n * @param nics [{name, networkName}]\n * @param vmMemoryMB\n * @param cpuCount\n * @returns readStream\n */\nexport async function writeOvaOn(\n outStream,\n { vmName, vmDescription = '', disks = [], firmware = 'bios', nics = [], vmMemoryMB = 64, cpuCount = 1 }\n) {\n const ovf = createOvf(vmName, vmDescription, disks, nics, vmMemoryMB, cpuCount, firmware)\n const tarStream = tar.pack()\n pipeline(tarStream, outStream, () => {})\n await fromCallback.call(tarStream, tarStream.entry, { name: `metadata.ovf` }, Buffer.from(ovf, 'utf8'))\n\n // https://github.com/mafintosh/tar-stream/issues/24#issuecomment-558358268\n async function pushDisk(disk) {\n let { iterator, size } = await vhdToVMDKIterator(disk.name, await disk.getStream())\n if (size === undefined) {\n size = await computeVmdkLength(disk.name, await disk.getStream())\n }\n disk.fileSize = size\n return new Promise((resolve, reject) => {\n const entryWriteStream = tarStream.entry({ name: `${disk.name}.vmdk`, size, type: 'file' }, err => {\n if (err == null) {\n return resolve()\n } else return reject(err)\n })\n pipeline(iterator, entryWriteStream, () => {})\n })\n }\n\n for (const disk of disks) {\n await pushDisk(disk)\n }\n tarStream.finalize()\n return outStream\n}\n\nfunction createDiskSections(disks) {\n const fileReferences = []\n const diskFragments = []\n const diskItems = []\n for (let i = 0; i < disks.length; i++) {\n const disk = disks[i]\n const diskId = `vmdisk${i + 1}`\n fileReferences.push(` <File ovf:href=\"${disk.fileName}\" ovf:id=\"file${i + 1}\"/>`)\n diskFragments.push(\n ` <Disk ovf:capacity=\"${\n disk.capacityMB\n }\" ovf:capacityAllocationUnits=\"byte * 2^20\" ovf:diskId=\"${diskId}\" ovf:fileRef=\"file${\n i + 1\n }\" ovf:format=\"http://www.vmware.com/interfaces/specifications/vmdk.html#streamOptimized\" />`\n )\n diskItems.push(`\n <Item>\n <rasd:AddressOnParent>${i}</rasd:AddressOnParent>\n <rasd:ElementName>Hard Disk ${i + 1}</rasd:ElementName>\n <rasd:HostResource>ovf:/disk/${diskId}</rasd:HostResource>\n <rasd:InstanceID>${diskId}</rasd:InstanceID>\n <rasd:Parent>4</rasd:Parent>\n <rasd:ResourceType>17</rasd:ResourceType>\n </Item>\n `)\n }\n return {\n fileReferences: fileReferences.join('\\n'),\n diskFragments: diskFragments.join('\\n'),\n diskItems: diskItems.join('\\n'),\n }\n}\n\nfunction createNicsSection(nics) {\n const networks = new Set()\n const nicItems = []\n for (let i = 0; i < nics.length; i++) {\n const nic = nics[i]\n networks.add(nic.networkName)\n const text = `\n <Item>\n <rasd:AddressOnParent>${i}</rasd:AddressOnParent>\n <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>\n <rasd:Connection>${nic.networkName}</rasd:Connection>\n <rasd:Description>PCNet32 ethernet adapter on \"${nic.networkName}\"</rasd:Description>\n <rasd:ElementName>Connection to ${nic.networkName}</rasd:ElementName>\n <rasd:InstanceID>${'nic' + i}</rasd:InstanceID>\n <rasd:ResourceSubType>PCNet32</rasd:ResourceSubType>\n <rasd:ResourceType>10</rasd:ResourceType>\n </Item>\n`\n nicItems.push(text)\n }\n const networksElements = []\n for (const network of networks) {\n networksElements.push(` <Network ovf:name=\"${network}\"/>`)\n }\n return { nicsSection: nicItems.join('\\n'), networksSection: networksElements.join('\\n') }\n}\n\nfunction createOvf(vmName, vmDescription, disks = [], nics = [], vmMemoryMB = 64, cpuCount = 1, firmware = 'bios') {\n const diskSection = createDiskSections(disks)\n const networkSection = createNicsSection(nics)\n let id = 1\n const nextId = () => id++\n\n return `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!--Generated by Xen Orchestra-->\n<ovf:Envelope xmlns=\"http://schemas.dmtf.org/ovf/envelope/1\" xmlns:ovf=\"http://schemas.dmtf.org/ovf/envelope/1\"\n xmlns:rasd=\"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData\"\n xmlns:vssd=\"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData\">\n <References>\n${diskSection.fileReferences}\n </References>\n <DiskSection>\n <Info>Virtual disk information</Info>\n${diskSection.diskFragments}\n </DiskSection>\n <NetworkSection>\n <Info>The list of logical networks</Info>\n${networkSection.networksSection}\n </NetworkSection>\n <VirtualSystem ovf:id=\"${vmName}\">\n <Info>A virtual machine</Info>\n <Name>${vmName}</Name>\n <OperatingSystemSection ovf:id=\"${nextId()}\">\n <Info>The kind of installed guest operating system</Info>\n </OperatingSystemSection>\n <VirtualHardwareSection>\n <Info>Virtual hardware requirements</Info>\n <System>\n <vssd:ElementName>Virtual Hardware Family</vssd:ElementName>\n <vssd:InstanceID>0</vssd:InstanceID>\n <vssd:VirtualSystemIdentifier>${vmName}</vssd:VirtualSystemIdentifier>\n <vssd:VirtualSystemType>vmx-11</vssd:VirtualSystemType>\n </System>\n <Item>\n <rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>\n <rasd:Description>Number of Virtual CPUs</rasd:Description>\n <rasd:ElementName>${cpuCount} virtual CPU(s)</rasd:ElementName>\n <rasd:InstanceID>1</rasd:InstanceID>\n <rasd:ResourceType>3</rasd:ResourceType>\n <rasd:VirtualQuantity>${cpuCount}</rasd:VirtualQuantity>\n </Item>\n <Item>\n <rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits>\n <rasd:Description>Memory Size</rasd:Description>\n <rasd:ElementName>${vmMemoryMB}MB of memory</rasd:ElementName>\n <rasd:InstanceID>2</rasd:InstanceID>\n <rasd:ResourceType>4</rasd:ResourceType>\n <rasd:VirtualQuantity>${vmMemoryMB}</rasd:VirtualQuantity>\n </Item>\n <Item>\n <rasd:Address>0</rasd:Address>\n <rasd:Description>IDE Controller</rasd:Description>\n <rasd:ElementName>VirtualIDEController 0</rasd:ElementName>\n <rasd:InstanceID>4</rasd:InstanceID>\n <rasd:ResourceType>5</rasd:ResourceType>\n </Item>\n <Item ovf:required=\"false\">\n <rasd:AutomaticAllocation>false</rasd:AutomaticAllocation>\n <rasd:ElementName>VirtualVideoCard</rasd:ElementName>\n <rasd:InstanceID>5</rasd:InstanceID>\n <rasd:ResourceType>24</rasd:ResourceType>\n </Item>\n${diskSection.diskItems}\n${networkSection.nicsSection}\n </VirtualHardwareSection>\n <AnnotationSection ovf:required=\"false\">\n <Info>A human-readable annotation</Info>\n <Annotation>${vmDescription}</Annotation>\n </AnnotationSection>\n </VirtualSystem>\n</ovf:Envelope>`\n}\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,CAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAAiC,SAAAD,uBAAAK,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAe1B,eAAeG,UAAUA,CAC9BC,SAAS,EACT;EAAEC,MAAM;EAAEC,aAAa,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