public bool InstallUninstall( InstallerConfig installerConfig, DriverTaskInstanceOptions options) { try { _results.Clear(); _vmPowerDriver.PowerOnDependencies(); _vmPowerDriver.ThrowOnFailure(); _vmPowerDriver.ConnectToHost(); CopyMethod copyMethod = _vmConfig.CopyMethod; if (copyMethod == CopyMethod.undefined) copyMethod = installerConfig.CopyMethod; _vmPowerDriver.MapVirtualMachine(copyMethod); if (!_snapshotRestored) { _vmPowerDriver.PrepareSnapshot(); _snapshotRestored = true; } _vmPowerDriver.LoginToGuest(); CopyInstaller(installerConfig); Instance installInstance = new Instance( _logpath, _simulationOnly, _config, _vmPowerDriver.Vm, _vmPowerDriver.VmConfig, installerConfig, _vmPowerDriver.SnapshotConfig); Instance.InstanceOptions instanceOptions = new Instance.InstanceOptions(); instanceOptions.Install = options.Install; instanceOptions.Uninstall = options.Uninstall; Result remoteInstallResult = installInstance.InstallUninstall(instanceOptions); foreach (VirtualMachinePowerResult powerResult in _vmPowerDriver.PowerResults) { remoteInstallResult.Add(powerResult); } _results.Add(remoteInstallResult); if (remoteInstallResult.RebootRequired) { if (installerConfig.RebootIfRequired) { ConsoleOutput.WriteLine("Shutting down '{0}:{1}'", _vmPowerDriver.VmConfig.Name, _vmPowerDriver.SnapshotConfig.Name); _vmPowerDriver.ShutdownGuest(); ConsoleOutput.WriteLine("Powering on '{0}:{1}'", _vmPowerDriver.VmConfig.Name, _vmPowerDriver.SnapshotConfig.Name); _vmPowerDriver.PowerOn(); } else if (options.PowerOff) { _vmPowerDriver.PowerOff(); } else { ConsoleOutput.WriteLine("Skipping reboot of '{0}:{1}'", _vmPowerDriver.VmConfig.Name, _vmPowerDriver.SnapshotConfig.Name); } } else if (options.PowerOff) { _vmPowerDriver.PowerOff(); } return remoteInstallResult.Success; } catch (Exception ex) { ConsoleOutput.WriteLine(ex); Result result = new Result(installerConfig.Name, installerConfig.SvnRevision); result.LastError = ex.Message; result.SuccessfulInstall = result.SuccessfulUnInstall = InstallResult.False; _results.Add(result); return false; } finally { _vmPowerDriver.CloseVirtualMachine(); _vmPowerDriver.DisconnectFromHost(); _vmPowerDriver.PowerOffDependencies(); } }
public bool InstallUninstall( InstallerConfig installerConfig, DriverTaskInstanceOptions options) { try { _results.Clear(); _vmPowerDriver.PowerOnDependencies(); _vmPowerDriver.ThrowOnFailure(); _vmPowerDriver.ConnectToHost(); CopyMethod copyMethod = _vmConfig.CopyMethod; if (copyMethod == CopyMethod.undefined) { copyMethod = installerConfig.CopyMethod; } _vmPowerDriver.MapVirtualMachine(copyMethod); if (!_snapshotRestored) { _vmPowerDriver.PrepareSnapshot(); _snapshotRestored = true; } _vmPowerDriver.LoginToGuest(); CopyInstaller(installerConfig); Instance installInstance = new Instance( _logpath, _simulationOnly, _config, _vmPowerDriver.Vm, _vmPowerDriver.VmConfig, installerConfig, _vmPowerDriver.SnapshotConfig); Instance.InstanceOptions instanceOptions = new Instance.InstanceOptions(); instanceOptions.Install = options.Install; instanceOptions.Uninstall = options.Uninstall; Result remoteInstallResult = installInstance.InstallUninstall(instanceOptions); foreach (VirtualMachinePowerResult powerResult in _vmPowerDriver.PowerResults) { remoteInstallResult.Add(powerResult); } _results.Add(remoteInstallResult); if (remoteInstallResult.RebootRequired) { if (installerConfig.RebootIfRequired) { ConsoleOutput.WriteLine("Shutting down '{0}:{1}'", _vmPowerDriver.VmConfig.Name, _vmPowerDriver.SnapshotConfig.Name); _vmPowerDriver.ShutdownGuest(); ConsoleOutput.WriteLine("Powering on '{0}:{1}'", _vmPowerDriver.VmConfig.Name, _vmPowerDriver.SnapshotConfig.Name); _vmPowerDriver.PowerOn(); } else if (options.PowerOff) { _vmPowerDriver.PowerOff(); } else { ConsoleOutput.WriteLine("Skipping reboot of '{0}:{1}'", _vmPowerDriver.VmConfig.Name, _vmPowerDriver.SnapshotConfig.Name); } } else if (options.PowerOff) { _vmPowerDriver.PowerOff(); } return(remoteInstallResult.Success); } catch (Exception ex) { ConsoleOutput.WriteLine(ex); Result result = new Result(installerConfig.Name, installerConfig.SvnRevision); result.LastError = ex.Message; result.SuccessfulInstall = result.SuccessfulUnInstall = InstallResult.False; _results.Add(result); return(false); } finally { _vmPowerDriver.CloseVirtualMachine(); _vmPowerDriver.DisconnectFromHost(); _vmPowerDriver.PowerOffDependencies(); } }