Beispiel #1
0
        /// <summary>
        /// Initiates the build process.
        /// </summary>
        /// <param name="baseName">The base name for the VMDK, for example 'foo' to create 'foo.vmdk'.</param>
        /// <returns>A set of one or more logical files that constitute the VMDK.  The first file is
        /// the 'primary' file that is normally attached to VMs.</returns>
        public override DiskImageFileSpecification[] Build(string baseName)
        {
            if (string.IsNullOrEmpty(baseName))
            {
                throw new ArgumentException("Invalid base file name", "baseName");
            }

            if (Content == null)
            {
                throw new InvalidOperationException("No content stream specified");
            }

            if (_diskType != DiskCreateType.Vmfs && _diskType != DiskCreateType.VmfsSparse && _diskType != DiskCreateType.MonolithicSparse)
            {
                throw new NotImplementedException("Only MonolithicSparse, Vmfs and VmfsSparse disks implemented");
            }

            List <DiskImageFileSpecification> fileSpecs = new List <DiskImageFileSpecification>();

            Geometry geometry     = Geometry ?? DiskImageFile.DefaultGeometry(Content.Length);
            Geometry biosGeometry = BiosGeometry ?? Geometry.LbaAssistedBiosGeometry(Content.Length);

            DescriptorFile baseDescriptor = DiskImageFile.CreateSimpleDiskDescriptor(geometry, biosGeometry, _diskType, _adapterType);

            if (_diskType == DiskCreateType.Vmfs)
            {
                ExtentDescriptor extent = new ExtentDescriptor(ExtentAccess.ReadWrite, Content.Length / 512, ExtentType.Vmfs, baseName + "-flat.vmdk", 0);
                baseDescriptor.Extents.Add(extent);

                MemoryStream ms = new MemoryStream();
                baseDescriptor.Write(ms);

                fileSpecs.Add(new DiskImageFileSpecification(baseName + ".vmdk", new PassthroughStreamBuilder(ms)));
                fileSpecs.Add(new DiskImageFileSpecification(baseName + "-flat.vmdk", new PassthroughStreamBuilder(Content)));
            }
            else if (_diskType == DiskCreateType.VmfsSparse)
            {
                ExtentDescriptor extent = new ExtentDescriptor(ExtentAccess.ReadWrite, Content.Length / 512, ExtentType.VmfsSparse, baseName + "-sparse.vmdk", 0);
                baseDescriptor.Extents.Add(extent);

                MemoryStream ms = new MemoryStream();
                baseDescriptor.Write(ms);

                fileSpecs.Add(new DiskImageFileSpecification(baseName + ".vmdk", new PassthroughStreamBuilder(ms)));
                fileSpecs.Add(new DiskImageFileSpecification(baseName + "-sparse.vmdk", new VmfsSparseExtentBuilder(Content)));
            }
            else if (_diskType == DiskCreateType.MonolithicSparse)
            {
                ExtentDescriptor extent = new ExtentDescriptor(ExtentAccess.ReadWrite, Content.Length / 512, ExtentType.Sparse, baseName + ".vmdk", 0);
                baseDescriptor.Extents.Add(extent);
                fileSpecs.Add(new DiskImageFileSpecification(baseName + ".vmdk", new MonolithicSparseExtentBuilder(Content, baseDescriptor)));
            }

            return(fileSpecs.ToArray());
        }
Beispiel #2
0
 internal static VirtualDiskTypeInfo MakeDiskTypeInfo(DiskCreateType createType)
 {
     return(new VirtualDiskTypeInfo()
     {
         Name = "VMDK",
         Variant = CreateTypeToVariant(createType),
         CanBeHardDisk = true,
         DeterministicGeometry = false,
         PreservesBiosGeometry = false,
         CalcGeometry = c => DiskImageFile.DefaultGeometry(c),
     });
 }