-
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.
Merge pull request #23 from csdhome/RunCloudAutomation
Added the ability to run cloud automation scripts by a sysprep command in the registry and added the ability to run them after a reboot if one is detected.
- Loading branch information
Showing
18 changed files
with
410 additions
and
25 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
50 changes: 50 additions & 0 deletions
50
src/Rackspace.Cloud.Server.Agent.Specs/CloudAutomationSubActionsSpec.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,50 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Microsoft.Win32; | ||
using NUnit.Framework; | ||
using Rackspace.Cloud.Server.Agent.Actions; | ||
using StructureMap; | ||
|
||
namespace Rackspace.Cloud.Server.Agent.Specs | ||
{ | ||
[TestFixture] | ||
public class CloudAutomationSubActionsSpec | ||
{ | ||
[SetUp] | ||
public void Setup() | ||
{ | ||
Utility.ConfigureStructureMap(); | ||
} | ||
|
||
[Test] | ||
public void should_detect_sysprep_key_and_remove_it_and_detect_it_is_gone() | ||
{ | ||
var cloudAutomationActions = ObjectFactory.GetInstance<ICloudAutomationSubActions>(); | ||
RegistryKey rk = Registry.LocalMachine.CreateSubKey(Constants.RackspaceRegKey); | ||
rk.SetValue(Constants.CloudAutomationSysPrepRegKey, "True"); | ||
|
||
Assert.IsTrue(cloudAutomationActions.IsSysPrepSignalPresent()); | ||
|
||
Assert.IsTrue(cloudAutomationActions.RemoveSysPrepSignal()); | ||
|
||
Assert.IsFalse(cloudAutomationActions.IsSysPrepSignalPresent()); | ||
} | ||
|
||
[Test] | ||
public void should_create_then_detect_kmsactivate_key_and_remove_it_and_detect_it_is_gone() | ||
{ | ||
var cloudAutomationActions = ObjectFactory.GetInstance<ICloudAutomationSubActions>(); | ||
|
||
Assert.IsTrue(cloudAutomationActions.WriteKMSActivateSignal()); | ||
|
||
Assert.IsTrue(cloudAutomationActions.IsKMSActivateSignalPresent()); | ||
|
||
Assert.IsTrue(cloudAutomationActions.RemoveKMSActivateSignal()); | ||
|
||
Assert.IsFalse(cloudAutomationActions.IsKMSActivateSignalPresent()); | ||
} | ||
|
||
|
||
} | ||
} |
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
110 changes: 110 additions & 0 deletions
110
src/Rackspace.Cloud.Server.Agent/Actions/CloudAutomationActions.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,110 @@ | ||
// Copyright 2011 OpenStack LLC. | ||
// All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. You may obtain | ||
// a copy of the License at | ||
// | ||
// http:https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
// License for the specific language governing permissions and limitations | ||
// under the License. | ||
|
||
using System; | ||
using Rackspace.Cloud.Server.Common.Restart; | ||
using Rackspace.Cloud.Server.Common.Logging; | ||
|
||
namespace Rackspace.Cloud.Server.Agent.Actions | ||
{ | ||
public interface ICloudAutomationActions | ||
{ | ||
void RunKMSActivateCloudAutomationScripts(); | ||
void RunPostRebootCloudAutomationScripts(); | ||
} | ||
|
||
public class CloudAutomationActions : ICloudAutomationActions | ||
{ | ||
private readonly ILogger _logger; | ||
private readonly ICloudAutomationSubActions _cloudAutomationSubActions; | ||
|
||
public CloudAutomationActions(ILogger logger, ICloudAutomationSubActions cloudAutomationSubActions) | ||
{ | ||
_logger = logger; | ||
_cloudAutomationSubActions = cloudAutomationSubActions; | ||
} | ||
|
||
#region ICloudAutomationActions Members | ||
|
||
public void RunPostRebootCloudAutomationScripts() | ||
{ | ||
try | ||
{ | ||
_logger.Log("Checking for KMSActivate cloud automation registry entry"); | ||
if (_cloudAutomationSubActions.IsKMSActivateSignalPresent()) | ||
{ | ||
_logger.Log("KMSActivate registry entry found, removing registry entry"); | ||
if (_cloudAutomationSubActions.RemoveKMSActivateSignal()) | ||
{ | ||
_logger.Log("Successfully removed KMSActivate registry entry, running cloud automation scripts"); | ||
_cloudAutomationSubActions.RunCloudAutomationScripts(); | ||
} | ||
else | ||
{ | ||
_logger.Log("Could not delete the KMSActivate registry entry for cloud automation, not running cloud automation."); | ||
} | ||
} | ||
else | ||
{ | ||
_logger.Log("KMSActivate cloud automation registry entry not detected."); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.Log(string.Format("Error running cloud automation: {0}", ex)); | ||
} | ||
} | ||
|
||
public void RunKMSActivateCloudAutomationScripts() | ||
{ | ||
try | ||
{ | ||
_logger.Log("Checking for SysPrep cloud automation registry entry"); | ||
if (_cloudAutomationSubActions.IsSysPrepSignalPresent()) | ||
{ | ||
_logger.Log("SysPrep registry entry found, removing registry entry"); | ||
if (_cloudAutomationSubActions.RemoveSysPrepSignal()) | ||
{ | ||
_logger.Log("Successfully removed SysPrep registry entry, checking to see if a reboot is pending"); | ||
if (RestartManager.RestartNeeded) | ||
{ | ||
_logger.Log("Reboot is pending, writing KMSActivate registry entry for post reboot cloud automation script execution"); | ||
_cloudAutomationSubActions.WriteKMSActivateSignal(); | ||
} | ||
else | ||
{ | ||
_logger.Log("Reboot is not pending, running cloud automation scripts"); | ||
_cloudAutomationSubActions.RunCloudAutomationScripts(); | ||
} | ||
} | ||
else | ||
{ | ||
_logger.Log("Could not remove the SysPrep registry key, not writing the KMSActivate registry key for cloud automation."); | ||
} | ||
} | ||
else | ||
{ | ||
_logger.Log("SysPrep cloud automation registry entry not detected"); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.Log(string.Format("An error occurred while writing the KMSActivate registry key for cloud automation: {0}", ex)); | ||
} | ||
} | ||
|
||
#endregion | ||
} | ||
} |
Oops, something went wrong.