private ConverterComputerSpec BuildLiveSourceSpec() { ConverterComputerSpec liveSourceSpec = new ConverterComputerSpec(); liveSourceSpec.location = Common.BuildLiveSourceLocation(_sourceName, _sourceUsername, _sourcePassword, _sourceOsType, _sourceThumbprint); return(liveSourceSpec); }
public InstallAgentResult InstallAgent(String sourceName, int sourceAgentPort, String sourceThumbprint, String sourceUsername, String sourcePassword, bool sourcePostponeReboot) { // Check for Agent existence. ConverterComputerSpecLiveComputerLocation liveComputerLocation = Common.BuildLiveSourceLocation(sourceName, sourceUsername, sourcePassword, "windowsOs", sourceThumbprint); ConverterComputerSpec computerSpec = new ConverterComputerSpec(); computerSpec.location = liveComputerLocation; bool availabilityValidated = false; bool retry; do { retry = false; try { _converterService.ConverterValidateAgentAvailability(_converterServerContent.queryManager, computerSpec); availabilityValidated = true; } catch (SoapException e) { String remoteThumbprint = ExtractCertificateThumbprintFromFaultMessage(e.Message); if (remoteThumbprint != null) { if (liveComputerLocation.sslThumbprint == null || liveComputerLocation.sslThumbprint.Length == 0) { if (ReadYesNo("\nSource machine certificate validation failed.\n" + "Source machine: " + liveComputerLocation.hostname + "\n" + "Certificate thumprint: " + remoteThumbprint + "\n" + "Proceed with connecting to the source machine?", false)) { liveComputerLocation.sslThumbprint = remoteThumbprint; retry = true; } } if (!retry) { Console.WriteLine("Caught SoapException - \n" + " Actor : " + e.Actor + "\n" + " Code : " + e.Code + "\n" + " Detail XML : " + e.Detail.OuterXml); return(new InstallAgentResult(false, null)); } } else { Console.WriteLine("Agent isn't installed on source machine {0} '" + e.Message + "'. Try to install agent...", sourceName); } } catch (Exception e) { Console.WriteLine("Agent isn't installed on source machine {0} '" + e.Message + "'. Try to install agent...", sourceName); } } while (retry); if (availabilityValidated) { return(new InstallAgentResult(true, liveComputerLocation.sslThumbprint)); } try { ConverterAgentManagerAgentDeploymentResult result = _converterService.ConverterInstallAgent(_converterServerContent.agentManager, sourceName, sourceAgentPort, true, sourceUsername, sourcePassword, sourcePostponeReboot, true); if (result.status == ConverterAgentManagerDeploymentStatus.completed) { return(new InstallAgentResult(true, result.sslThumbprint)); } else if (result.status == ConverterAgentManagerDeploymentStatus.rebootRequired && sourcePostponeReboot == true) { Console.WriteLine("A reboot of the physical source {0} is required for the agent installation to succeed. Please try the P2V after rebooting the source", sourceName); return(new InstallAgentResult(false, result.sslThumbprint)); } else if (result.status == ConverterAgentManagerDeploymentStatus.rebootRequired && sourcePostponeReboot == false) { _converterService.ConverterRebootMachine(_converterServerContent.agentManager, sourceName, sourceUsername, sourcePassword); Console.WriteLine("A reboot of the physical source {0} has been initiated.", sourceName); } // Update source computer spec thumbprint with the one returned after agent // deployment, if any liveComputerLocation.sslThumbprint = result.sslThumbprint; // If a reboot of the Physical source has been initiated. for (int attempt = 0; attempt < _totalAttempts; attempt++) { try { _converterService.ConverterValidateAgentAvailability(_converterServerContent.queryManager, computerSpec); availabilityValidated = true; break; } catch (Exception e) { Console.WriteLine("Caught Exception : " + e.Message + " Trying again..."); System.Threading.Thread.Sleep(_waitSeconds * 1000); } } return(new InstallAgentResult(availabilityValidated, result.sslThumbprint)); } catch (SoapException se) { Console.WriteLine("Caught SoapException - \n" + " Actor : " + se.Actor + "\n" + " Code : " + se.Code + "\n" + " Detail XML : " + se.Detail.OuterXml); } catch (Exception e) { Console.WriteLine("Caught Exception : \n" + " Name : " + e.GetType().Name + "\n" + " Message : " + e.Message + "\n" + " Trace : " + e.StackTrace); } return(new InstallAgentResult(false, null)); }