public VMControllerByAPI(VMWareInfo.VMCoreTypes type) { try { _api = new VixLibClass(); } catch (System.Runtime.InteropServices.COMException e) { throw new VMXServiceException( "Unable to find Vix library!\n" + e.ToString()); } int core = GetVIXServiceProviderByType(type); IJob job = _api.Connect( Constants.VIX_API_VERSION, core, null, 0, null, null, 0, null, null); _host = GetResult <IHost>(WaitForResults(job)); if (_host == null) { throw new VMXServiceException("Connecting to VMWare provider was failed."); } CloseVixObject(job); }
public Service(string vmx_file, VMWareInfo.VMCoreTypes vm_target) : base() { SetServiceBehavior(); _vmx_file = vmx_file; try { if (IsUsingApi) { _control = new VMControllerByAPI(vm_target); } else { _control = new VMControllerByVMRun(vm_target); } } catch (VMXServiceException) { _invalid_state = true; WriteLog("Failed To Initialize VMWare controller!", EventLogEntryType.Error); return; } if (!File.Exists(_vmx_file)) { WriteLog("Specified vmx file '{0}' does not exists!", EventLogEntryType.FailureAudit, _vmx_file); _invalid_state = true; return; } _timer = new Timer(TimeSpan.FromSeconds(20).TotalMilliseconds); _timer.Elapsed += new ElapsedEventHandler(OnTimerEvent); _timer.Enabled = false; }
public VMControllerByVMRun(VMWareInfo.VMCoreTypes type) { VMWareInfo vm_info = new VMWareInfo(); _vmware_core = GetTargetNameByType(type); _vmrun_path = vm_info.PathToVMRun; }
protected int GetVIXServiceProviderByType(VMWareInfo.VMCoreTypes type) { if (map_type_to_VIX_SERVICEPROVIDER.ContainsKey(type)) { return(map_type_to_VIX_SERVICEPROVIDER[type]); } else { return(map_type_to_VIX_SERVICEPROVIDER[VMWareInfo.VMCoreTypes.UNKNOWN]); } }
public string GetShortNameByType(VMWareInfo.VMCoreTypes type) { if (map_type_to_short_name.ContainsKey(type)) { return(map_type_to_short_name[type]); } else { return(map_type_to_short_name[VMWareInfo.VMCoreTypes.UNKNOWN]); } }
protected string GetTargetNameByType(VMWareInfo.VMCoreTypes type) { if (map_type_to_target.ContainsKey(type)) { return(map_type_to_target[type]); } else { return(map_type_to_target[VMWareInfo.VMCoreTypes.UNKNOWN]); } }