-
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 #12 from kashivreddy/master
Added sethostname command/feature
- Loading branch information
Showing
18 changed files
with
183 additions
and
46 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
11 changes: 2 additions & 9 deletions
11
src/Rackspace.Cloud.Server.Agent.DiffieHellman/Properties/AssemblyInfo.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 |
---|---|---|
@@ -1,14 +1,7 @@ | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
|
||
[assembly: AssemblyTitle("DiffieHellmanManaged")] | ||
[assembly: AssemblyDescription("C#.NET Agent for Windows Virtual Machines")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("Rackspace Cloud")] | ||
[assembly: AssemblyProduct("Rackspace Cloud Server Agent")] | ||
[assembly: AssemblyCopyright("Copyright (c) 2009 2010, Rackspace Cloud. All Rights Reserved")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
[assembly: ComVisible(false)] | ||
[assembly: AssemblyVersion("1.2.4.0")] | ||
[assembly: AssemblyFileVersion("1.2.4.0")] | ||
[assembly: AssemblyCopyright("Copyright (c) 2009 2010 2011, Rackspace Cloud. All Rights Reserved")] | ||
[assembly: AssemblyVersion("1.2.5.0")] |
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
11 changes: 2 additions & 9 deletions
11
src/Rackspace.Cloud.Server.Agent.Specs/Properties/AssemblyInfo.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 |
---|---|---|
@@ -1,14 +1,7 @@ | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
|
||
[assembly: AssemblyTitle("Rackspace.Cloud.Server.ConfigurationAgent.Specs")] | ||
[assembly: AssemblyDescription("C#.NET Agent for Windows Virtual Machines")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("Rackspace Cloud")] | ||
[assembly: AssemblyProduct("Rackspace Cloud Server Agent")] | ||
[assembly: AssemblyCopyright("Copyright (c) 2009 2010, Rackspace Cloud. All Rights Reserved")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
[assembly: ComVisible(false)] | ||
[assembly: AssemblyVersion("1.2.4.0")] | ||
[assembly: AssemblyFileVersion("1.2.4.0")] | ||
[assembly: AssemblyCopyright("Copyright (c) 2009 2010 2011, Rackspace Cloud. All Rights Reserved")] | ||
[assembly: AssemblyVersion("1.2.5.0")] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using NUnit.Framework; | ||
using Rackspace.Cloud.Server.Agent.Actions; | ||
using Rackspace.Cloud.Server.Agent.Commands; | ||
using Rackspace.Cloud.Server.Common.Logging; | ||
using Rhino.Mocks; | ||
using System.Linq; | ||
|
||
namespace Rackspace.Cloud.Server.Agent.Specs | ||
{ | ||
[TestFixture] | ||
public class SetHostnameSpec | ||
{ | ||
private ISetHostnameAction _action; | ||
private ILogger _logger; | ||
private SetHostname _command; | ||
|
||
[SetUp] | ||
public void Setup() { | ||
_action = MockRepository.GenerateMock<ISetHostnameAction>(); | ||
_logger = MockRepository.GenerateMock<ILogger>(); | ||
_command = new SetHostname(_logger, _action); | ||
} | ||
|
||
[Test] | ||
public void should_call_sethostname_action() | ||
{ | ||
const string newhost = "newhost"; | ||
|
||
_action.Expect(a => a.SetHostname(newhost)).Return("0"); | ||
var result = _command.Execute(newhost); | ||
|
||
Assert.AreEqual("0", result.ExitCode); | ||
} | ||
|
||
[Test] | ||
public void should_not_execute_set_password_when_diffiehellman_statics_not_set() | ||
{ | ||
const string newhost = "newhost"; | ||
|
||
_action.Expect(a => a.SetHostname(newhost)).Throw(new Exception("sample error")); | ||
var result = _command.Execute(newhost); | ||
|
||
Assert.AreEqual("1", result.ExitCode); | ||
Assert.AreEqual("SetHostname failed", result.Error.First()); | ||
} | ||
|
||
[TearDown] | ||
public void Teardown() | ||
{ | ||
_action.VerifyAllExpectations(); | ||
} | ||
|
||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
src/Rackspace.Cloud.Server.Agent/Actions/ISetHostnameAction.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,7 @@ | ||
namespace Rackspace.Cloud.Server.Agent.Actions | ||
{ | ||
public interface ISetHostnameAction | ||
{ | ||
string SetHostname(string hostname); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Rackspace.Cloud.Server.Agent/Actions/SetHostnameAction.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,22 @@ | ||
using System; | ||
using System.Management; | ||
|
||
namespace Rackspace.Cloud.Server.Agent.Actions | ||
{ | ||
public class SetHostnameAction : ISetHostnameAction | ||
{ | ||
public string SetHostname(string hostname) | ||
{ | ||
var oldName = Environment.MachineName; | ||
using (var cs = new ManagementObject(@"Win32_Computersystem.Name='" + oldName + "'")) | ||
{ | ||
cs.Get(); | ||
var inParams = cs.GetMethodParameters("Rename"); | ||
inParams.SetPropertyValue("Name", hostname); | ||
var methodOptions = new InvokeMethodOptions(null, TimeSpan.MaxValue); | ||
var outParams = cs.InvokeMethod("Rename", inParams, methodOptions); | ||
return Convert.ToString(outParams.Properties["ReturnValue"].Value); | ||
} | ||
} | ||
} | ||
} |
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 @@ | ||
// 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://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 System.Collections.Generic; | ||
using Rackspace.Cloud.Server.Agent.Actions; | ||
using Rackspace.Cloud.Server.Agent.Configuration; | ||
using Rackspace.Cloud.Server.Agent.Interfaces; | ||
using Rackspace.Cloud.Server.Common.Logging; | ||
|
||
namespace Rackspace.Cloud.Server.Agent.Commands { | ||
public class SetHostname : IExecutableCommand | ||
{ | ||
private readonly ILogger _logger; | ||
private readonly ISetHostnameAction _setHostnameAction; | ||
|
||
public SetHostname(ILogger logger, ISetHostnameAction setHostnameAction) | ||
{ | ||
_logger = logger; | ||
_setHostnameAction = setHostnameAction; | ||
} | ||
|
||
public ExecutableResult Execute(string value) | ||
{ | ||
_logger.Log("Setting hostname to: " + value); | ||
try | ||
{ | ||
var returnValue = _setHostnameAction.SetHostname(value); | ||
return new ExecutableResult {ExitCode = returnValue}; | ||
} | ||
catch (Exception ex) | ||
{ | ||
_logger.Log("Exception was : " + ex.Message + "\nStackTrace Was: " + ex.StackTrace); | ||
return new ExecutableResult { Error = new List<string> { "SetHostname failed" }, ExitCode = "1" }; | ||
} | ||
} | ||
} | ||
} |
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
11 changes: 2 additions & 9 deletions
11
src/Rackspace.Cloud.Server.Common/Properties/AssemblyInfo.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 |
---|---|---|
@@ -1,14 +1,7 @@ | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
|
||
[assembly: AssemblyTitle("Rackspace.Cloud.Server.Common")] | ||
[assembly: AssemblyDescription("C#.NET Agent for Windows Virtual Machines")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("Rackspace Cloud")] | ||
[assembly: AssemblyProduct("Rackspace Cloud Server Agent")] | ||
[assembly: AssemblyCopyright("Copyright (c) 2009 2010, Rackspace Cloud. All Rights Reserved")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
[assembly: ComVisible(false)] | ||
[assembly: AssemblyVersion("1.2.4.0")] | ||
[assembly: AssemblyFileVersion("1.2.4.0")] | ||
[assembly: AssemblyCopyright("Copyright (c) 2009 2010 2011, Rackspace Cloud. All Rights Reserved")] | ||
[assembly: AssemblyVersion("1.2.5.0")] |
11 changes: 2 additions & 9 deletions
11
src/Rackspace.Cloud.Server.DiffieHellman.Specs/Properties/AssemblyInfo.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 |
---|---|---|
@@ -1,14 +1,7 @@ | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
|
||
[assembly: AssemblyTitle("Rackspace.Cloud.Server.DiffieHellmanManaged.Specs")] | ||
[assembly: AssemblyDescription("C#.NET Agent for Windows Virtual Machines")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("Rackspace Cloud")] | ||
[assembly: AssemblyProduct("Rackspace Cloud Server Agent")] | ||
[assembly: AssemblyCopyright("Copyright (c) 2009 2010, Rackspace Cloud. All Rights Reserved")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
[assembly: ComVisible(false)] | ||
[assembly: AssemblyVersion("1.2.4.0")] | ||
[assembly: AssemblyFileVersion("1.2.4.0")] | ||
[assembly: AssemblyCopyright("Copyright (c) 2009 2010 2011, Rackspace Cloud. All Rights Reserved")] | ||
[assembly: AssemblyVersion("1.2.5.0")] |
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