Skip to content

Commit

Permalink
Merge pull request #12 from kashivreddy/master
Browse files Browse the repository at this point in the history
Added sethostname command/feature
  • Loading branch information
kashivreddy committed Jul 30, 2013
2 parents c8a3c86 + 45f8ada commit 4f42947
Show file tree
Hide file tree
Showing 18 changed files with 183 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Properties.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
COMPANY = "Rackspace Cloud"
DESCRIPTION = "C#.NET Agent for Windows Virtual Machines"
CLR_VERSION = 'v3.5'
RELEASE_BUILD_NUMBER = "1.2.4.0"
RELEASE_BUILD_NUMBER = "1.2.5.0"

#Paths
SLN_FILE = File.join(ABSOLUTE_PATH,'src','WindowsConfigurationAgent.sln')
Expand Down
30 changes: 28 additions & 2 deletions rakefile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
Rake::Task["update_service:assemblyinfo"].execute
Rake::Task["common:assemblyinfo"].execute
Rake::Task["diffie_hellman:assemblyinfo"].execute
Rake::Task["diffie_hellmanSpecs:assemblyinfo"].execute
Rake::Task["agentSpecs:assemblyinfo"].execute
end

namespace :agent do
Expand All @@ -39,7 +41,31 @@
asm.product_name = PRODUCT
asm.description = DESCRIPTION
asm.copyright = COPYRIGHT
asm.output_file = File.join(ABSOLUTE_PATH,'src','Rackspace.Cloud.Server.Agent','Properties','AssemblyInfo.cs')
asm.output_file = File.join(ABSOLUTE_PATH,'src','Rackspace.Cloud.Server.Common','Properties','AssemblyInfo.cs')
end
end

namespace :agentSpecs do
desc "Update the version information for agentSpecs"
assemblyinfo :assemblyinfo do |asm|
asm.version = RELEASE_BUILD_NUMBER
asm.company_name = COMPANY
asm.product_name = PRODUCT
asm.description = DESCRIPTION
asm.copyright = COPYRIGHT
asm.output_file = File.join(ABSOLUTE_PATH,'src','Rackspace.Cloud.Server.Agent.Specs','Properties','AssemblyInfo.cs')
end
end

namespace :diffie_hellmanSpecs do
desc "Update the version information for diffie_hellmanSpecs library"
assemblyinfo :assemblyinfo do |asm|
asm.version = RELEASE_BUILD_NUMBER
asm.company_name = COMPANY
asm.product_name = PRODUCT
asm.description = DESCRIPTION
asm.copyright = COPYRIGHT
asm.output_file = File.join(ABSOLUTE_PATH,'src','Rackspace.Cloud.Server.DiffieHellman.Specs','Properties','AssemblyInfo.cs')
end
end

Expand All @@ -51,7 +77,7 @@
asm.product_name = PRODUCT
asm.description = DESCRIPTION
asm.copyright = COPYRIGHT
asm.output_file = File.join(ABSOLUTE_PATH,'src','Rackspace.Cloud.Server.Agent','Properties','AssemblyInfo.cs')
asm.output_file = File.join(ABSOLUTE_PATH,'src','Rackspace.Cloud.Server.Agent.DiffieHellman','Properties','AssemblyInfo.cs')
end
end

Expand Down
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")]
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
[assembly: AssemblyCompany("Rackspace Cloud")]
[assembly: AssemblyProduct("Rackspace Cloud Server Agent")]
[assembly: AssemblyCopyright("Copyright (c) 2009 2010 2011, Rackspace Cloud. All Rights Reserved")]
[assembly: AssemblyVersion("1.2.4.0")]

[assembly: AssemblyVersion("1.2.5.0")]
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")]
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<Compile Include="ReadProviderDataInformationSpec.cs" />
<Compile Include="ResetNetworkSpec.cs" />
<Compile Include="RestartServiceSpec.cs" />
<Compile Include="SetHostnameSpec.cs" />
<Compile Include="SetNetworkInterfaceSpec.cs" />
<Compile Include="SetNetworkRoutesSpec.cs" />
<Compile Include="SetPasswordCommandSpec.cs" />
Expand Down
55 changes: 55 additions & 0 deletions src/Rackspace.Cloud.Server.Agent.Specs/SetHostnameSpec.cs
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();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
[assembly: AssemblyCompany("Rackspace Cloud")]
[assembly: AssemblyProduct("Rackspace Cloud Server Agent")]
[assembly: AssemblyCopyright("Copyright (c) 2009 2010 2011, Rackspace Cloud. All Rights Reserved")]
[assembly: AssemblyVersion("1.2.4.0")]

[assembly: AssemblyVersion("1.2.5.0")]
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 src/Rackspace.Cloud.Server.Agent/Actions/SetHostnameAction.cs
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);
}
}
}
}
50 changes: 50 additions & 0 deletions src/Rackspace.Cloud.Server.Agent/Commands/SetHostname.cs
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" };
}
}
}
}
2 changes: 2 additions & 0 deletions src/Rackspace.Cloud.Server.Agent/IoC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class IoC {
StructureMapConfiguration.BuildInstancesOf<IInstaller>().TheDefaultIsConcreteType<Installer>();
StructureMapConfiguration.BuildInstancesOf<ISetNetworkInterface>().TheDefaultIsConcreteType<SetNetworkInterface>();
StructureMapConfiguration.BuildInstancesOf<ISetNetworkRoutes>().TheDefaultIsConcreteType<SetNetworkRoutes>();
StructureMapConfiguration.BuildInstancesOf<ISetHostnameAction>().TheDefaultIsConcreteType<SetHostnameAction>();

StructureMapConfiguration.BuildInstancesOf<ISetProviderData>().TheDefaultIsConcreteType<SetProviderData>();

Expand Down Expand Up @@ -96,6 +97,7 @@ public class IoC {
StructureMapConfiguration.AddInstanceOf<IExecutableCommand>().UsingConcreteType<Features>().WithName(Utilities.Commands.features.ToString());
StructureMapConfiguration.AddInstanceOf<IExecutableCommand>().UsingConcreteType<Unrescue>().WithName(Utilities.Commands.unrescue.ToString());
StructureMapConfiguration.AddInstanceOf<IExecutableCommand>().UsingConcreteType<UpdaterUpdate>().WithName(Utilities.Commands.updaterupdate.ToString());
StructureMapConfiguration.AddInstanceOf<IExecutableCommand>().UsingConcreteType<SetHostname>().WithName(Utilities.Commands.sethostname.ToString());
}
}
}
3 changes: 1 addition & 2 deletions src/Rackspace.Cloud.Server.Agent/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
[assembly: AssemblyCompany("Rackspace Cloud")]
[assembly: AssemblyProduct("Rackspace Cloud Server Agent")]
[assembly: AssemblyCopyright("Copyright (c) 2009 2010 2011, Rackspace Cloud. All Rights Reserved")]
[assembly: AssemblyVersion("1.2.4.0")]

[assembly: AssemblyVersion("1.2.5.0")]
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Actions\ChecksumValidator.cs" />
<Compile Include="Actions\ISetHostnameAction.cs" />
<Compile Include="Actions\SetHostnameAction.cs" />
<Compile Include="Actions\SetProviderData.cs" />
<Compile Include="Actions\Downloader.cs" />
<Compile Include="Actions\FileCopier.cs" />
Expand All @@ -97,6 +99,7 @@
<Compile Include="Actions\Sleeper.cs" />
<Compile Include="Actions\ServiceStarter.cs" />
<Compile Include="Actions\ServiceStopper.cs" />
<Compile Include="Commands\SetHostname.cs" />
<Compile Include="Commands\Unrescue.cs" />
<Compile Include="Actions\Unzipper.cs" />
<Compile Include="Actions\VersionChecker.cs" />
Expand Down
3 changes: 2 additions & 1 deletion src/Rackspace.Cloud.Server.Agent/Utilities/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public enum Commands
injectfile,
features,
unrescue,
updaterupdate
updaterupdate,
sethostname
}

public class NotUrlEncodedAttribute : Attribute
Expand Down
11 changes: 2 additions & 9 deletions src/Rackspace.Cloud.Server.Common/Properties/AssemblyInfo.cs
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")]
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")]
1 change: 1 addition & 0 deletions src/WindowsConfigurationAgent.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build Artifacts", "Build Ar
..\Click To Build.bat = ..\Click To Build.bat
..\installagentservice.bat = ..\installagentservice.bat
..\installupdateservice.bat = ..\installupdateservice.bat
..\Properties.rb = ..\Properties.rb
..\rakefile.rb = ..\rakefile.rb
..\README.txt = ..\README.txt
EndProjectSection
Expand Down

0 comments on commit 4f42947

Please sign in to comment.