-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Xen Tools Installer logic for custom packages.
- Loading branch information
Showing
17 changed files
with
269 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/Rackspace.Cloud.Server.Agent/Actions/XenToolsUpdateActions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Rackspace.Cloud.Server.Agent.Configuration; | ||
using Rackspace.Cloud.Server.Agent.Interfaces; | ||
using Rackspace.Cloud.Server.Agent.Utilities; | ||
using Rackspace.Cloud.Server.Common.Logging; | ||
|
||
namespace Rackspace.Cloud.Server.Agent.Actions | ||
{ | ||
public interface IXenToolsUpdateActions | ||
{ | ||
void ProcessXenToolsPostUpgradeActions(); | ||
} | ||
|
||
public class XenToolsUpdateActions : IXenToolsUpdateActions | ||
{ | ||
private readonly ILogger _logger; | ||
private readonly IXenToolsUpdateSubActions _xenToolsUpdateSubActions; | ||
private readonly ICommandFactory _factory; | ||
|
||
public XenToolsUpdateActions(ILogger logger, IXenToolsUpdateSubActions xenToolsUpdateSubActions, ICommandFactory commandFactory) | ||
{ | ||
_logger = logger; | ||
_xenToolsUpdateSubActions = xenToolsUpdateSubActions; | ||
_factory = commandFactory; | ||
} | ||
|
||
|
||
public void ProcessXenToolsPostUpgradeActions() | ||
{ | ||
if (_xenToolsUpdateSubActions.IsXenToolsUpdateSignalPresent()) | ||
{ | ||
_logger.Log("Xen Tools update signal was detected"); | ||
if (XenStoreWmi.IsWmiEnabled()) | ||
{ | ||
_logger.Log("Xen Store WMI Interface successfully detected, running resetnetwork"); | ||
if (RunResetNetworkCommand()) | ||
{ | ||
_logger.Log("Reset Netowrk successfully executed"); | ||
if (_xenToolsUpdateSubActions.RemoveXenToolsUpdateSignal()) | ||
{ | ||
_logger.Log("Xen Tools update signal successfully removed"); | ||
} | ||
else | ||
{ | ||
_logger.Log("Error removing Xen Tools update signal, please manually remove before reboot.."); | ||
_logger.Log(Constants.RackspaceRegKey); | ||
_logger.Log(Constants.XenToolsUpdateSignalKey); | ||
} | ||
} | ||
else | ||
{ | ||
_logger.Log("Error running reset-network for post Xen Tools Upgrade process, will retry at next service startup"); | ||
} | ||
} | ||
else | ||
{ | ||
_logger.Log("WMI is not active yet, not processing Xen Tools Post Upgrade Command"); | ||
} | ||
} | ||
else | ||
{ | ||
_logger.Log("Xen Tools update signal is not present"); | ||
} | ||
} | ||
|
||
public bool RunResetNetworkCommand() | ||
{ | ||
var success = false; | ||
|
||
try | ||
{ | ||
var executableCommand = _factory.CreateCommand("resetnetwork"); | ||
var executableResult = executableCommand.Execute("nohostname"); | ||
_logger.Log(executableResult.Output.Value()); | ||
success = true; | ||
} | ||
catch (InvalidCommandException exception) | ||
{ | ||
_logger.Log(exception.Message); | ||
} | ||
catch (UnsuccessfulCommandExecutionException exception) | ||
{ | ||
var result = (ExecutableResult)exception.Data["result"]; | ||
var output = ""; | ||
var error = ""; | ||
if (result.Output != null && !string.IsNullOrEmpty(result.Output.Value())) | ||
output = ", Output:" + result.Output.Value(); | ||
if (result.Error != null && !string.IsNullOrEmpty(result.Error.Value())) | ||
error = ", Error:" + result.Error.Value(); | ||
|
||
_logger.Log(string.Format("{0}{1}{2}", exception.Message, output, error)); | ||
|
||
} | ||
|
||
return success; | ||
} | ||
|
||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
src/Rackspace.Cloud.Server.Agent/Actions/XenToolsUpdateSubActions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Microsoft.Win32; | ||
using Rackspace.Cloud.Server.Common.Logging; | ||
|
||
namespace Rackspace.Cloud.Server.Agent.Actions | ||
{ | ||
public interface IXenToolsUpdateSubActions | ||
{ | ||
bool IsXenToolsUpdateSignalPresent(); | ||
bool RemoveXenToolsUpdateSignal(); | ||
bool WriteXenToolsUpdateSignal(); | ||
} | ||
|
||
public class XenToolsUpdateSubActions : IXenToolsUpdateSubActions | ||
{ | ||
private readonly ILogger _logger; | ||
|
||
public XenToolsUpdateSubActions(ILogger logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public bool IsXenToolsUpdateSignalPresent() | ||
{ | ||
using (var rk = Registry.LocalMachine.OpenSubKey(Constants.RackspaceRegKey)) | ||
{ | ||
if (rk != null) | ||
{ | ||
var signal = rk.GetValue(Constants.XenToolsUpdateSignalKey); | ||
|
||
if (signal != null) | ||
{ | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public bool RemoveXenToolsUpdateSignal() | ||
{ | ||
try | ||
{ | ||
using (var rk = Registry.LocalMachine.OpenSubKey(Constants.RackspaceRegKey, true)) | ||
{ | ||
if (rk != null) | ||
{ | ||
rk.DeleteValue(Constants.XenToolsUpdateSignalKey); | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.Log(ex.ToString()); | ||
return false; | ||
} | ||
} | ||
|
||
public bool WriteXenToolsUpdateSignal() | ||
{ | ||
try | ||
{ | ||
using (var rsrk = Registry.LocalMachine.CreateSubKey(Constants.RackspaceRegKey)) | ||
{ | ||
if (rsrk != null) | ||
{ | ||
rsrk.SetValue(Constants.XenToolsUpdateSignalKey, "True"); | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.Log(ex.ToString()); | ||
return false; | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.