You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by de...@apache.org on 2014/01/10 12:38:53 UTC
git commit: updated refs/heads/4.3 to 06a7795
Updated Branches:
refs/heads/4.3 f417297bb -> 06a779555
CLOUDSTACK-5657: Run the service as an account (hyper-v admin on host) so
that migration can work across hosts.
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/06a77955
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/06a77955
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/06a77955
Branch: refs/heads/4.3
Commit: 06a77955528a92c27d32b90b619da11408cb4c25
Parents: f417297
Author: Devdeep Singh <de...@gmail.com>
Authored: Thu Jan 9 20:42:47 2014 +0530
Committer: Devdeep Singh <de...@gmail.com>
Committed: Fri Jan 10 17:09:26 2014 +0530
----------------------------------------------------------------------
.../DotNet/ServerResource/AgentShell/Program.cs | 87 ++++++++++++++++++--
.../AgentShell/ProjectInstaller.Designer.cs | 31 +++++--
2 files changed, 102 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/06a77955/plugins/hypervisors/hyperv/DotNet/ServerResource/AgentShell/Program.cs
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/AgentShell/Program.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/AgentShell/Program.cs
index 5e58211..7545644 100644
--- a/plugins/hypervisors/hyperv/DotNet/ServerResource/AgentShell/Program.cs
+++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/AgentShell/Program.cs
@@ -29,7 +29,13 @@ namespace CloudStack.Plugin.AgentShell
static class Program
{
private static ILog logger = LogManager.GetLogger(typeof(Program));
- public static string serviceName = "CloudStack Hyper-V Agent";
+ public const string serviceName = "CloudStack Hyper-V Agent";
+ private static string option = null;
+ private static string user = null;
+ private static string password = null;
+ private const string install = "--install";
+ private const string uninstall = "--uninstall";
+ private const string console = "--console";
/// <summary>
/// Application entry point allows service to run in console application or as a Windows service.
@@ -43,22 +49,21 @@ namespace CloudStack.Plugin.AgentShell
ServiceBase[] ServicesToRun = new ServiceBase[] { new AgentService() };
ServiceBase.Run(ServicesToRun);
}
- else if (args.Length == 1)
+ else if (ParseArguments(args))
{
- logger.DebugFormat(serviceName + " arg is ", args[0]);
- switch (args[0])
+ switch (option)
{
- case "--install":
+ case install:
logger.InfoFormat("Installing and running " + serviceName);
InstallService();
StartService();
break;
- case "--uninstall":
+ case uninstall:
logger.InfoFormat("Stopping and uninstalling " + serviceName);
StopService();
UninstallService();
break;
- case "--console":
+ case console:
logger.InfoFormat(serviceName + " is running as console application");
new AgentService().RunConsole(args);
break;
@@ -66,6 +71,74 @@ namespace CloudStack.Plugin.AgentShell
throw new NotImplementedException();
}
}
+ else
+ {
+ string argumentExample = "--(install/uninstall/console) [-u <hyper-v admin user>] [-p <hyper-v admin password>].\n" +
+ " For example:\n " +
+ " --install -u domain1\\user1 -p mypwd\n"+
+ " --uninstall";
+ logger.Error("Invalid arguments passed for installing\\uninstalling the service. \n" + argumentExample);
+ }
+ }
+
+ static private Boolean ParseArguments(string[] args)
+ {
+ logger.DebugFormat(serviceName + " arg is ", args[0]);
+ int argIndex = 0;
+ while (argIndex < args.Length)
+ {
+ switch (args[argIndex])
+ {
+ case install:
+ case uninstall:
+ case console:
+ option = args[argIndex];
+ argIndex++;
+ break;
+ case "-u":
+ user = args[argIndex+1];
+ argIndex+=2;
+ break;
+ case "-p":
+ password = args[argIndex+1];
+ argIndex+=2;
+ break;
+ default:
+ argIndex++;
+ // Unrecognised argument. Do nothing;
+ break;
+ }
+ }
+
+ // Validate arguments
+ return ValidateArguments();
+ }
+
+ private static Boolean ValidateArguments()
+ {
+ Boolean argsValid = false;
+ switch (option)
+ {
+ case uninstall:
+ case install:
+ case console:
+ argsValid = true;
+ break;
+ default:
+ break;
+ }
+
+ return argsValid;
+ }
+
+ public static string GetPassword()
+ {
+ return password;
+ }
+
+ public static string GetUser()
+ {
+ return user;
}
private static bool IsInstalled()
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/06a77955/plugins/hypervisors/hyperv/DotNet/ServerResource/AgentShell/ProjectInstaller.Designer.cs
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/hyperv/DotNet/ServerResource/AgentShell/ProjectInstaller.Designer.cs b/plugins/hypervisors/hyperv/DotNet/ServerResource/AgentShell/ProjectInstaller.Designer.cs
index d858192..2c6ffe2 100644
--- a/plugins/hypervisors/hyperv/DotNet/ServerResource/AgentShell/ProjectInstaller.Designer.cs
+++ b/plugins/hypervisors/hyperv/DotNet/ServerResource/AgentShell/ProjectInstaller.Designer.cs
@@ -46,22 +46,35 @@ namespace CloudStack.Plugin.AgentShell
{
this.serviceProcessInstaller = new System.ServiceProcess.ServiceProcessInstaller();
this.serviceInstaller = new System.ServiceProcess.ServiceInstaller();
- //
+ //
// serviceProcessInstaller
- //
- this.serviceProcessInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
- this.serviceProcessInstaller.Password = null;
- this.serviceProcessInstaller.Username = null;
- //
+ //
+ string user = Program.GetUser();
+ string password = Program.GetPassword();
+
+ if (string.IsNullOrEmpty(user))
+ {
+ this.serviceProcessInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
+ this.serviceProcessInstaller.Password = null;
+ this.serviceProcessInstaller.Username = null;
+ }
+ else
+ {
+ this.serviceProcessInstaller.Account = System.ServiceProcess.ServiceAccount.User;
+ this.serviceProcessInstaller.Password = password;
+ this.serviceProcessInstaller.Username = user;
+ }
+
+ //
// serviceInstaller
- //
+ //
this.serviceInstaller.Description = "CloudStack agent for managing a hyper-v host";
this.serviceInstaller.DisplayName = Program.serviceName;
this.serviceInstaller.ServiceName = Program.serviceName;
this.serviceInstaller.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
- //
+ //
// ProjectInstaller
- //
+ //
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.serviceProcessInstaller,
this.serviceInstaller});