start stop vm test
parent
6e7d32220a
commit
de38dd0c9c
|
@ -17,6 +17,8 @@ https://forum.proxmox.com/threads/shutdown-the-server-via-api.98125/
|
|||
|
||||
https://github.com/Corsinvest/cv4pve-api-dotnet
|
||||
|
||||
API Viewer: https://pve.proxmox.com/pve-docs/api-viewer/index.html
|
||||
|
||||
|
||||
***REMOVED***
|
||||
https://***REMOVED******REMOVED***/
|
||||
|
|
|
@ -6,5 +6,7 @@ namespace ProxmoxConnector.Integration.Abstractions
|
|||
{
|
||||
Task TestWithLogin();
|
||||
Task TestWithToken();
|
||||
Task Start();
|
||||
Task Stop();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,10 +10,11 @@ namespace ProxmoxConnector.Integration.Corsinvest.Services
|
|||
{
|
||||
public async Task TestWithLogin()
|
||||
{
|
||||
//var client = new PveClient("***REMOVED***"); ***REMOVED*** ***REMOVED***
|
||||
var client = new PveClient("***REMOVED***"); ***REMOVED***
|
||||
if (await client.Login(***REMOVED***))
|
||||
{
|
||||
var vm = client.Nodes["pve-test1"].Qemu[100];
|
||||
var vm = client.Nodes["pve-lora"].Qemu[100];
|
||||
|
||||
//config vm
|
||||
var config = await vm.Config.VmConfig();
|
||||
|
@ -50,5 +51,33 @@ namespace ProxmoxConnector.Integration.Corsinvest.Services
|
|||
var version = await client2.Version.Version();
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
using MediatR;
|
||||
using ProxmoxConnector.Integration.Abstractions;
|
||||
using ProxmoxConnector.Server.Application.Utils;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ProxmoxConnector.Integration.Abstractions;
|
||||
using ProxmoxConnector.Server.Application.Queries;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProxmoxConnector.Server.Controllers
|
||||
|
@ -12,10 +14,12 @@ namespace ProxmoxConnector.Server.Controllers
|
|||
public class ConnectorController : ControllerBase
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly IPveConnector _pveConnector;
|
||||
|
||||
public ConnectorController(IMediator mediator)
|
||||
public ConnectorController(IMediator mediator, IPveConnector pveConnector)
|
||||
{
|
||||
_mediator=mediator;
|
||||
_pveConnector=pveConnector;
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
|
@ -25,5 +29,22 @@ namespace ProxmoxConnector.Server.Controllers
|
|||
var result = await _mediator.Send(query);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue