start stop vm test

master
Tudor Stanciu 2022-04-07 08:27:42 +03:00
parent 6e7d32220a
commit de38dd0c9c
5 changed files with 56 additions and 3 deletions

View File

@ -17,6 +17,8 @@ https://forum.proxmox.com/threads/shutdown-the-server-via-api.98125/
https://github.com/Corsinvest/cv4pve-api-dotnet https://github.com/Corsinvest/cv4pve-api-dotnet
API Viewer: https://pve.proxmox.com/pve-docs/api-viewer/index.html
***REMOVED*** ***REMOVED***
https://***REMOVED******REMOVED***/ https://***REMOVED******REMOVED***/

View File

@ -6,5 +6,7 @@ namespace ProxmoxConnector.Integration.Abstractions
{ {
Task TestWithLogin(); Task TestWithLogin();
Task TestWithToken(); Task TestWithToken();
Task Start();
Task Stop();
} }
} }

View File

@ -10,10 +10,11 @@ namespace ProxmoxConnector.Integration.Corsinvest.Services
{ {
public async Task TestWithLogin() public async Task TestWithLogin()
{ {
//var client = new PveClient("***REMOVED***"); ***REMOVED*** ***REMOVED***
var client = new PveClient("***REMOVED***"); ***REMOVED*** var client = new PveClient("***REMOVED***"); ***REMOVED***
if (await client.Login(***REMOVED***)) if (await client.Login(***REMOVED***))
{ {
var vm = client.Nodes["pve-test1"].Qemu[100]; var vm = client.Nodes["pve-lora"].Qemu[100];
//config vm //config vm
var config = await vm.Config.VmConfig(); var config = await vm.Config.VmConfig();
@ -50,5 +51,33 @@ namespace ProxmoxConnector.Integration.Corsinvest.Services
var version = await client2.Version.Version(); var version = await client2.Version.Version();
Console.WriteLine(JsonConvert.SerializeObject(version.Response.data, Formatting.Indented)); Console.WriteLine(JsonConvert.SerializeObject(version.Response.data, Formatting.Indented));
} }
public async Task Start()
{
var client = new PveClient("***REMOVED***"); ***REMOVED***
if (await client.Login(***REMOVED***))
{
var vm = client.Nodes["pve-lora"].Qemu[100];
var startEvent = vm.Status.Start;
var start = await startEvent.VmStart();
if (start.IsSuccessStatusCode)
Console.WriteLine(JsonConvert.SerializeObject(start.Response, Formatting.Indented));
}
}
public async Task Stop()
{
var client = new PveClient("***REMOVED***"); ***REMOVED***
if (await client.Login(***REMOVED***))
{
var vm = client.Nodes["pve-lora"].Qemu[100];
var stopEvent = vm.Status.Stop;
var stop = await stopEvent.VmStop();
if (stop.IsSuccessStatusCode)
Console.WriteLine(JsonConvert.SerializeObject(stop.Response, Formatting.Indented));
}
}
} }
} }

View File

@ -1,6 +1,5 @@
using MediatR; using MediatR;
using ProxmoxConnector.Integration.Abstractions; using ProxmoxConnector.Integration.Abstractions;
using ProxmoxConnector.Server.Application.Utils;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@ -1,7 +1,9 @@
using MediatR; using MediatR;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using ProxmoxConnector.Integration.Abstractions;
using ProxmoxConnector.Server.Application.Queries; using ProxmoxConnector.Server.Application.Queries;
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ProxmoxConnector.Server.Controllers namespace ProxmoxConnector.Server.Controllers
@ -12,10 +14,12 @@ namespace ProxmoxConnector.Server.Controllers
public class ConnectorController : ControllerBase public class ConnectorController : ControllerBase
{ {
private readonly IMediator _mediator; private readonly IMediator _mediator;
private readonly IPveConnector _pveConnector;
public ConnectorController(IMediator mediator) public ConnectorController(IMediator mediator, IPveConnector pveConnector)
{ {
_mediator=mediator; _mediator=mediator;
_pveConnector=pveConnector;
} }
[AllowAnonymous] [AllowAnonymous]
@ -25,5 +29,22 @@ namespace ProxmoxConnector.Server.Controllers
var result = await _mediator.Send(query); var result = await _mediator.Send(query);
return Ok(result); return Ok(result);
} }
[AllowAnonymous]
[HttpGet("start")]
public async Task<IActionResult> Start()
{
await _pveConnector.Start();
return Ok(DateTime.Now);
}
[AllowAnonymous]
[HttpGet("stop")]
public async Task<IActionResult> Stop()
{
await _pveConnector.Stop();
return Ok(DateTime.Now);
}
} }
} }