public static ConnectionOptions GetHostConnectionOptions(VMHost host) { //ConnectionOptions opt = new ConnectionOptions(); //opt.Password = host.Password; //opt.Username = host.UserName; return(host.HostConnectionOptions); }
public List <VMHost> GetHostListFromFile(string path) { StreamReader SR = File.OpenText(path); List <VMHost> hostList = new List <VMHost> (); string hostName = SR.ReadLine(); //AutoResetEvent signal = new AutoResetEvent(false); //int counter = 0; while (hostName != null) { if (hostName[0] != '#') { string hstName = hostName; VMHost host = new VMHost((string)hstName); hostList.Add(host); //ThreadPool.QueueUserWorkItem(delegate(object o) //{ // Interlocked.Increment(ref counter); // VMHost host = new VMHost((string)hstName); // lock (hostList) // { // hostList.Add(host); // } // if (Interlocked.Decrement(ref counter)==0) // { // signal.Set(); // } //}, hstName); } hostName = SR.ReadLine(); } //signal.WaitOne(); return(hostList); }
protected void OnHostListChanged(VMHost host, bool added) { if (HostListChanged != null) { HostListChanged(this, new VMHostListChangedEventArgs(host, added)); } OnPropertyChanged("HostList"); }
public RPCCallException(VMHost host, COMException ex) : base(ex.Message, ex.ErrorCode) { host.Status = VMHostStatus.ERROR; host.StatusString = ex.Message; if ((uint)ex.ErrorCode == 0x80070721) { throw new UnauthorizedAccessException(ex.Message, ex); } }
public static ObservableCollection <VM> GetHostVMCollection(VMHost host) { //Query all properties from Msvm_ComputerSystem class ObjectQuery queryObj = new ObjectQuery("SELECT * FROM Msvm_ComputerSystem"); ConnectionOptions connOpts = GetHostConnectionOptions(host); //Making connection to virtualization namespace //ManagementScope manScope = new ManagementScope(@"\\" + host.Name + @"\root\virtualization", connOpts); ManagementScope manScope = new ManagementScope(@"\\" + host.Name + @"\root\virtualization", connOpts); // connect and set up our search EnumerationOptions EnumOpts = new EnumerationOptions(); //Ensure to return complete collection EnumOpts.ReturnImmediately = false; //EnumOpts.Timeout = TimeSpan.FromMilliseconds(100); ManagementObjectSearcher vmSearcher = new ManagementObjectSearcher(manScope, queryObj, EnumOpts); ObservableCollection <VM> vmCollection = new ObservableCollection <VM> (); //ManagementOperationObserver watcher = new ManagementOperationObserver(); try { // get the collection of computer system objects ManagementObjectCollection ManObjCollection = vmSearcher.Get(); if (ManObjCollection != null) { foreach (ManagementObject vmobj in ManObjCollection) { // only copy details of the Virtual Machines //MSDN:A textual description of the object. This property is inherited from CIM_ManagedElement //and it is set to "Microsoft Virtual Computer System" if the instance represents a VM or "Microsoft Hosting Computer System" //if the instance represents the host system. if (vmobj["Caption"].ToString().Contains("Virtual Machine")) { // capture the machine name, status and type //MSDN:Caption - A short textual description (one-line string) of the object. This property is inherited //from CIM_ManagedElement and it is set to "Virtual Machine" if the instance represents a VM //or "Hosting Computer System" if the instance represents the host system. //VM vm = new VM(host, vmobj["Name"].ToString()); //ManagementObject[] OutPut = n; VM vm = new VM(host, vmobj); vmCollection.Add(vm); } } } //String strTargetVM = "*"; // loop through the machines } catch (COMException ex) { //MessageBox.Show(ex.Message, ex.ErrorCode.ToString()); throw new RPCCallException(host, ex); } return(vmCollection); }
private void CreateVMHost(object args) { VMHost host = new VMHost((args as object [])[0] as string); VMHostGroup group = (args as object[])[1] as VMHostGroup; if (host != null) { lock (group) { group.AddHost(host); } } }
public void RemoveHost(VMHost host) { HostList.Remove(host); if (this.DataObject is XElement) { XElement tree = this.DataObject as XElement; var CheckVMHostPresenceQuery = from el in tree.Elements() where el.Attribute("Name").Value == host.Name select el; foreach (XElement XcurHost in CheckVMHostPresenceQuery) { XcurHost.Remove(); } } OnPropertyChanged("HostList"); //OnPropertyChanged("Children"); }
public VM(VMHost hst, ManagementObject manObj) { host = hst; this.instance = manObj; this.Name = manObj["ElementName"].ToString(); //this.DnsName = Utility.GetFullyQualifiedDomainName(this); this.guid = manObj["Name"].ToString(); this.status = (UInt16)manObj["EnabledState"]; //this.TimeOfLastConfigurationChange = Utility.ConvertToDateTime(manObj["TimeOfLastConfigurationChange"].ToString()); this.TimeOfLastStateChange = Utility.ConvertToDateTime(manObj["TimeOfLastStateChange"].ToString()); this.description = manObj["Description"].ToString(); ManagementBaseObject summaryInfo = Utility.GetSummaryInformation(this, new uint[] { VMRequestedInformation.CreationTime, }); this.creationTime = Utility.ConvertToDateTime(summaryInfo["CreationTime"].ToString()); SnapshotTree = Utility.GetVMSnapshotTree(this); //Register to WMI event of Status changing stateModificationWatcher = new VMModificationEventWatcher(this, OnVMStateChange); settingsModificationWatcher = new VMSettingsModificationEventWatcher(this, OnVMSettingsChange); }
/// <summary> /// Returns parent group for VM Host /// </summary> /// <param name="vm">VMHost a parent is searching for</param> /// <param name="root">Root VM group</param> /// <returns>Parent VMHostGroup if it exists of null otherwise</returns> public static VMHostGroup FindParentFor(VMHost host, VMHostGroup root) { return(FindParentFor(host.Name, root)); //VMHostGroup parent = null; //if (root.HostList.Contains(host)) //{ // parent = root; //} //else //{ // foreach (VMHostGroup group in root.ChildGroups) // { // parent = FindParentFor(host, group); // if (parent != null) // { // //parent = group; // break; // } // } //} //return parent; }
public void AddHost(VMHost host) { hostList.Add(host); host.Group = this; OnHostListChanged(host, true); }
public VMHostListChangedEventArgs(VMHost host) : this(host, true) { }
public VMHostListChangedEventArgs(VMHost host, bool hostAdded) { this.involvedHost = host; this.isHostAdded = hostAdded; }