static void Main(string[] args) { var app = ShellHelper.CreateConsoleApp(APP_NAME, "Telegram bot for Proxmox VE"); ShellCommands.Commands(app); app.ExecuteConsoleApp(Console.Out, args); }
static int Main(string[] args) { var app = ShellHelper.CreateConsoleApp(APP_NAME, "Command line for Proxmox VE"); ShellCommands.Commands(app); return(app.ExecuteConsoleApp(args)); }
static int Main(string[] args) { var app = ShellHelper.CreateConsoleApp(Application.NAME, "Automatic snapshot VM/CT with retention"); new ShellCommands(app); return(app.ExecuteConsoleApp(args)); }
/// <summary> /// Main for cli. /// </summary> /// <param name="args"></param> /// <returns></returns> public static int MainForCli(string[] args) { var app = ShellHelper.CreateConsoleApp(Command.APPLICATION_NAME, "Automatic snapshot with retention"); new ShellCommand(app); return(app.ExecuteConsoleApp(Console.Out, args)); }
static int Main(string[] args) { var app = ShellHelper.CreateConsoleApp("cv4pve-node-protect", "Node protect for Proxmox VE"); app.GetApiToken().ShowInHelpText = false; new ShellCommands(app); return(app.ExecuteConsoleApp(args)); }
static int Main(string[] args) { var app = ShellHelper.CreateConsoleApp("cv4pve-pepper", "Launching SPICE on Proxmox VE"); var optVmId = app.VmIdOrNameOption().DependOn(app, CommandOptionExtension.HOST_OPTION_NAME); var optRemoteViewer = app.Option("--viewer", "Executable SPICE client remote viewer", CommandOptionType.SingleValue) .DependOn(app, CommandOptionExtension.HOST_OPTION_NAME); optRemoteViewer.Accepts().ExistingFile(); app.OnExecute(() => { var fileName = Path.GetTempFileName().Replace(".tmp", ".vv"); var ret = SpiceHelper.CreateFileSpaceClient(app.ClientTryLogin(), optVmId.Value(), fileName); if (ret) { var process = new Process { StartInfo = new ProcessStartInfo() { UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = false, FileName = StringHelper.Quote(optRemoteViewer.Value()), Arguments = StringHelper.Quote(fileName) } }; if (app.DebugIsActive()) { app.Out.WriteLine($"Run FileName: {process.StartInfo.FileName}"); app.Out.WriteLine($"Run Arguments: {process.StartInfo.Arguments}"); } if (!app.DryRunIsActive()) { process.Start(); ret = process.HasExited ? process.ExitCode == 0 : true; } } return(ret ? 0 : 1); }); return(app.ExecuteConsoleApp(args)); }
static void Main(string[] args) { var app = ShellHelper.CreateConsoleApp("cv4pve-botgram", "Telegram bot for Proxmox VE"); var optToken = app.Option("--token", "Telegram API token bot", CommandOptionType.SingleValue) .DependOn(app, CommandOptionExtension.HOST_OPTION_NAME); var optChatsId = app.Option("--chatsId", "Telegram Chats Id valid for communication (comma separated)", CommandOptionType.SingleValue); app.OnExecute(() => { var chatsId = new List <long>(); foreach (var chatId in (optChatsId.Value() + "").Split(",")) { if (long.TryParse(chatId, out var id)) { chatsId.Add(id); } } var botManager = new BotManager(app.GetHost().Value(), app.GetApiToken().Value(), app.GetUsername().Value(), app.GetPasswordFromOption(), optToken.Value(), chatsId.ToArray(), app.Out); botManager.StartReceiving(); Console.ReadLine(); try { botManager.StopReceiving(); } catch { } app.Out.WriteLine("End application"); }); app.ExecuteConsoleApp(args); }
static int Main(string[] args) { var app = ShellHelper.CreateConsoleApp("cv4pve-pepper", "Launching SPICE on Proxmox VE"); var optVmId = app.VmIdOrNameOption().DependOn(app, CommandOptionExtension.HOST_OPTION_NAME); var optRemoteViewer = app.Option("--viewer", "Executable SPICE client remote viewer", CommandOptionType.SingleValue) .DependOn(app, CommandOptionExtension.HOST_OPTION_NAME); optRemoteViewer.Accepts().ExistingFile(); app.OnExecute(() => { var fileName = Path.GetTempFileName().Replace(".tmp", ".vv"); var client = app.ClientTryLogin(); var ret = SpiceHelper.CreateFileSpaceClient(client, optVmId.Value(), fileName); if (ret) { var startInfo = new ProcessStartInfo { UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = false, }; if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { startInfo.FileName = "/bin/bash"; startInfo.Arguments = $"-c \"{optRemoteViewer.Value()} {fileName}\""; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { startInfo.FileName = StringHelper.Quote(optRemoteViewer.Value()); startInfo.Arguments = StringHelper.Quote(fileName); } var process = new Process { StartInfo = startInfo }; if (app.DebugIsActive()) { app.Out.WriteLine($"Run FileName: {process.StartInfo.FileName}"); app.Out.WriteLine($"Run Arguments: {process.StartInfo.Arguments}"); } if (!app.DryRunIsActive()) { process.Start(); ret = !process.HasExited || process.ExitCode == 0; } } else { if (!client.LastResult.IsSuccessStatusCode) { app.Out.WriteLine($"Error: {client.LastResult.ReasonPhrase}"); } } return(ret ? 0 : 1); }); return(app.ExecuteConsoleApp(args)); }
static int Main(string[] args) { var app = ShellHelper.CreateConsoleApp("cv4pve-pepper", "Launching SPICE on Proxmox VE"); var optVmId = app.VmIdOrNameOption().DependOn(app, CommandOptionExtension.HOST_OPTION_NAME); var optProxy = app.Option("--proxy", @"SPICE proxy server. This can be used by the client to specify the proxy server." + " All nodes in a cluster runs 'spiceproxy', so it is up to the client to choose one." + " By default, we return the node where the VM is currently running." + " If specify http://[host]:[port] then replace proxy option in file .vv. E.g. for reverse proxy.", CommandOptionType.SingleValue); var optRemoteViewer = app.Option("--viewer", "Executable SPICE client remote viewer", CommandOptionType.SingleValue) .DependOn(app, CommandOptionExtension.HOST_OPTION_NAME); optRemoteViewer.Accepts().ExistingFile(); app.OnExecute(() => { var client = app.ClientTryLogin(); var proxy = optProxy.HasValue() ? optProxy.Value() : null; var proxyForce = (proxy + "").ToLower().StartsWith("http://"); var content = client.GetVM(optVmId.Value()).GetSpiceFileVV(proxyForce ? null : proxy); var ret = client.LastResult.IsSuccessStatusCode; if (ret) { //proxy force if (proxyForce) { var lines = content.Split("\n"); for (int i = 0; i < lines.Length; i++) { if (lines[i].StartsWith("proxy=")) { lines[i] = $"proxy={proxy}"; break; } } content = string.Join("\n", lines); if (app.DebugIsActive()) { app.Out.WriteLine($"Replace Proxy: {proxy}"); app.Out.WriteLine(content); } } var fileName = Path.GetTempFileName().Replace(".tmp", ".vv"); File.WriteAllText(fileName, content); var startInfo = new ProcessStartInfo { UseShellExecute = false, CreateNoWindow = true, RedirectStandardOutput = false, }; if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { startInfo.FileName = "/bin/bash"; startInfo.Arguments = $"-c \"{optRemoteViewer.Value()} {fileName}\""; } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { startInfo.FileName = StringHelper.Quote(optRemoteViewer.Value()); startInfo.Arguments = StringHelper.Quote(fileName); } var process = new Process { StartInfo = startInfo }; if (app.DebugIsActive()) { app.Out.WriteLine($"Run FileName: {process.StartInfo.FileName}"); app.Out.WriteLine($"Run Arguments: {process.StartInfo.Arguments}"); } if (!app.DryRunIsActive()) { process.Start(); ret = !process.HasExited || process.ExitCode == 0; } } else { if (!app.ClientTryLogin().LastResult.IsSuccessStatusCode) { app.Out.WriteLine($"Error: {app.ClientTryLogin().LastResult.ReasonPhrase}"); } } return(ret ? 0 : 1); }); return(app.ExecuteConsoleApp(args)); }
static void Main(string[] args) { var settingsFileName = "settings.json"; var ignoredIssuesFileName = "ignored-issues.json"; var app = ShellHelper.CreateConsoleApp("cv4pve-diag", "Diagnostic for Proxmox VE"); var optSettingsFile = app.Option("--settings-file", "File settings (generated from create-settings)", CommandOptionType.SingleValue); optSettingsFile.Accepts().ExistingFile(); var optIgnoredIssuesFile = app.Option("--ignored-issues-file", "File ignored issues (generated from create-ignored-issues)", CommandOptionType.SingleValue); optIgnoredIssuesFile.Accepts().ExistingFile(); var optShowIgnoredIssues = app.Option("--ignored-issues-show", "Show second table with ignored issue", CommandOptionType.NoValue); var optOutput = app.OutputTypeArgument(); app.Command("create-settings", cmd => { cmd.Description = $"Create file settings ({settingsFileName})"; cmd.AddFullNameLogo(); cmd.OnExecute(() => { File.WriteAllText(settingsFileName, JsonConvert.SerializeObject(new Settings(), Formatting.Indented)); app.Out.WriteLine(PrintEnum("SeriesType", typeof(SettingsTimeSeriesType))); app.Out.WriteLine($"Create file: {settingsFileName}"); }); }); app.Command("create-ignored-issues", cmd => { cmd.Description = $"Create File ignored issues ({ignoredIssuesFileName})"; cmd.AddFullNameLogo(); cmd.OnExecute(() => { File.WriteAllText(ignoredIssuesFileName, JsonConvert.SerializeObject(new[] { new DiagnosticResult() }, Formatting.Indented)); app.Out.WriteLine(PrintEnum("Context", typeof(DiagnosticResultContext))); app.Out.WriteLine(PrintEnum("Gravity", typeof(DiagnosticResultGravity))); app.Out.WriteLine($"Create file: {ignoredIssuesFileName}"); }); }); var fileExport = "data.json"; app.Command("export-collect", cmd => { cmd.ShowInHelpText = false; cmd.Description = $"Export collect data collect to {fileExport}"; cmd.AddFullNameLogo(); cmd.OnExecute(() => { var ci = new ClusterInfo(); ci.Collect(app.ClientTryLogin()); File.WriteAllText(fileExport, JsonConvert.SerializeObject(ci, Formatting.Indented)); app.Out.WriteLine($"Exported {fileExport}!"); }); }); app.Command("examine-collect", cmd => { cmd.ShowInHelpText = false; cmd.Description = $"Examine collect data collect from {fileExport}"; cmd.AddFullNameLogo(); cmd.OnExecute(() => { var ci = JsonConvert.DeserializeObject <ClusterInfo>(File.ReadAllText(fileExport)); Print(app, ci, optSettingsFile, optIgnoredIssuesFile, optShowIgnoredIssues, optOutput); }); }); app.OnExecute(() => { var ci = new ClusterInfo(); ci.Collect(app.ClientTryLogin()); ci = JsonConvert.DeserializeObject <ClusterInfo>(JsonConvert.SerializeObject(ci)); Print(app, ci, optSettingsFile, optIgnoredIssuesFile, optShowIgnoredIssues, optOutput); }); app.ExecuteConsoleApp(args); }