当前位置: 首页>>代码示例>>C#>>正文


C# V2.ComputerSystem类代码示例

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


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

示例1: AddUserData

        /// <summary>
        /// Returns ComputerSystem lacking any NICs and VOLUMEs
        /// </summary>
        public ComputerSystem AddUserData(ComputerSystem vm, string userData)
        {
            // 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"] = userData;
            kvpItem.LateBoundObject["Source"] = 0;
            logger.Debug("VM " + vm.Name + " gets userdata " + userData);

            // Update the resource settings for the VM.
            System.Management.ManagementBaseObject kvpMgmtObj = kvpItem.LateBoundObject;
            System.Management.ManagementPath jobPath;
            String kvpStr = kvpMgmtObj.GetText(System.Management.TextFormat.CimDtd20);
            uint ret_val = vmMgmtSvc.AddKvpItems(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;
            }

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

示例2: AttachIso

 /// <summary>
 /// Create Msvm_StorageAllocationSettingData corresponding to the ISO image, and 
 /// associate this with the VM's DVD drive.
 /// </summary>
 private void AttachIso(ComputerSystem vm, string isoPath)
 {
     // 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 driveWmiObj = GetDvdDriveSettings(vmSettings);
     InsertDiskImage(vm, isoPath, ISO_DISK, driveWmiObj.Path);
 }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:11,代码来源:WmiCallsV2.cs

示例3: AddVirtualResource

        private ManagementPath[] AddVirtualResource(string[] resourceSettings, ComputerSystem vm )
        {
            var virtSysMgmtSvc = GetVirtualisationSystemManagementService();

            ManagementPath jobPath;
            ManagementPath[] resourcePaths;
            var ret_val = virtSysMgmtSvc.AddResourceSettings(
                vm.Path,
                resourceSettings,
                out jobPath,
                out resourcePaths);

            // 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 add resources to 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;
            }

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

示例4: AddStorageResource

 /// <summary>
 /// Adds storage images to coputer system (disk image, iso image).
 /// </summary>
 /// <param name="storageSettings">Msvm_StorageAllocationSettings with HostResource configured with image
 /// file and Parent set to a controller associated with the ComputerSystem</param>
 /// <param name="vm">VM to which the disk image will be attached.</param>
 // Add new
 private ManagementPath[] AddStorageResource(string[] storageSettings, ComputerSystem vm)
 {
     return AddVirtualResource(storageSettings, vm);
 }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:11,代码来源:WmiCallsV2.cs

示例5: AddDiskDriveToIdeController

        /// </summary>
        /// <param name="vm"></param>
        /// <param name="cntrllerAddr"></param>
        /// <param name="driveResourceType">IDE_HARDDISK_DRIVE or IDE_ISO_DRIVE</param>
        public ManagementPath AddDiskDriveToIdeController(ComputerSystem vm, string vhdfile, string cntrllerAddr, string driveResourceType)
        {
            logger.DebugFormat("Creating DISK for VM {0} (GUID {1}) by attaching {2}",
                        vm.ElementName,
                        vm.Name,
                        vhdfile);

            // Determine disk type for drive and assert drive type valid
            string diskResourceSubType = null;
            switch(driveResourceType) {
                case HARDDISK_DRIVE:
                    diskResourceSubType = HARDDISK_DISK;
                    break;
                case ISO_DRIVE:
                    diskResourceSubType = ISO_DISK;
                    break;
                default:
                    var errMsg = string.Format(
                        "Unrecognised disk drive type {0} for VM {1} (GUID {2})",
                        string.IsNullOrEmpty(driveResourceType) ? "NULL": driveResourceType,
                        vm.ElementName,
                        vm.Name);
                    var ex = new WmiException(errMsg);
                    logger.Error(errMsg, ex);
                    throw ex;
            }

            ManagementPath newDrivePath = AttachNewDrive(vm, cntrllerAddr, driveResourceType);

            // If there's not disk to insert, we are done.
            if (String.IsNullOrEmpty(vhdfile))
            {
                logger.DebugFormat("No disk to be added to drive, disk drive {0} is complete", newDrivePath.Path);
            }
            else
            {
                InsertDiskImage(vm, vhdfile, diskResourceSubType, newDrivePath);
            }
            return newDrivePath;
        }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:44,代码来源:WmiCallsV2.cs

示例6: GetDiskDriveOnScsiController

 private ManagementPath GetDiskDriveOnScsiController(ComputerSystem vm, string addrOnController)
 {
     VirtualSystemSettingData vmSettings = GetVmSettings(vm);
     var wmiObjCollection = GetResourceAllocationSettings(vmSettings);
     foreach (ResourceAllocationSettingData wmiObj in wmiObjCollection)
     {
         if (wmiObj.ResourceSubType == HARDDISK_DRIVE)
         {
             ResourceAllocationSettingData parent = new ResourceAllocationSettingData(new ManagementObject(wmiObj.Parent));
             if (parent.ResourceSubType == SCSI_CONTROLLER && wmiObj.AddressOnParent == addrOnController)
             {
                 return wmiObj.Path;
             }
         }
     }
     return null;
 }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:17,代码来源: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: 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

示例9: 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

示例10: GetEthernetPortSettings

        public SyntheticEthernetPortSettingData[] GetEthernetPortSettings(ComputerSystem vm)
        {
            // An ASSOCIATOR object provides the cross reference from the ComputerSettings and the
            // SyntheticEthernetPortSettingData, via the VirtualSystemSettingData.
            // However, 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);
            //
            VirtualSystemSettingData vmSettings = GetVmSettings(vm);

            var wmiObjQuery = new RelatedObjectQuery(vmSettings.Path.Path, SyntheticEthernetPortSettingData.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 SyntheticEthernetPortSettingData.SyntheticEthernetPortSettingDataCollection(wmiObjectSearch.Get());

            List<SyntheticEthernetPortSettingData> results = new List<SyntheticEthernetPortSettingData>(wmiObjCollection.Count);
            foreach (SyntheticEthernetPortSettingData item in wmiObjCollection)
            {
                results.Add(item);
            }

            return results.ToArray();
        }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:26,代码来源:WmiCallsV2.cs

示例11: GetStorageSettings

        public StorageAllocationSettingData[] GetStorageSettings(ComputerSystem vm)
        {
            // ComputerSystem -> VirtualSystemSettingData -> EthernetPortAllocationSettingData
            VirtualSystemSettingData vmSettings = GetVmSettings(vm);

            var wmiObjQuery = new RelatedObjectQuery(vmSettings.Path.Path, StorageAllocationSettingData.CreatedClassName);

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

            var result = new List<StorageAllocationSettingData>(wmiObjCollection.Count);
            foreach (StorageAllocationSettingData item in wmiObjCollection)
            {
                result.Add(item);
            }
            return result.ToArray();
        }
开发者ID:KadnikovVN,项目名称:cloudstack,代码行数:19,代码来源:WmiCallsV2.cs

示例12: ShutdownVm

 public void ShutdownVm(ComputerSystem vm)
 {
     ShutdownComponent sc = GetShutdownComponent(vm);
     if (sc != null)
     {
         var ret_val = sc.InitiateShutdown(true, "need to shutdown");
         if (ret_val != ReturnCode.Completed)
         {
             logger.Info("Shutting down of system failed, may be shutdown integration services are missing");
         }
         else
         {
             // shutdown job is not returned so checking for shutdown completion by checking the current state of system.
             // poll every one second and timeout after 10 minutes
             for (int period = 0 ; period < 600 && (GetComputerSystem(vm.ElementName).EnabledState != EnabledState.Disabled); period++)
             {
                 System.Threading.Thread.Sleep(1000);
             }
         }
     }
     else
     {
         logger.Info("Shutting down of system failed; may be shutdown integration services are missing");
     }
 }
开发者ID:rafaelthedevops,项目名称:cloudstack,代码行数:25,代码来源:WmiCallsV2.cs

示例13: GetShutdownComponent

        public ShutdownComponent GetShutdownComponent(ComputerSystem vm)
        {
            var wmiQuery = String.Format("SystemName=\"{0}\"", vm.Name);
            ShutdownComponent.ShutdownComponentCollection vmCollection = ShutdownComponent.GetInstances(wmiQuery);

            // Return the first one
            foreach (ShutdownComponent sc in vmCollection)
            {
                return sc;
            }
            return null;
        }
开发者ID:rafaelthedevops,项目名称:cloudstack,代码行数:12,代码来源:WmiCallsV2.cs

示例14: TestStartCommand

        public void TestStartCommand()
        {
            ComputerSystem system = new ComputerSystem();
            wmiCallsV2.DeployVirtualMachine(Arg.Any<Object>(), Arg.Any<string>()).Returns(system);

            // Arrange
            HypervResourceController rsrcServer = new HypervResourceController();
            HypervResourceController.wmiCallsV2 = wmiCallsV2;
            String sample = getSampleStartCommand();


            dynamic jsonStartCmd = JsonConvert.DeserializeObject(sample);

            // Act
            dynamic startAns = rsrcServer.StartCommand(jsonStartCmd);

            // Assert
            Assert.NotNull(startAns[0][CloudStackTypes.StartAnswer]);
            Assert.True((bool)startAns[0][CloudStackTypes.StartAnswer].result, "StartCommand did not succeed " + startAns[0][CloudStackTypes.StartAnswer].details);

            Assert.Null((string)startAns[0][CloudStackTypes.StartAnswer].details);            
        }
开发者ID:RSI-RKlein,项目名称:cloudstack,代码行数:22,代码来源:HypervResourceController1Test.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


注:本文中的CloudStack.Plugin.WmiWrappers.ROOT.VIRTUALIZATION.V2.ComputerSystem类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。