示例#1
0
        public bool TryCalcRequiredDiskCapacity(out ulong capacity)
        {
            capacity = 0;

            if (file == null)
            {
                return(false);
            }

            VirtualDiskDesc_Type disk = OVF.FindDiskReference(envelope, rasd);

            capacity = disk != null && !string.IsNullOrEmpty(disk.capacity)
                ? Convert.ToUInt64(OVF.ComputeCapacity(Convert.ToInt64(disk.capacity), disk.capacityAllocationUnits))
                : file.size;

            return(true);
        }
示例#2
0
        public DiskElements CreateDiskModels(IList <Disk> diskModels)
        {
            var diskFiles  = new List <File_Type>();
            var disks      = new List <VirtualDiskDesc_Type>();
            var diskDrives = new List <RASD_Type>();

            int ideDiskCount  = 0;
            int scsiDiskCount = 0;

            for (var i = 0; i < diskModels.Count; i++)
            {
                var diskModel = diskModels[i];
                var diskFile  = new File_Type {
                    href = diskModel.Path, id = "diskFile" + i, sizeSpecified = true, size = diskModel.FileSize
                };
                var disk = new VirtualDiskDesc_Type
                {
                    fileRef  = diskFile.id,
                    diskId   = "diskId" + i,
                    capacity = diskModels[i].CapacityMb.ToString(),
                    format   = formatStringLookup[diskModels[i].Format],
                    capacityAllocationUnits = "byte * 2^20"
                };

                string parent;
                int    addressOnParent;
                if (diskModel.ControllerType == ControllerType.IDE)
                {
                    parent          = "ide" + ideDiskCount / 2;
                    addressOnParent = ideDiskCount % 2;
                    ideDiskCount++;
                }
                else
                {
                    parent          = "scsi0";
                    addressOnParent = scsiDiskCount;
                    scsiDiskCount++;
                }

                var diskDrive = new RASD_Type
                {
                    AddressOnParent = new cimString {
                        Value = addressOnParent.ToString()
                    },
                    AutomaticAllocation = new cimBoolean {
                        Value = false
                    },
                    AutomaticDeallocation = new cimBoolean {
                        Value = false
                    },
                    InstanceID = new cimString {
                        Value = disk.diskId
                    },
                    ElementName = new cimString {
                        Value = "Disk " + disk.diskId
                    },
                    ResourceType = new ResourceType {
                        Value = "17"
                    },
                    HostResource = new[] { new cimString {
                                               Value = "ovf:/disk/" + disk.diskId
                                           } },
                    Parent = new cimString {
                        Value = parent
                    }
                };

                diskFiles.Add(diskFile);
                disks.Add(disk);
                diskDrives.Add(diskDrive);
            }

            return(new DiskElements(diskFiles, disks, diskDrives));
        }