Merge pull request #70 from Moonlight-Panel/FixServerDelete

Fixed server deletion and creation allocation bugs
This commit is contained in:
Marcel Baumgartner
2023-04-14 14:00:25 +02:00
committed by GitHub
2 changed files with 43 additions and 6 deletions

View File

@@ -138,8 +138,16 @@ public class ServersController : Controller
await MessageService.Emit($"wings.{node.Id}.serverfetch", server); await MessageService.Emit($"wings.{node.Id}.serverfetch", server);
try //TODO: Remove
{
return Converter.FromServer(server); return Converter.FromServer(server);
} }
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
[HttpGet("{uuid}/install")] [HttpGet("{uuid}/install")]
public async Task<ActionResult<WingsServerInstall>> GetServerInstall(Guid uuid) public async Task<ActionResult<WingsServerInstall>> GetServerInstall(Guid uuid)

View File

@@ -201,7 +201,8 @@ public class ServerService
{ {
x.Add<Server>(server.Uuid); x.Add<Server>(server.Uuid);
x.Add<ServerBackup>(backup.Uuid); x.Add<ServerBackup>(backup.Uuid);
}); }
);
} }
public async Task<string> DownloadBackup(Server s, ServerBackup serverBackup) public async Task<string> DownloadBackup(Server s, ServerBackup serverBackup)
@@ -262,10 +263,15 @@ public class ServerService
node = NodeRepository node = NodeRepository
.Get() .Get()
.Include(x => x.Allocations) .Include(x => x.Allocations)
.First(x => x.Id == n.Id); .First(); //TODO: Add smart deploy maybe
} }
else else
node = n; {
node = NodeRepository
.Get()
.Include(x => x.Allocations)
.First(x => x.Id == n.Id);
}
NodeAllocation[] freeAllocations; NodeAllocation[] freeAllocations;
@@ -339,7 +345,7 @@ public class ServerService
x.Add<Node>(node.Id); x.Add<Node>(node.Id);
}); });
ServerRepository.Delete(newServerData); ServerRepository.Delete(newServerData); //TODO Remove unsinged table stuff
throw new DisplayException("Error creating server on wings"); throw new DisplayException("Error creating server on wings");
} }
@@ -388,9 +394,32 @@ public class ServerService
{ {
var server = EnsureNodeData(s); var server = EnsureNodeData(s);
var backups = await GetBackups(server);
foreach (var backup in backups)
{
try
{
await DeleteBackup(server, backup);
}
catch (Exception)
{
// ignored
}
}
await WingsApiHelper.Delete(server.Node, $"api/servers/{server.Uuid}", null); await WingsApiHelper.Delete(server.Node, $"api/servers/{server.Uuid}", null);
ServerRepository.Delete(s); //TODO: Fix empty data models
server.Allocations = new();
server.MainAllocation = null;
server.Variables = new();
server.Backups = new();
ServerRepository.Update(server);
ServerRepository.Delete(server);
} }
public async Task<bool> IsHostUp(Server s) public async Task<bool> IsHostUp(Server s)