Ejemplo n.º 1
0
 public override int Execute(ClientController controller, ClientOptions options)
 {
     controller.CopyFromVM(options.Values[1], options.Values[2],
         options.Recursive, options.Force);
     return 0;
 }
Ejemplo n.º 2
0
 public override int Execute(ClientController controller, ClientOptions options)
 {
     string ip = controller.GetIP();
     Console.Out.WriteLine(ip);
     return 0;
 }
Ejemplo n.º 3
0
            public override int Execute(ClientController controller, ClientOptions options)
            {
                Dictionary<string, string> environmentVariables = null;
                if (options.EnvironmentVariables != null)
                {
                    environmentVariables = new Dictionary<string, string>();
                    foreach (string v in options.EnvironmentVariables)
                    {
                        int equalsPos = v.IndexOf('=');
                        if (equalsPos < 0)
                            environmentVariables[v] = "";
                        else
                            environmentVariables[v.Substring(0, equalsPos)] = v.Substring(equalsPos + 1);
                    }
                }

                string executable = options.Values[1];
                StringBuilder arguments = new StringBuilder();
                for (int i = 2; i < options.Values.Count; i++)
                {
                    if (i != 2)
                        arguments.Append(" ");

                    string argument = options.Values[i];
                    if (ShouldArgumentBeQuoted(argument))
                        arguments.Append("\"").Append(argument).Append("\"");
                    else
                        arguments.Append(argument);
                }

                return controller.Execute(executable, arguments.ToString(), options.WorkingDirectory,
                    environmentVariables,
                    line => Console.Out.WriteLine(line),
                    line => Console.Error.WriteLine(line),
                    options.Timeout <= 0 ? (TimeSpan?)null : TimeSpan.FromSeconds(options.Timeout));
            }
Ejemplo n.º 4
0
 public override int Execute(ClientController controller, ClientOptions options)
 {
     controller.TakeSnapshot(options.Values[1]);
     return 0;
 }
Ejemplo n.º 5
0
 public override int Execute(ClientController controller, ClientOptions options)
 {
     Status status = controller.GetStatus();
     Console.Out.WriteLine(status);
     return 0;
 }
Ejemplo n.º 6
0
 public override int Execute(ClientController controller, ClientOptions options)
 {
     controller.Shutdown();
     return 0;
 }
Ejemplo n.º 7
0
 public override int Execute(ClientController controller, ClientOptions options)
 {
     controller.SaveState();
     return 0;
 }
Ejemplo n.º 8
0
        public static int Main(string[] args)
        {
            try
            {
                var options = new ClientOptions();
                var parser = new CommandLineParser();
                if (!parser.ParseArguments(args, options, Console.Error))
                    return 1;

                if (options.Values == null || options.Values.Count == 0)
                {
                    PrintErrorMessageAndHelp(options,"Must specify a command.");
                    return 1;
                }

                string commandName = options.Values[0];
                Command command = CreateCommand(commandName);
                if (command == null)
                {
                    PrintErrorMessageAndHelp(options, "Unrecognized command name.");
                    return 1;
                }

                bool haveMaster = options.Master != null;
                bool haveProfile = options.Configuration != null || options.Profile != null;
                if (haveMaster && haveProfile
                    || ! haveMaster && ! haveProfile
                    || (options.Configuration != null) != (options.Profile != null))
                {
                    PrintErrorMessageAndHelp(options, "Must specify either --master or both --configuration and --profile.");
                    return 1;
                }

                Profile profile;
                if (options.Configuration != null && options.Profile != null)
                {
                    XmlConfiguration xmlConfiguration = ConfigurationFileHelper.LoadConfiguration(options.Configuration);
                    XmlProfile xmlProfile = xmlConfiguration.GetProfileById(options.Profile);
                    if (xmlProfile == null)
                    {
                        PrintErrorMessageAndHelp(options, "Profile not found in configuration file.");
                        return 1;
                    }

                    profile = xmlProfile.ToProfile();
                }
                else
                {
                    profile = new Profile()
                    {
                        Master = options.Master,
                        MasterPort = options.MasterPort,
                        Slave = options.Slave,
                        SlavePort = options.SlavePort,
                        VM = options.VM,
                        Snapshot = options.Snapshot
                    };
                }

                if (!command.Validate(profile, options))
                    return 1;

                using (var controller = new ClientController(profile))
                {
                    controller.Quiet = options.Quiet;
                    controller.ConnectionTimeout = TimeSpan.FromSeconds(options.ConnectionTimeout);

                    try
                    {
                        return command.Execute(controller, options);
                    }
                    catch (OperationFailedException ex)
                    {
                        Console.Error.WriteLine("Operation failed.");
                        Console.Error.WriteLine(ex.Why);

                        if (ex.__isset.details)
                        {
                            Console.Error.WriteLine("Details:");
                            Console.Error.WriteLine(ex.Details);
                        }
                        return 1;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Fatal exception: " + ex);
                return 1;
            }
        }
Ejemplo n.º 9
0
 public override int Execute(ClientController controller, ClientOptions options)
 {
     controller.PowerOff();
     return 0;
 }
Ejemplo n.º 10
0
 public override int Execute(ClientController controller, ClientOptions options)
 {
     controller.CopyFromVM(options.Values[1], options.Values[2],
                           options.Recursive, options.Force);
     return(0);
 }
Ejemplo n.º 11
0
 public abstract int Execute(ClientController controller, ClientOptions options);
Ejemplo n.º 12
0
 public override int Execute(ClientController controller, ClientOptions options)
 {
     controller.TakeSnapshot(options.Values[1]);
     return(0);
 }
Ejemplo n.º 13
0
 public override int Execute(ClientController controller, ClientOptions options)
 {
     controller.SaveState();
     return(0);
 }
Ejemplo n.º 14
0
 public override int Execute(ClientController controller, ClientOptions options)
 {
     controller.PowerOff();
     return(0);
 }
Ejemplo n.º 15
0
 public abstract int Execute(ClientController controller, ClientOptions options);
Ejemplo n.º 16
0
        public static int Main(string[] args)
        {
            try
            {
                var options = new ClientOptions();
                var parser  = new CommandLineParser();
                if (!parser.ParseArguments(args, options, Console.Error))
                {
                    return(1);
                }

                if (options.Values == null || options.Values.Count == 0)
                {
                    PrintErrorMessageAndHelp(options, "Must specify a command.");
                    return(1);
                }

                string  commandName = options.Values[0];
                Command command     = CreateCommand(commandName);
                if (command == null)
                {
                    PrintErrorMessageAndHelp(options, "Unrecognized command name.");
                    return(1);
                }

                bool haveMaster  = options.Master != null;
                bool haveProfile = options.Configuration != null || options.Profile != null;
                if (haveMaster && haveProfile ||
                    !haveMaster && !haveProfile ||
                    (options.Configuration != null) != (options.Profile != null))
                {
                    PrintErrorMessageAndHelp(options, "Must specify either --master or both --configuration and --profile.");
                    return(1);
                }

                Profile profile;
                if (options.Configuration != null && options.Profile != null)
                {
                    XmlConfiguration xmlConfiguration = ConfigurationFileHelper.LoadConfiguration(options.Configuration);
                    XmlProfile       xmlProfile       = xmlConfiguration.GetProfileById(options.Profile);
                    if (xmlProfile == null)
                    {
                        PrintErrorMessageAndHelp(options, "Profile not found in configuration file.");
                        return(1);
                    }

                    profile = xmlProfile.ToProfile();
                }
                else
                {
                    profile = new Profile()
                    {
                        Master     = options.Master,
                        MasterPort = options.MasterPort,
                        Slave      = options.Slave,
                        SlavePort  = options.SlavePort,
                        VM         = options.VM,
                        Snapshot   = options.Snapshot
                    };
                }

                if (!command.Validate(profile, options))
                {
                    return(1);
                }

                using (var controller = new ClientController(profile))
                {
                    controller.Quiet             = options.Quiet;
                    controller.ConnectionTimeout = TimeSpan.FromSeconds(options.ConnectionTimeout);

                    try
                    {
                        return(command.Execute(controller, options));
                    }
                    catch (OperationFailedException ex)
                    {
                        Console.Error.WriteLine("Operation failed.");
                        Console.Error.WriteLine(ex.Why);

                        if (ex.__isset.details)
                        {
                            Console.Error.WriteLine("Details:");
                            Console.Error.WriteLine(ex.Details);
                        }
                        return(1);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Fatal exception: " + ex);
                return(1);
            }
        }