public static PveClient GetClient() { var client = new PveClient(Host, Port); client.Login(Username, Password); return(client); }
private async Task Login() { bool successful = await Task.Run(() => client.Login(HypervisorNode.Hypervisor.UserName, _password)); if (!successful) { throw new UnauthorizedProxmoxUser(); } _loggedInAt = DateTime.Now; }
/// <summary> /// Try login client api /// </summary> /// <param name="command"></param> /// <returns></returns> public static PveClient ClientTryLogin(this CommandLineApplication command) { var error = "Problem connection!"; foreach (var host in GetHostAndPort(command)) { using (var ping = new Ping()) { if (ping.Send(host.Host).Status != IPStatus.Success) { if (command.DebugIsActive()) { command.Out.WriteLine($"Error: try login unknown host {host.Host}"); } continue; } } try { var client = new PveClient(host.Host, host.Port); //check enable debug if (command.DebugIsActive()) { client.DebugLevel = 99; } //try login if (client.Login(command.GetOption(USERNAME_OPTION_NAME, true).Value(), GetPasswordFromOption(command))) { return(client); } if (!client.LastResult.IsSuccessStatusCode) { error += " " + client.LastResult.ReasonPhrase; } } catch { } } throw new ApplicationException(error); }
private static void Run(Options option) { var builder = new HostBuilder() .UseConsoleLifetime(); var host = builder.Build(); using var serviceScope = host.Services.CreateScope(); { var services = serviceScope.ServiceProvider; try { var client = new PveClient(option.Host, option.Port); if (!client.Login(option.Username, option.Password)) { return; } if (option.isDebugger) { Console.WriteLine($"Connect to PVE[{option.Host}] with {option.Username}"); } foreach (var vm in client.GetVMs()) { vm.LxcApi.Vncproxy.CreateRest(); if (option.isDebugger) { Console.WriteLine($"Connect to [{vm.Node}]'s VM {vm.Name} ...{vm.Status}"); } } } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred."); } } }