Exemple #1
0
 ///<summary>Initializes a new instance of the <see cref="VirtualHardDisk"/> class of the specified format, type, size, and path.</summary>
 ///<param name="format">The file format of the virtual hard disk file.</param>
 ///<param name="type">The type of virtual hard disk.</param>
 ///<param name="size">The size in GB of the virtual hard disk.</param>
 ///<param name="path">The path for the virtual hard disk file.</param>
 public VirtualHardDisk(VirtualHardDiskFormat format, VirtualHardDiskType type, UInt64 size, string path)
 {
     Format = format;
     Path   = path;
     Size   = size;
     Type   = type;
 }
Exemple #2
0
        CreateVirtualHardDisk(
            string ServerName,
            string VirtualHardDiskPath,
            string ParentPath,
            VirtualHardDiskType Type,
            VirtualHardDiskFormat Format,
            Int64 FileSize,
            Int32 BlockSize,
            Int32 LogicalSectorSize,
            Int32 PhysicalSectorSize)
        {
            ManagementScope scope =
                new ManagementScope("\\\\" + ServerName + "\\root\\virtualization\\v2");

            VirtualHardDiskSettingData settingData =
                new VirtualHardDiskSettingData(
                    Type,
                    Format,
                    VirtualHardDiskPath,
                    ParentPath,
                    FileSize,
                    BlockSize,
                    LogicalSectorSize,
                    PhysicalSectorSize);

            using (ManagementObject imageManagementService =
                       StorageUtilities.GetImageManagementService(scope))
            {
                using (ManagementBaseObject inParams =
                           imageManagementService.GetMethodParameters("CreateVirtualHardDisk"))
                {
                    inParams["VirtualDiskSettingData"] =
                        settingData.GetVirtualHardDiskSettingDataEmbeddedInstance(
                            ServerName,
                            imageManagementService.Path.Path);

                    using (ManagementBaseObject outParams = imageManagementService.InvokeMethod(
                               "CreateVirtualHardDisk", inParams, null))
                    {
                        WmiUtilities.ValidateOutput(outParams, scope);
                    }
                }
            }
        }
        CreateVirtualHardDisk(
            string ServerName,
            string VirtualHardDiskPath,
            string ParentPath,
            VirtualHardDiskType Type,
            VirtualHardDiskFormat Format,
            Int64 FileSize,
            Int32 BlockSize,
            Int32 LogicalSectorSize,
            Int32 PhysicalSectorSize)
        {
            ManagementScope scope =
                new ManagementScope("\\\\" + ServerName + "\\root\\virtualization\\v2");

            VirtualHardDiskSettingData settingData =
                new VirtualHardDiskSettingData(
                    Type,
                    Format,
                    VirtualHardDiskPath,
                    ParentPath,
                    FileSize,
                    BlockSize,
                    LogicalSectorSize,
                    PhysicalSectorSize);

            using (ManagementObject imageManagementService =
                StorageUtilities.GetImageManagementService(scope))
            {
                using (ManagementBaseObject inParams =
                    imageManagementService.GetMethodParameters("CreateVirtualHardDisk"))
                {
                    inParams["VirtualDiskSettingData"] =
                        settingData.GetVirtualHardDiskSettingDataEmbeddedInstance(
                            ServerName,
                            imageManagementService.Path.Path);

                    using (ManagementBaseObject outParams = imageManagementService.InvokeMethod(
                        "CreateVirtualHardDisk", inParams, null))
                    {
                        WmiUtilities.ValidateOutput(outParams, scope);
                    }
                }
            }
        }
 VirtualHardDiskSettingData(
     VirtualHardDiskType diskType,
     VirtualHardDiskFormat diskFormat,
     string path,
     string parentPath,
     Int64 maxInternalSize,
     Int32 blockSize,
     Int32 logicalSectorSize,
     Int32 physicalSectorSize)
 {
     m_DiskType           = diskType;
     m_DiskFormat         = diskFormat;
     m_Path               = path;
     m_ParentPath         = parentPath;
     m_MaxInternalSize    = maxInternalSize;
     m_BlockSize          = blockSize;
     m_LogicalSectorSize  = logicalSectorSize;
     m_PhysicalSectorSize = physicalSectorSize;
 }
        ConvertVirtualHardDisk(
            string ServerName,
            string SourcePath,
            string DestinationPath,
            VirtualHardDiskFormat Format)
        {
            ManagementScope scope =
                new ManagementScope("\\\\" + ServerName + "\\root\\virtualization\\v2");

            VirtualHardDiskSettingData settingData =
                new VirtualHardDiskSettingData(
                    VirtualHardDiskType.FixedSize,
                    Format,
                    DestinationPath,
                    null,
                    0,
                    0,
                    0,
                    0);

            using (ManagementObject imageManagementService =
                StorageUtilities.GetImageManagementService(scope))
            {
                using (ManagementBaseObject inParams =
                    imageManagementService.GetMethodParameters("ConvertVirtualHardDisk"))
                {
                    inParams["SourcePath"] = SourcePath;

                    inParams["VirtualDiskSettingData"] =
                        settingData.GetVirtualHardDiskSettingDataEmbeddedInstance(
                            ServerName,
                            imageManagementService.Path.Path);

                    using (ManagementBaseObject outParams = imageManagementService.InvokeMethod(
                        "ConvertVirtualHardDisk", inParams, null))
                    {
                        WmiUtilities.ValidateOutput(outParams, scope);
                    }
                }
            }
        }
Exemple #6
0
        ConvertVirtualHardDisk(
            string ServerName,
            string SourcePath,
            string DestinationPath,
            VirtualHardDiskFormat Format)
        {
            ManagementScope scope =
                new ManagementScope("\\\\" + ServerName + "\\root\\virtualization\\v2");

            VirtualHardDiskSettingData settingData =
                new VirtualHardDiskSettingData(
                    VirtualHardDiskType.FixedSize,
                    Format,
                    DestinationPath,
                    null,
                    0,
                    0,
                    0,
                    0);

            using (ManagementObject imageManagementService =
                       StorageUtilities.GetImageManagementService(scope))
            {
                using (ManagementBaseObject inParams =
                           imageManagementService.GetMethodParameters("ConvertVirtualHardDisk"))
                {
                    inParams["SourcePath"] = SourcePath;

                    inParams["VirtualDiskSettingData"] =
                        settingData.GetVirtualHardDiskSettingDataEmbeddedInstance(
                            ServerName,
                            imageManagementService.Path.Path);

                    using (ManagementBaseObject outParams = imageManagementService.InvokeMethod(
                               "ConvertVirtualHardDisk", inParams, null))
                    {
                        WmiUtilities.ValidateOutput(outParams, scope);
                    }
                }
            }
        }
 public VirtualHardDiskInfo(long fileSize, bool inSavedState, bool inUse, long maxInternalSize, string parentPath, VirtualHardDiskType diskType,
                            bool supportPersistentReservations, ulong maximumIOPS, ulong minimumIOPS, ControllerType vhdControllerType, int controllerNumber, int controllerLocation,
                            string name, string path, VirtualHardDiskFormat diskFormat, bool attached, uint blockSizeBytes)
 {
     FileSize        = fileSize;
     InSavedState    = inSavedState;
     InUse           = inUse;
     MaxInternalSize = maxInternalSize;
     ParentPath      = parentPath;
     DiskType        = diskType;
     SupportPersistentReservations = supportPersistentReservations;
     MaximumIOPS        = maximumIOPS;
     MinimumIOPS        = minimumIOPS;
     VHDControllerType  = vhdControllerType;
     ControllerNumber   = controllerNumber;
     ControllerLocation = controllerLocation;
     Name           = name;
     Path           = path;
     DiskFormat     = diskFormat;
     Attached       = attached;
     BlockSizeBytes = blockSizeBytes;
 }
        Parse(
            string embeddedInstance)
        {
            VirtualHardDiskType   type   = VirtualHardDiskType.Unknown;
            VirtualHardDiskFormat format = VirtualHardDiskFormat.Unknown;
            string path               = string.Empty;
            string parentPath         = string.Empty;
            Int64  maxInternalSize    = 0;
            Int32  blockSize          = 0;
            Int32  logicalSectorSize  = 0;
            Int32  physicalSectorSize = 0;

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(embeddedInstance);

            XmlNodeList nodelist = doc.SelectNodes(@"/INSTANCE/@CLASSNAME");

            if (nodelist.Count != 1)
            {
                throw new FormatException();
            }

            if (nodelist[0].Value != "Msvm_VirtualHardDiskSettingData")
            {
                throw new FormatException();
            }

            // Disk type
            nodelist = doc.SelectNodes(@"//PROPERTY[@NAME = 'Type']/VALUE/child::text()");
            if (nodelist.Count != 1)
            {
                throw new FormatException();
            }

            int itype =
                int.Parse(nodelist[0].Value, NumberStyles.None, CultureInfo.InvariantCulture);

            type = (VirtualHardDiskType)itype;

            if (type != VirtualHardDiskType.Differencing &&
                type != VirtualHardDiskType.DynamicallyExpanding &&
                type != VirtualHardDiskType.FixedSize)
            {
                // The type integer returned is of an unrecognized type.
                throw new FormatException();
            }

            // Disk format
            nodelist = doc.SelectNodes(@"//PROPERTY[@NAME = 'Format']/VALUE/child::text()");
            if (nodelist.Count != 1)
            {
                throw new FormatException();
            }

            int iformat =
                int.Parse(nodelist[0].Value, NumberStyles.None, CultureInfo.InvariantCulture);

            format = (VirtualHardDiskFormat)iformat;

            if (format != VirtualHardDiskFormat.Vhd &&
                format != VirtualHardDiskFormat.Vhdx)
            {
                //The format integer returned is of an unrecognized type.
                throw new FormatException();
            }

            // Path
            nodelist = doc.SelectNodes(@"//PROPERTY[@NAME = 'Path']/VALUE/child::text()");

            if (nodelist.Count != 1)
            {
                // There can not be multiple parents.
                throw new FormatException();
            }

            path = nodelist[0].Value;

            // ParentPath
            nodelist = doc.SelectNodes(@"//PROPERTY[@NAME = 'ParentPath']/VALUE/child::text()");

            // A nodeList.Count == 0 is okay and indicates that there is no parent.

            if (nodelist.Count == 1)
            {
                parentPath = nodelist[0].Value;
            }
            else if (nodelist.Count != 0)
            {
                // There can not be multiple parents.
                throw new FormatException();
            }

            if (type == VirtualHardDiskType.Differencing && string.IsNullOrEmpty(parentPath))
            {
                // Parent path must be set if this is a differencing disk.
                throw new FormatException();
            }

            // MaxInternalSize
            nodelist =
                doc.SelectNodes(@"//PROPERTY[@NAME = 'MaxInternalSize']/VALUE/child::text()");
            if (nodelist.Count != 1)
            {
                throw new FormatException();
            }

            maxInternalSize = Int64.Parse(nodelist[0].Value, CultureInfo.InvariantCulture);

            // BlockSize
            nodelist =
                doc.SelectNodes(@"//PROPERTY[@NAME = 'BlockSize']/VALUE/child::text()");
            if (nodelist.Count != 1)
            {
                throw new FormatException();
            }

            blockSize = Int32.Parse(nodelist[0].Value, CultureInfo.InvariantCulture);

            // LogicalSectorSize
            nodelist =
                doc.SelectNodes(@"//PROPERTY[@NAME = 'LogicalSectorSize']/VALUE/child::text()");
            if (nodelist.Count != 1)
            {
                throw new FormatException();
            }

            logicalSectorSize = Int32.Parse(nodelist[0].Value, CultureInfo.InvariantCulture);

            // PhysicalSectorSize
            nodelist =
                doc.SelectNodes(@"//PROPERTY[@NAME = 'PhysicalSectorSize']/VALUE/child::text()");
            if (nodelist.Count != 1)
            {
                throw new FormatException();
            }

            physicalSectorSize = Int32.Parse(nodelist[0].Value, CultureInfo.InvariantCulture);

            return(new VirtualHardDiskSettingData(type, format, path, parentPath,
                                                  maxInternalSize, blockSize, logicalSectorSize, physicalSectorSize));
        }
 VirtualHardDiskSettingData(
     VirtualHardDiskType diskType,
     VirtualHardDiskFormat diskFormat,
     string path,
     string parentPath,
     Int64 maxInternalSize,
     Int32 blockSize,
     Int32 logicalSectorSize,
     Int32 physicalSectorSize)
 {
     m_DiskType = diskType;
     m_DiskFormat = diskFormat;
     m_Path = path;
     m_ParentPath = parentPath;
     m_MaxInternalSize = maxInternalSize;
     m_BlockSize = blockSize;
     m_LogicalSectorSize = logicalSectorSize;
     m_PhysicalSectorSize = physicalSectorSize;
 }