• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# HypervResource.WmiException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中HypervResource.WmiException的典型用法代码示例。如果您正苦于以下问题:C# WmiException类的具体用法?C# WmiException怎么用?C# WmiException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



WmiException类属于HypervResource命名空间,在下文中一共展示了WmiException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetVirtualSwitchManagementService

        public VirtualEthernetSwitchManagementService GetVirtualSwitchManagementService()
        {
            // VirtualSwitchManagementService is a singleton, most anonymous way of lookup is by asking for the set
            // of local instances, which should be size 1.
            var virtSwtichSvcCollection = VirtualEthernetSwitchManagementService.GetInstances();
            foreach (VirtualEthernetSwitchManagementService item in virtSwtichSvcCollection)
            {
                return item;
            }

            var errMsg = string.Format("No Hyper-V subsystem on server");
            var ex = new WmiException(errMsg);
            logger.Error(errMsg, ex);
            throw ex;
        }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:15,代码来源:WmiCallsV2.cs


示例2: CreateDynamicVirtualHardDisk

        /// <summary>
        /// Always produces a VHDX.
        /// </summary>
        /// <param name="MaxInternalSize"></param>
        /// <param name="Path"></param>
        public void CreateDynamicVirtualHardDisk(ulong MaxInternalSize, string Path)
        {
            // Produce description of the virtual disk in the format of a Msvm_VirtualHardDiskSettings object

            // Example at http://www.getcodesamples.com/src/FC025DDC/76689747, but
            // Is there a template we can use to fill in the settings?
            var newVirtHDSettings = VirtualHardDiskSettingData.CreateInstance();
            newVirtHDSettings.LateBoundObject["Type"] = 3; // Dynamic
            newVirtHDSettings.LateBoundObject["Format"] = 3; // VHDX
            newVirtHDSettings.LateBoundObject["Path"] = Path;
            newVirtHDSettings.LateBoundObject["MaxInternalSize"] = MaxInternalSize;
            newVirtHDSettings.LateBoundObject["BlockSize"] = 0; // Use defaults
            newVirtHDSettings.LateBoundObject["LogicalSectorSize"] = 0; // Use defaults
            newVirtHDSettings.LateBoundObject["PhysicalSectorSize"] = 0; // Use defaults

            // Optional: newVirtHDSettings.CommitObject();

            // Add the new vhd object as a virtual hard disk to the vm.
            string newVirtHDSettingsString = newVirtHDSettings.LateBoundObject.GetText(System.Management.TextFormat.CimDtd20);

            // Resource settings are changed through the management service
            System.Management.ManagementPath jobPath;
            var imgMgr = GetImageManagementService();
            var ret_val = imgMgr.CreateVirtualHardDisk(newVirtHDSettingsString, out jobPath);

            // If the Job is done asynchronously
            if (ret_val == ReturnCode.Started)
            {
                StorageJobCompleted(jobPath);
            }
            else if (ret_val != ReturnCode.Completed)
            {
                var errMsg = string.Format(
                    "Failed to CreateVirtualHardDisk size {0}, path {1} due to {2}",
                    MaxInternalSize,
                    Path,
                    ReturnCode.ToString(ret_val));
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }
        }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:47,代码来源:WmiCallsV2.cs


示例3: DeleteHostKvpItem

        public void DeleteHostKvpItem(ComputerSystem vm, string key)
        {
            // Obtain controller for Hyper-V virtualisation subsystem
            VirtualSystemManagementService vmMgmtSvc = GetVirtualisationSystemManagementService();

            // Create object to hold the data.
            KvpExchangeDataItem kvpItem = KvpExchangeDataItem.CreateInstance();
            kvpItem.LateBoundObject["Name"] = WmiCallsV2.CloudStackUserDataKey;
            kvpItem.LateBoundObject["Data"] = "dummy";
            kvpItem.LateBoundObject["Source"] = 0;
            logger.Debug("VM " + vm.Name + " will have KVP key " + key + " removed.");

            String kvpStr = kvpItem.LateBoundObject.GetText(TextFormat.CimDtd20);

            // Update the resource settings for the VM.
            ManagementPath jobPath;

            uint ret_val = vmMgmtSvc.RemoveKvpItems(new String[] { kvpStr }, vm.Path, out jobPath);

            // If the Job is done asynchronously
            if (ret_val == ReturnCode.Started)
            {
                JobCompleted(jobPath);
            }
            else if (ret_val != ReturnCode.Completed)
            {
                var errMsg = string.Format(
                    "Failed to update VM {0} (GUID {1}) due to {2} (ModifyVirtualSystem call), existing VM not deleted",
                    vm.ElementName,
                    vm.Name,
                    ReturnCode.ToString(ret_val));
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }
        }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:36,代码来源:WmiCallsV2.cs


示例4: SetBandWidthLimit

        private void SetBandWidthLimit(ulong limit, EthernetPortAllocationSettingData portPath)
        {
            logger.DebugFormat("Setting network rate limit to {0}", limit);

            var vmVirtMgmtSvc = GetVirtualisationSystemManagementService();
            var bandwidthSettings = EthernetSwitchPortBandwidthSettingData.GetInstances(vmVirtMgmtSvc.Scope, "InstanceID LIKE \"%Default\"");

            // Assert
            if (bandwidthSettings.Count != 1)
            {
                var errMsg = string.Format("Internal error, could not find default EthernetSwitchPortBandwidthSettingData instance");
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }
            var defaultBandwidthSettings = bandwidthSettings.OfType<EthernetSwitchPortBandwidthSettingData>().First();

            var newBandwidthSettings = new EthernetSwitchPortBandwidthSettingData((ManagementBaseObject)defaultBandwidthSettings.LateBoundObject.Clone());
            newBandwidthSettings.Limit = limit * 1000000;

            // Insert bandwidth settings to nic
            string[] newResources = new string[] { newBandwidthSettings.LateBoundObject.GetText(System.Management.TextFormat.CimDtd20) };
            ManagementPath[] newResourcePaths = AddFeatureSettings(newResources, portPath.Path);

            // assert
            if (newResourcePaths.Length != 1)
            {
                var errMsg = string.Format(
                    "Failed to properly apply network rate limit {0} for NIC on port {1}",
                    limit,
                    portPath.Path);
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }
        }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:36,代码来源:WmiCallsV2.cs


示例5: GetExternalVirtSwitch

        /// <summary>
        /// External VSwitch has an external NIC, and we assume there is only one external NIC and one external vswitch.
        /// </summary>
        /// <param name="vmSettings"></param>
        /// <returns></returns>
        /// <throw>Throws if there is no vswitch</throw>
        /// <remarks>
        /// With V1 API, external ethernet port was attached to the land endpoint, which was attached to the switch.
        /// e.g. Msvm_ExternalEthernetPort -> SwitchLANEndpoint -> SwitchPort -> VirtualSwitch
        /// 
        /// With V2 API, there are two kinds of lan endpoint:  one on the computer system and one on the switch
        /// e.g. Msvm_ExternalEthernetPort -> LANEndpoint -> LANEdnpoint -> EthernetSwitchPort -> VirtualEthernetSwitch
        /// </remarks>
        public static VirtualEthernetSwitch GetExternalVirtSwitch(String vSwitchName)
        {
            // Work back from the first *bound* external NIC we find.
            var externNICs = ExternalEthernetPort.GetInstances("IsBound = TRUE");
            VirtualEthernetSwitch vSwitch = null;
            // Assert
            if (externNICs.Count == 0 )
            {
                var errMsg = "No ExternalEthernetPort available to Hyper-V";
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }
            foreach(ExternalEthernetPort externNIC in externNICs.OfType<ExternalEthernetPort>()) {
            // A sequence of ASSOCIATOR objects need to be traversed to get from external NIC the vswitch.
            // We use ManagementObjectSearcher objects to execute this sequence of questions
            // NB: default scope of ManagementObjectSearcher is '\\.\root\cimv2', which does not contain
            // the virtualisation objects.
            var endpointQuery = new RelatedObjectQuery(externNIC.Path.Path, LANEndpoint.CreatedClassName);
            var endpointSearch = new ManagementObjectSearcher(externNIC.Scope, endpointQuery);
            var endpointCollection = new LANEndpoint.LANEndpointCollection(endpointSearch.Get());

            // assert
            if (endpointCollection.Count < 1 )
            {
                var errMsg = string.Format("No adapter-based LANEndpoint for external NIC {0} on Hyper-V server", externNIC.Name);
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }

            LANEndpoint adapterEndPoint = endpointCollection.OfType<LANEndpoint>().First();
            var switchEndpointQuery = new RelatedObjectQuery(adapterEndPoint.Path.Path, LANEndpoint.CreatedClassName);
            var switchEndpointSearch = new ManagementObjectSearcher(externNIC.Scope, switchEndpointQuery);
            var switchEndpointCollection = new LANEndpoint.LANEndpointCollection(switchEndpointSearch.Get());

            // assert
            if (endpointCollection.Count < 1)
            {
                var errMsg = string.Format("No Switch-based LANEndpoint for external NIC {0} on Hyper-V server", externNIC.Name);
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }

            LANEndpoint switchEndPoint = switchEndpointCollection.OfType<LANEndpoint>().First();
            var switchPortQuery = new RelatedObjectQuery(switchEndPoint.Path.Path, EthernetSwitchPort.CreatedClassName);
            var switchPortSearch = new ManagementObjectSearcher(switchEndPoint.Scope, switchPortQuery);
            var switchPortCollection = new EthernetSwitchPort.EthernetSwitchPortCollection(switchPortSearch.Get());

            // assert
            if (switchPortCollection.Count < 1 )
            {
                var errMsg = string.Format("No SwitchPort for external NIC {0} on Hyper-V server", externNIC.Name);
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }

            EthernetSwitchPort switchPort = switchPortCollection.OfType<EthernetSwitchPort>().First();
            var vSwitchQuery = new RelatedObjectQuery(switchPort.Path.Path, VirtualEthernetSwitch.CreatedClassName);
            var vSwitchSearch = new ManagementObjectSearcher(externNIC.Scope, vSwitchQuery);
            var vSwitchCollection = new VirtualEthernetSwitch.VirtualEthernetSwitchCollection(vSwitchSearch.Get());

            // assert
            if (vSwitchCollection.Count < 1)
            {
                var errMsg = string.Format("No virtual switch for external NIC {0} on Hyper-V server", externNIC.Name);
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }
            vSwitch = vSwitchCollection.OfType<VirtualEthernetSwitch>().First();
            if (vSwitch.ElementName.Equals(vSwitchName) == true)
            {
                return vSwitch;
            }
            }
            return vSwitch;
        }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:93,代码来源:WmiCallsV2.cs


示例6: InsertDiskImage

        private void InsertDiskImage(ComputerSystem vm, string diskImagePath, string diskResourceSubType, ManagementPath drivePath)
        {
            // A description of the disk is created by modifying a clone of the default ResourceAllocationSettingData for that disk type
            string defaultDiskQuery = String.Format("ResourceSubType LIKE \"{0}\" AND InstanceID LIKE \"%Default\"", diskResourceSubType);
            var newDiskSettings = CloneStorageAllocationSetting(defaultDiskQuery);

            // Set file containing the disk image
            newDiskSettings.LateBoundObject["Parent"] = drivePath.Path;

            // V2 API uses HostResource to specify image, see http://msdn.microsoft.com/en-us/library/hh859775(v=vs.85).aspx
            newDiskSettings.LateBoundObject["HostResource"] = new string[] { diskImagePath };
            newDiskSettings.CommitObject();

            // Add the new Msvm_StorageAllocationSettingData object as a virtual hard disk to the vm.
            string[] newDiskResource = new string[] { newDiskSettings.LateBoundObject.GetText(System.Management.TextFormat.CimDtd20) };
            ManagementPath[] newDiskPaths = AddStorageResource(newDiskResource, vm);
            // assert
            if (newDiskPaths.Length != 1)
            {
                var errMsg = string.Format(
                    "Failed to add disk image type {3} to VM {0} (GUID {1}): number of resource created {2}",
                    vm.ElementName,
                    vm.Name,
                    newDiskPaths.Length,
                    diskResourceSubType);
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }
            logger.InfoFormat("Created disk {2} for VM {0} (GUID {1}), image {3} ",
                    vm.ElementName,
                    vm.Name,
                    newDiskPaths[0].Path,
                    diskImagePath);
        }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:35,代码来源:WmiCallsV2.cs


示例7: RemoveStorageImage

        /// <summary>
        /// Removes a disk image from a drive, but does not remove the drive itself.
        /// </summary>
        /// <param name="vm"></param>
        /// <param name="diskFileName"></param>
        private void RemoveStorageImage(ComputerSystem vm, string diskFileName)
        {
            // Obtain StorageAllocationSettingData for disk
            StorageAllocationSettingData.StorageAllocationSettingDataCollection storageSettingsObjs = StorageAllocationSettingData.GetInstances();

            StorageAllocationSettingData imageToRemove = null;
            foreach (StorageAllocationSettingData item in storageSettingsObjs)
            {
                if (item.HostResource == null || item.HostResource.Length != 1)
                {
                    continue;
                }

                string hostResource = item.HostResource[0];
                if (Path.Equals(hostResource, diskFileName))
                {
                    imageToRemove = item;
                    break;
                }
            }

            // assert
            if (imageToRemove  == null)
            {
                var errMsg = string.Format(
                    "Failed to remove disk image {0} from VM {1} (GUID {2}): the disk image is not attached.",
                    diskFileName,
                    vm.ElementName,
                    vm.Name);
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }

            RemoveStorageResource(imageToRemove.Path, vm);

            logger.InfoFormat("Removed disk image {0} from VM {1} (GUID {2}): the disk image is not attached.",
                    diskFileName,
                    vm.ElementName,
                    vm.Name);
        }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:46,代码来源:WmiCallsV2.cs


示例8: SetState

        public void SetState(ComputerSystem vm, ushort requiredState)
        {
            logger.InfoFormat(
                "Changing state of {0} (GUID {1}) to {2}",
                vm.ElementName,
                vm.Name,
                RequiredState.ToString(requiredState));

            ManagementPath jobPath;
            // DateTime is unused
            var ret_val = vm.RequestStateChange(requiredState, new DateTime(), out jobPath);

            // If the Job is done asynchronously
            if (ret_val == ReturnCode.Started)
            {
                JobCompleted(jobPath);
            }
            else if (ret_val == 32775)
            {   // TODO: check
                logger.InfoFormat("RequestStateChange returned 32775, which means vm in wrong state for requested state change.  Treating as if requested state was reached");
            }
            else if (ret_val != ReturnCode.Completed)
            {
                var errMsg = string.Format(
                    "Failed to change state of VM {0} (GUID {1}) to {2} due to {3}",
                    vm.ElementName,
                    vm.Name,
                    RequiredState.ToString(requiredState),
                    ReturnCode.ToString(ret_val));
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }

            logger.InfoFormat(
                "Successfully changed vm state of {0} (GUID {1} to requested state {2}",
                vm.ElementName,
                vm.Name,
                requiredState);
        }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:40,代码来源:WmiCallsV2.cs


示例9: CloneStorageAllocationSetting

        /// <summary>
        /// Create new storage media resources, e.g. hard disk images and ISO disk images
        /// see http://msdn.microsoft.com/en-us/library/hh859775(v=vs.85).aspx
        /// </summary>
        /// <param name="wmiQuery"></param>
        /// <returns></returns>
        private static StorageAllocationSettingData CloneStorageAllocationSetting(string wmiQuery)
        {
            var defaultDiskImageSettingsObjs = StorageAllocationSettingData.GetInstances(wmiQuery);

            // assert
            if (defaultDiskImageSettingsObjs.Count != 1)
            {
                var errMsg = string.Format("Failed to find Msvm_StorageAllocationSettingData for the query {0}", wmiQuery);
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }

            StorageAllocationSettingData defaultDiskDriveSettings = defaultDiskImageSettingsObjs.OfType<StorageAllocationSettingData>().First();
            return new StorageAllocationSettingData((ManagementBaseObject)defaultDiskDriveSettings.LateBoundObject.Clone());
        }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:22,代码来源:WmiCallsV2.cs


示例10: MigrateVmWithVolume

        /// <summary>
        /// Migrates the volume of a vm to a given destination storage
        /// </summary>
        /// <param name="displayName"></param>
        /// <param name="destination host"></param>
        /// <param name="volumeToPool"> volume to me migrated to which pool</param>
        public void MigrateVmWithVolume(string vmName, string destination, Dictionary<string, string> volumeToPool)
        {
            ComputerSystem vm = GetComputerSystem(vmName);
            VirtualSystemSettingData vmSettings = GetVmSettings(vm);
            VirtualSystemMigrationSettingData migrationSettingData = VirtualSystemMigrationSettingData.CreateInstance();
            VirtualSystemMigrationService service = GetVirtualisationSystemMigrationService();
            StorageAllocationSettingData[] sasd = GetStorageSettings(vm);

            string[] rasds = null;
            if (sasd != null)
            {
                rasds = new string[sasd.Length];
                uint index = 0;
                foreach (StorageAllocationSettingData item in sasd)
                {
                    string vhdFileName = Path.GetFileNameWithoutExtension(item.HostResource[0]);
                    if (!String.IsNullOrEmpty(vhdFileName) && volumeToPool.ContainsKey(vhdFileName))
                    {
                        string newVhdPath = Path.Combine(volumeToPool[vhdFileName], Path.GetFileName(item.HostResource[0]));
                        item.LateBoundObject["HostResource"] = new string[] { newVhdPath };
                        item.LateBoundObject["PoolId"] = "";
                    }

                    rasds[index++] = item.LateBoundObject.GetText(System.Management.TextFormat.CimDtd20);
                }
            }

            IPAddress addr = IPAddress.Parse(destination);
            IPHostEntry entry = Dns.GetHostEntry(addr);
            string[] destinationHost = new string[] { destination };

            migrationSettingData.LateBoundObject["MigrationType"] = MigrationType.VirtualSystemAndStorage;
            migrationSettingData.LateBoundObject["TransportType"] = TransportType.TCP;
            migrationSettingData.LateBoundObject["DestinationIPAddressList"] = destinationHost;
            string migrationSettings = migrationSettingData.LateBoundObject.GetText(System.Management.TextFormat.CimDtd20);

            ManagementPath jobPath;
            var ret_val = service.MigrateVirtualSystemToHost(vm.Path, entry.HostName, migrationSettings, rasds, null, out jobPath);
            if (ret_val == ReturnCode.Started)
            {
                MigrationJobCompleted(jobPath);
            }
            else if (ret_val != ReturnCode.Completed)
            {
                var errMsg = string.Format(
                    "Failed migrating VM {0} and its volumes to destination {1} (GUID {2}) due to {3}",
                    vm.ElementName,
                    destination,
                    vm.Name,
                    ReturnCode.ToString(ret_val));
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }
        }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:61,代码来源:WmiCallsV2.cs


示例11: MigrateVolume

        /// <summary>
        /// Migrates the volume of a vm to a given destination storage
        /// </summary>
        /// <param name="displayName"></param>
        /// <param name="volume"></param>
        /// <param name="destination storage pool"></param>
        public void MigrateVolume(string vmName, string volume, string destination)
        {
            ComputerSystem vm = GetComputerSystem(vmName);
            VirtualSystemSettingData vmSettings = GetVmSettings(vm);
            VirtualSystemMigrationSettingData migrationSettingData = VirtualSystemMigrationSettingData.CreateInstance();
            VirtualSystemMigrationService service = GetVirtualisationSystemMigrationService();
            StorageAllocationSettingData[] sasd = GetStorageSettings(vm);

            string[] rasds = null;
            if (sasd != null)
            {
                rasds = new string[1];
                foreach (StorageAllocationSettingData item in sasd)
                {
                    string vhdFileName = Path.GetFileNameWithoutExtension(item.HostResource[0]);
                    if (!String.IsNullOrEmpty(vhdFileName) && vhdFileName.Equals(volume))
                    {
                        string newVhdPath = Path.Combine(destination, Path.GetFileName(item.HostResource[0]));
                        item.LateBoundObject["HostResource"] = new string[] { newVhdPath };
                        item.LateBoundObject["PoolId"] = "";
                        rasds[0] = item.LateBoundObject.GetText(System.Management.TextFormat.CimDtd20);
                        break;
                    }
                }
            }

            migrationSettingData.LateBoundObject["MigrationType"] = MigrationType.Storage;
            migrationSettingData.LateBoundObject["TransportType"] = TransportType.TCP;
            string migrationSettings = migrationSettingData.LateBoundObject.GetText(System.Management.TextFormat.CimDtd20);

            ManagementPath jobPath;
            var ret_val = service.MigrateVirtualSystemToHost(vm.Path, null, migrationSettings, rasds, null, out jobPath);
            if (ret_val == ReturnCode.Started)
            {
                MigrationJobCompleted(jobPath);
            }
            else if (ret_val != ReturnCode.Completed)
            {
                var errMsg = string.Format(
                    "Failed migrating volume {0} of VM {1} (GUID {2}) due to {3}",
                    volume,
                    vm.ElementName,
                    vm.Name,
                    ReturnCode.ToString(ret_val));
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }
        }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:55,代码来源:WmiCallsV2.cs


示例12: MigrateVm

        /// <summary>
        /// Migrates a vm to the given destination host
        /// </summary>
        /// <param name="desplayName"></param>
        /// <param name="destination host"></param>
        public void MigrateVm(string vmName, string destination)
        {
            ComputerSystem vm = GetComputerSystem(vmName);
            VirtualSystemMigrationSettingData migrationSettingData = VirtualSystemMigrationSettingData.CreateInstance();
            VirtualSystemMigrationService service = GetVirtualisationSystemMigrationService();

            IPAddress addr = IPAddress.Parse(destination);
            IPHostEntry entry = Dns.GetHostEntry(addr);
            string[] destinationHost = new string[] { destination };

            migrationSettingData.LateBoundObject["MigrationType"] = MigrationType.VirtualSystem;
            migrationSettingData.LateBoundObject["TransportType"] = TransportType.TCP;
            migrationSettingData.LateBoundObject["DestinationIPAddressList"] = destinationHost;
            string migrationSettings = migrationSettingData.LateBoundObject.GetText(System.Management.TextFormat.CimDtd20);

            ManagementPath jobPath;
            var ret_val = service.MigrateVirtualSystemToHost(vm.Path, entry.HostName, migrationSettings, null, null, out jobPath);
            if (ret_val == ReturnCode.Started)
            {
                MigrationJobCompleted(jobPath);
            }
            else if (ret_val != ReturnCode.Completed)
            {
                var errMsg = string.Format(
                    "Failed migrating VM {0} (GUID {1}) due to {2}",
                    vm.ElementName,
                    vm.Name,
                    ReturnCode.ToString(ret_val));
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }
        }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:38,代码来源:WmiCallsV2.cs


示例13: GetVmSettings

        public VirtualSystemSettingData GetVmSettings(ComputerSystem vm)
        {
            // An ASSOCIATOR object provides the cross reference from the ComputerSettings and the
            // VirtualSystemSettingData, but generated wrappers do not expose a ASSOCIATOR OF query as a method.
            // Instead, we use the System.Management to code the equivalant of
            //  string query = string.Format( "ASSOCIATORS OF {{{0}}} WHERE ResultClass = {1}", vm.path, resultclassName);
            //
            var wmiObjQuery = new RelatedObjectQuery(vm.Path.Path, VirtualSystemSettingData.CreatedClassName);

            // NB: default scope of ManagementObjectSearcher is '\\.\root\cimv2', which does not contain
            // the virtualisation objects.
            var wmiObjectSearch = new ManagementObjectSearcher(vm.Scope, wmiObjQuery);
            var wmiObjCollection = new VirtualSystemSettingData.VirtualSystemSettingDataCollection(wmiObjectSearch.Get());

            // When snapshots are taken into account, there can be multiple settings objects
            // take the first one that isn't a snapshot
            foreach (VirtualSystemSettingData wmiObj in wmiObjCollection)
            {
                if (wmiObj.VirtualSystemType == "Microsoft:Hyper-V:System:Realized" ||
                    wmiObj.VirtualSystemType == "Microsoft:Hyper-V:System:Planned")
                {
                    return wmiObj;
                }
            }

            var errMsg = string.Format("No VirtualSystemSettingData for VM {0}, path {1}", vm.ElementName, vm.Path.Path);
            var ex = new WmiException(errMsg);
            logger.Error(errMsg, ex);
            throw ex;
        }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:30,代码来源:WmiCallsV2.cs


示例14: GetVlanSettings

        public EthernetSwitchPortVlanSettingData GetVlanSettings(EthernetPortAllocationSettingData ethernetConnection)
        {
            // An ASSOCIATOR object provides the cross reference from the VirtualSystemSettingData and the
            // EthernetPortAllocationSettingData, but generated wrappers do not expose a ASSOCIATOR OF query as a method.
            // Instead, we use the System.Management to code the equivalant of
            //  string query = string.Format( "ASSOCIATORS OF {{{0}}} WHERE ResultClass = {1}", vmSettings.path, resultclassName);
            //
            var wmiObjQuery = new RelatedObjectQuery(ethernetConnection.Path.Path, EthernetSwitchPortVlanSettingData.CreatedClassName);

            // NB: default scope of ManagementObjectSearcher is '\\.\root\cimv2', which does not contain
            // the virtualisation objects.
            var wmiObjectSearch = new ManagementObjectSearcher(ethernetConnection.Scope, wmiObjQuery);
            var wmiObjCollection = new EthernetSwitchPortVlanSettingData.EthernetSwitchPortVlanSettingDataCollection(wmiObjectSearch.Get());

            if (wmiObjCollection.Count == 0)
            {
                return null;
            }

            // Assert
            if (wmiObjCollection.Count > 1)
            {
                var errMsg = string.Format("Internal error, morn one VLAN settings for a single ethernetConnection");
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }

            return wmiObjCollection.OfType<EthernetSwitchPortVlanSettingData>().First();
        }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:30,代码来源:WmiCallsV2.cs


示例15: AttachNewDrive

        private ManagementPath AttachNewDrive(ComputerSystem vm, string cntrllerAddr, string driveType)
        {
            // Disk drives are attached to a 'Parent' IDE controller.  We IDE Controller's settings for the 'Path', which our new Disk drive will use to reference it.
            VirtualSystemSettingData vmSettings = GetVmSettings(vm);
            var ctrller = GetIDEControllerSettings(vmSettings, cntrllerAddr);

            // A description of the drive is created by modifying a clone of the default ResourceAllocationSettingData for that drive type
            string defaultDriveQuery = String.Format("ResourceSubType LIKE \"{0}\" AND InstanceID LIKE \"%Default\"", driveType);
            var newDiskDriveSettings = CloneResourceAllocationSetting(defaultDriveQuery);

            // Set IDE controller and address on the controller for the new drive
            newDiskDriveSettings.LateBoundObject["Parent"] = ctrller.Path.ToString();
            newDiskDriveSettings.LateBoundObject["AddressOnParent"] = "0";
            newDiskDriveSettings.CommitObject();

            // Add this new disk drive to the VM
            logger.DebugFormat("Creating disk drive type {0}, parent IDE controller is {1} and address on controller is {2}",
                newDiskDriveSettings.ResourceSubType,
                newDiskDriveSettings.Parent,
                newDiskDriveSettings.AddressOnParent);
            string[] newDriveResource = new string[] { newDiskDriveSettings.LateBoundObject.GetText(System.Management.TextFormat.CimDtd20) };
            ManagementPath[] newDrivePaths = AddVirtualResource(newDriveResource, vm);

            // assert
            if (newDrivePaths.Length != 1)
            {
                var errMsg = string.Format(
                    "Failed to add disk drive type {3} to VM {0} (GUID {1}): number of resource created {2}",
                    vm.ElementName,
                    vm.Name,
                    newDrivePaths.Length,
                    driveType);
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }
            logger.DebugFormat("New disk drive type {0} WMI path is {1}s",
                newDiskDriveSettings.ResourceSubType,
                newDrivePaths[0].Path);
            return newDrivePaths[0];
        }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:41,代码来源:WmiCallsV2.cs


示例16: CreateDefaultVm

        private static ComputerSystem CreateDefaultVm(VirtualSystemManagementService vmMgmtSvc, string name)
        {
            // Tweak default settings by basing new VM on default global setting object
            // with designed display name.
            UInt16 startupAction = 2; // Do nothing.
            UInt16 stopAction = 4; // Shutdown.
            VirtualSystemSettingData vs_gs_data = VirtualSystemSettingData.CreateInstance();
            vs_gs_data.LateBoundObject["ElementName"] = name;
            vs_gs_data.LateBoundObject["AutomaticStartupAction"] = startupAction.ToString();
            vs_gs_data.LateBoundObject["AutomaticShutdownAction"] = stopAction.ToString();
            vs_gs_data.LateBoundObject["Notes"] = new string[] { "CloudStack creating VM, do not edit. \n" };

            System.Management.ManagementPath jobPath;
            System.Management.ManagementPath defined_sys;
            var ret_val = vmMgmtSvc.DefineSystem(
                null,
                new string[0],
                vs_gs_data.LateBoundObject.GetText(System.Management.TextFormat.CimDtd20),
                out jobPath,
                out defined_sys);

            // If the Job is done asynchronously
            if (ret_val == ReturnCode.Started)
            {
                JobCompleted(jobPath);
            }
            else if (ret_val != ReturnCode.Completed)
            {
                var errMsg = string.Format(
                    "Failed to create VM {0} due to {1} (DefineVirtualSystem call)",
                    name, ReturnCode.ToString(ret_val));
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }

            logger.DebugFormat(CultureInfo.InvariantCulture, "Created VM {0}", name);

            // Is the defined_system real?
            var vm = new ComputerSystem(defined_sys);

            // Assertion
            if (vm.ElementName.CompareTo(name) != 0)
            {
                var errMsg = string.Format(
                    "New VM created with wrong name (is {0}, should be {1}, GUID {2})",
                    vm.ElementName,
                    name,
                    vm.Name);
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }

            return vm;
        }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:56,代码来源:WmiCallsV2.cs


示例17: AttachNicToPort

        private EthernetPortAllocationSettingData AttachNicToPort(ComputerSystem newVm, SyntheticEthernetPortSettingData newAdapter, String vSwitchName)
        {
            // Get the virtual switch
            VirtualEthernetSwitch vSwitch = GetExternalVirtSwitch(vSwitchName);
            //check the the recevied vSwitch is the same as vSwitchName.
            if (!vSwitchName.Equals("")  && !vSwitch.ElementName.Equals(vSwitchName))
            {
               var errMsg = string.Format("Internal error, coudl not find Virtual Switch with the name : " +vSwitchName);
               var ex = new WmiException(errMsg);
               logger.Error(errMsg, ex);
               throw ex;
            }

            // Create port for adapter
            var defaultEthernetPortSettings = EthernetPortAllocationSettingData.GetInstances(vSwitch.Scope, "InstanceID LIKE \"%Default\"");

            // assert
            if (defaultEthernetPortSettings.Count != 1)
            {
                var errMsg = string.Format("Internal error, coudl not find default EthernetPortAllocationSettingData instance");
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }

            var defaultEthernetPortSettingsObj = defaultEthernetPortSettings.OfType<EthernetPortAllocationSettingData>().First();
            var newEthernetPortSettings = new EthernetPortAllocationSettingData((ManagementBaseObject)defaultEthernetPortSettingsObj.LateBoundObject.Clone());
            newEthernetPortSettings.LateBoundObject["Parent"] = newAdapter.Path.Path;
            newEthernetPortSettings.LateBoundObject["HostResource"] = new string[] { vSwitch.Path.Path };

            // Insert NIC into vm
            string[] newResources = new string[] { newEthernetPortSettings.LateBoundObject.GetText(System.Management.TextFormat.CimDtd20) };
            ManagementPath[] newResourcePaths = AddVirtualResource(newResources, newVm);

            // assert
            if (newResourcePaths.Length != 1)
            {
                var errMsg = string.Format(
                    "Failed to properly insert a single NIC on VM {0} (GUID {1}): number of resource created {2}",
                    newVm.ElementName,
                    newVm.Name,
                    newResourcePaths.Length);
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }

            return new EthernetPortAllocationSettingData(newResourcePaths[0]);
        }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:49,代码来源:WmiCallsV2.cs


示例18: ModifySystemSetting

        private static void ModifySystemSetting(VirtualSystemManagementService vmMgmtSvc, string systemSettings)
        {
            // Resource settings are changed through the management service
            System.Management.ManagementPath jobPath;

            var ret_val = vmMgmtSvc.ModifySystemSettings(
                systemSettings,
                out jobPath);

            // If the Job is done asynchronously
            if (ret_val == ReturnCode.Started)
            {
                JobCompleted(jobPath);
            }
            else if (ret_val != ReturnCode.Completed)
            {
                var errMsg = string.Format(
                    "Failed to update system setting {0}",
                    ReturnCode.ToString(ret_val));
                var ex = new WmiException(errMsg);
                logger.Error(errMsg, ex);
                throw ex;
            }
        }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:24,代码来源:WmiCallsV2.cs


示例19: RemoveNetworkResource

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DB2.DB2Connection类代码示例发布时间:2022-05-26
下一篇:
C# Client.NetworkClient类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap