public Uri CurrentSourceUri() { HostUriBuilder helperHostUriBuilder = this._Context.CredentialHelper.ReverseHelperHostUriBuilder; HostUriBuilder hostUriBuilder = new HostUriBuilder(helperHostUriBuilder.Uri); CUtils.CombinUsernameAndDomain(helperHostUriBuilder.Credentials.UserName, helperHostUriBuilder.Credentials.Domain); string password = helperHostUriBuilder.Credentials.Password; if (this._Context.JobInfoWrapper.IsSourceHostCluster) { this._Logger.Information("Finding Owning node for clustered Vm."); ClusteredVirtualMachinesInfo[] clusteredVirtualMachines = this._Context.ServiceResolver.Resolve <IClusterProvider>().GetCluster(helperHostUriBuilder.Uri).GetClusteredVirtualMachines(); ClusteredVirtualMachinesInfo virtualMachinesInfo = ((IEnumerable <ClusteredVirtualMachinesInfo>)clusteredVirtualMachines).Where <ClusteredVirtualMachinesInfo>((Func <ClusteredVirtualMachinesInfo, bool>)(n => ((IEnumerable <VirtualMachine>)n.VirtualMachine).Any <VirtualMachine>((Func <VirtualMachine, bool>)(v => string.Compare(v.Id, this._Context.JobInfoWrapper.SourceVmInfo.Id.ToString("D"), true) == 0)))).FirstOrDefault <ClusteredVirtualMachinesInfo>(); if (virtualMachinesInfo == null) { this._Logger.FormatError("Couldn't find the owning node of {0}", (object)this._Context.JobInfoWrapper.SourceVmInfo.DisplayName); this._Logger.Verbose("The considered nodes were :"); foreach (ClusteredVirtualMachinesInfo data in clusteredVirtualMachines) { this._Logger.Verbose(DataContractUtility.ToXmlString <ClusteredVirtualMachinesInfo>(data)); } throw new OculiServiceException(0, "Couldn't find the owning node for the Vm resource " + this._Context.JobInfoWrapper.SourceVmInfo.DisplayName); } hostUriBuilder.NetworkId = virtualMachinesInfo.OwningNode; } return(hostUriBuilder.Uri); }
public IHvService TargetHost_Hv2() { string address = this.CurrentTargetHostName(); string username = ""; string password = ""; string str = "localhost"; if (address != str) { HostUriBuilder helperHostUriBuilder = this._Context.CredentialHelper.TargetHelperHostUriBuilder; username = CUtils.CombinUsernameAndDomain(helperHostUriBuilder.Credentials.UserName, helperHostUriBuilder.Credentials.Domain); password = helperHostUriBuilder.Credentials.Password; } IHvServiceLogger serviceLogger = this._ServiceLogger; IHvServiceCallContext serviceCallContext = this._ServiceCallContext; IHvService service2012ByWmi = HvServiceFactory.CreateHvService2012ByWmi(address, serviceLogger, serviceCallContext); try { service2012ByWmi.Logon(username, password); return(service2012ByWmi); } catch (Exception ex) { this._Logger.Information(ex, "Exception thrown during login: "); service2012ByWmi.Dispose(); throw; } }
public HyperVService(string address, NetworkCredential cred, ILogger logger, IHvServiceCallContext callContext) { this._Address = address; this._Cred = cred; this._Logger = logger; this._CallContext = callContext; this._Scope = WMIUtils.ConnectToServer(this._Address, CUtils.CombinUsernameAndDomain(this._Cred.UserName, this._Cred.Domain), this._Cred.Password, "\\root\\virtualization\\v2"); this._VirtSysMgmt = VirtualSystemManagementService.GetVirtualSystemManagmentService(this._Scope); this._SystemName = this._VirtSysMgmt.SystemName; }
public IHvService SourceHost() { HostUriBuilder helperHostUriBuilder = this._Context.CredentialHelper.ReverseHelperHostUriBuilder; string username = CUtils.CombinUsernameAndDomain(helperHostUriBuilder.Credentials.UserName, helperHostUriBuilder.Credentials.Domain); string password = helperHostUriBuilder.Credentials.Password; IHvService hvServiceByWmi = HvServiceFactory.CreateHvServiceByWmi(this.CurrentSourceHostName(), this._ServiceLogger, this._ServiceCallContext); try { hvServiceByWmi.Logon(username, password); return(hvServiceByWmi); } catch (Exception ex) { this._Logger.Information(ex, "Exception thrown during login: "); hvServiceByWmi.Dispose(); throw; } }
public static ManagementScope ConnectToServerDefaultPath(string server, NetworkCredential credentials) { string userName = CUtils.CombinUsernameAndDomain(credentials.UserName, credentials.Domain); return(WMIUtils.ConnectToServerDefaultPath(server, userName, credentials.Password)); }