Implemented multi allocation
This commit is contained in:
@@ -221,7 +221,10 @@ public class ServerService
|
|||||||
x.Add<ServerBackup>(serverBackup.Uuid);
|
x.Add<ServerBackup>(serverBackup.Uuid);
|
||||||
});
|
});
|
||||||
|
|
||||||
return $"https://{server.Node.Fqdn}:{server.Node.HttpPort}/download/backup?token={token}";
|
if (server.Node.Ssl)
|
||||||
|
return $"https://{server.Node.Fqdn}:{server.Node.HttpPort}/download/backup?token={token}";
|
||||||
|
else
|
||||||
|
return $"http://{server.Node.Fqdn}:{server.Node.HttpPort}/download/backup?token={token}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<FileAccess> CreateFileAccess(Server s, User user) // We need the user to create the launch url
|
public Task<FileAccess> CreateFileAccess(Server s, User user) // We need the user to create the launch url
|
||||||
@@ -240,7 +243,7 @@ public class ServerService
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Server> Create(string name, int cpu, long memory, long disk, User u, Image i, Node? n = null,
|
public async Task<Server> Create(string name, int cpu, long memory, long disk, User u, Image i, Node? n = null,
|
||||||
Action<Server>? modifyDetails = null)
|
Action<Server>? modifyDetails = null, int allocations = 1)
|
||||||
{
|
{
|
||||||
var user = UserRepository
|
var user = UserRepository
|
||||||
.Get()
|
.Get()
|
||||||
@@ -264,22 +267,27 @@ public class ServerService
|
|||||||
else
|
else
|
||||||
node = n;
|
node = n;
|
||||||
|
|
||||||
NodeAllocation freeAllo;
|
NodeAllocation[] freeAllocations;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
freeAllo = node.Allocations.First(a => !ServerRepository.Get()
|
freeAllocations = node.Allocations
|
||||||
.SelectMany(s => s.Allocations)
|
.Where(a => !ServerRepository.Get()
|
||||||
.Any(b => b.Id == a.Id)); // Thank you ChatGPT <3
|
.SelectMany(s => s.Allocations)
|
||||||
|
.Any(b => b.Id == a.Id))
|
||||||
|
.Take(allocations).ToArray();
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
throw new DisplayException("No allocation found");
|
throw new DisplayException("No allocation found");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (freeAllo == null)
|
if (!freeAllocations.Any())
|
||||||
throw new DisplayException("No allocation found");
|
throw new DisplayException("No allocation found");
|
||||||
|
|
||||||
|
if (freeAllocations.Length != allocations)
|
||||||
|
throw new DisplayException("Not enough allocations found");
|
||||||
|
|
||||||
var server = new Server()
|
var server = new Server()
|
||||||
{
|
{
|
||||||
Cpu = cpu,
|
Cpu = cpu,
|
||||||
@@ -290,11 +298,8 @@ public class ServerService
|
|||||||
Owner = user,
|
Owner = user,
|
||||||
Node = node,
|
Node = node,
|
||||||
Uuid = Guid.NewGuid(),
|
Uuid = Guid.NewGuid(),
|
||||||
MainAllocation = freeAllo,
|
MainAllocation = freeAllocations.First(),
|
||||||
Allocations = new()
|
Allocations = freeAllocations.ToList(),
|
||||||
{
|
|
||||||
freeAllo
|
|
||||||
},
|
|
||||||
Backups = new(),
|
Backups = new(),
|
||||||
OverrideStartup = "",
|
OverrideStartup = "",
|
||||||
DockerImageIndex = image.DockerImages.FindIndex(x => x.Default)
|
DockerImageIndex = image.DockerImages.FindIndex(x => x.Default)
|
||||||
@@ -322,10 +327,7 @@ public class ServerService
|
|||||||
StartOnCompletion = false
|
StartOnCompletion = false
|
||||||
});
|
});
|
||||||
|
|
||||||
await AuditLogService.Log(AuditLogType.CreateServer, x =>
|
await AuditLogService.Log(AuditLogType.CreateServer, x => { x.Add<Server>(newServerData.Uuid); });
|
||||||
{
|
|
||||||
x.Add<Server>(newServerData.Uuid);
|
|
||||||
});
|
|
||||||
|
|
||||||
return newServerData;
|
return newServerData;
|
||||||
}
|
}
|
||||||
@@ -349,10 +351,7 @@ public class ServerService
|
|||||||
|
|
||||||
await WingsApiHelper.Post(server.Node, $"api/servers/{server.Uuid}/reinstall", null);
|
await WingsApiHelper.Post(server.Node, $"api/servers/{server.Uuid}/reinstall", null);
|
||||||
|
|
||||||
await AuditLogService.Log(AuditLogType.ReinstallServer, x =>
|
await AuditLogService.Log(AuditLogType.ReinstallServer, x => { x.Add<Server>(server.Uuid); });
|
||||||
{
|
|
||||||
x.Add<Server>(server.Uuid);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Server> SftpServerLogin(int serverId, int id, string password)
|
public async Task<Server> SftpServerLogin(int serverId, int id, string password)
|
||||||
@@ -361,10 +360,7 @@ public class ServerService
|
|||||||
|
|
||||||
if (server == null)
|
if (server == null)
|
||||||
{
|
{
|
||||||
await SecurityLogService.LogSystem(SecurityLogType.SftpBruteForce, x =>
|
await SecurityLogService.LogSystem(SecurityLogType.SftpBruteForce, x => { x.Add<int>(id); });
|
||||||
{
|
|
||||||
x.Add<int>(id);
|
|
||||||
});
|
|
||||||
throw new Exception("Server not found");
|
throw new Exception("Server not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -209,7 +209,9 @@
|
|||||||
disk,
|
disk,
|
||||||
User,
|
User,
|
||||||
Model.Image,
|
Model.Image,
|
||||||
DeployNode
|
DeployNode,
|
||||||
|
null,
|
||||||
|
Model.Image.Allocations
|
||||||
);
|
);
|
||||||
|
|
||||||
NavigationManager.NavigateTo($"/server/{server.Uuid}");
|
NavigationManager.NavigateTo($"/server/{server.Uuid}");
|
||||||
|
|||||||
Reference in New Issue
Block a user