예제 #1
0
 protected override bool CheckUnusedEnvironmentVariables(ClientOptions options)
 {
     return(true);
 }
예제 #2
0
 public override int Execute(ClientController controller, ClientOptions options)
 {
     controller.TakeSnapshot(options.Values[1]);
     return(0);
 }
예제 #3
0
 protected override bool CheckValues(ClientOptions options)
 {
     return(Check(options.Values.Count >= 2, "Missing command to execute."));
 }
예제 #4
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);
            }
        }
예제 #5
0
 protected override bool CheckValues(ClientOptions options)
 {
     return(Check(options.Values.Count >= 2, "Missing new snapshot name.") &&
            Check(options.Values.Count == 2, "Found excess arguments."));
 }
예제 #6
0
 protected override bool CheckValues(ClientOptions options)
 {
     return(Check(options.Values.Count >= 3, "Missing files to copy.") &&
            Check(options.Values.Count == 3, "Found excess arguments."));
 }
예제 #7
0
 protected override bool CheckUnusedForce(ClientOptions options)
 {
     return(true);
 }
예제 #8
0
 protected virtual bool CheckUnusedWorkingDirectory(ClientOptions options)
 {
     return(Check(options.WorkingDirectory == null,
                  "--dir is not used by this command."));
 }
예제 #9
0
 protected virtual bool CheckUnusedTimeout(ClientOptions options)
 {
     return(Check(options.Timeout == 0,
                  "--timeout is not used by this command."));
 }
예제 #10
0
 protected virtual bool CheckUnusedForce(ClientOptions options)
 {
     return(Check(!options.Force,
                  "--force is not used by this command."));
 }
예제 #11
0
 protected virtual bool CheckUnusedEnvironmentVariables(ClientOptions options)
 {
     return(Check(options.EnvironmentVariables == null || options.EnvironmentVariables.Length == 0,
                  "--env is not used by this command."));
 }
예제 #12
0
 protected virtual bool CheckUnusedRecursive(ClientOptions options)
 {
     return(Check(!options.Recursive,
                  "--recursive is not used by this command."));
 }
예제 #13
0
 protected virtual bool CheckValues(ClientOptions options)
 {
     return(Check(options.Values.Count == 1,
                  "Found excess arguments."));
 }
예제 #14
0
 public abstract int Execute(ClientController controller, ClientOptions options);
예제 #15
0
 protected override bool CheckUnusedWorkingDirectory(ClientOptions options)
 {
     return(true);
 }
예제 #16
0
 public override bool Validate(Profile profile, ClientOptions options)
 {
     return(base.Validate(profile, options) &&
            Check(profile.VM != null, "--vm or --profile required for this command."));
 }
예제 #17
0
 protected override bool CheckUnusedTimeout(ClientOptions options)
 {
     return(true);
 }
예제 #18
0
 public override int Execute(ClientController controller, ClientOptions options)
 {
     controller.PowerOff();
     return(0);
 }
예제 #19
0
 protected override bool CheckUnusedRecursive(ClientOptions options)
 {
     return(true);
 }
예제 #20
0
 public override int Execute(ClientController controller, ClientOptions options)
 {
     controller.SaveState();
     return(0);
 }
예제 #21
0
 public override int Execute(ClientController controller, ClientOptions options)
 {
     controller.CopyFromVM(options.Values[1], options.Values[2],
                           options.Recursive, options.Force);
     return(0);
 }
예제 #22
0
 private static void PrintErrorMessageAndHelp(ClientOptions options, string message)
 {
     Console.Error.WriteLine(message);
     Console.Error.WriteLine();
     Console.Error.WriteLine(options.GetUsage());
 }