Merge pull request #77 from Moonlight-Panel/FixServerCreateAllocations

Fixed my stupid mistakes
This commit is contained in:
Marcel Baumgartner 2023-04-16 16:03:24 +02:00 committed by GitHub
commit c2a7b42a90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 5 deletions

View file

@ -259,7 +259,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, int allocations = 1) Action<Server>? modifyDetails = null)
{ {
var user = UserRepository var user = UserRepository
.Get() .Get()
@ -271,6 +271,8 @@ public class ServerService
.Include(x => x.DockerImages) .Include(x => x.DockerImages)
.First(x => x.Id == i.Id); .First(x => x.Id == i.Id);
var allocations = image.Allocations;
Node node = n ?? NodeRepository.Get().First(); Node node = n ?? NodeRepository.Get().First();
NodeAllocation[] freeAllocations; NodeAllocation[] freeAllocations;

View file

@ -109,6 +109,25 @@
OnClick="CreateAllocation"> OnClick="CreateAllocation">
</WButton> </WButton>
</div> </div>
<div class="col-auto">
<label class="form-label">
<TL>Start</TL>
</label>
<input @bind="StartPort" type="number" class="col-auto form-control bg-transparent">
</div>
<div class="col-auto">
<label class="form-label">
<TL>End</TL>
</label>
<input @bind="EndPort" type="number" class="col-auto form-control bg-transparent">
</div>
<div class="col-auto">
<WButton Text="@(SmartTranslateService.Translate("Add"))"
WorkingText="@(SmartTranslateService.Translate("Adding"))"
CssClasses="col-auto btn-success"
OnClick="CreateAllocationRange">
</WButton>
</div>
</div> </div>
</div> </div>
<Table TableItem="NodeAllocation" Items="Node.Allocations" PageSize="25" TableHeadClass="border-bottom border-gray-200 fs-6 text-gray-600 fw-bold bg-light bg-opacity-75"> <Table TableItem="NodeAllocation" Items="Node.Allocations" PageSize="25" TableHeadClass="border-bottom border-gray-200 fs-6 text-gray-600 fw-bold bg-light bg-opacity-75">
@ -142,6 +161,9 @@
private int Port = 2000; private int Port = 2000;
private int StartPort = 2000;
private int EndPort = 3000;
private Task Load(LazyLoader arg) private Task Load(LazyLoader arg)
{ {
Node = NodeRepository Node = NodeRepository
@ -183,4 +205,24 @@
await LazyLoader.Reload(); await LazyLoader.Reload();
} }
private async Task CreateAllocationRange()
{
for (int i = StartPort; i < EndPort; i++)
{
var nodeAllocation = new NodeAllocation()
{
Port = i
};
Node!.Allocations.Add(nodeAllocation);
}
NodeRepository.Update(Node);
StartPort = 2000;
EndPort = 3000;
await LazyLoader.Reload();
}
} }

View file

@ -209,10 +209,8 @@
disk, disk,
User, User,
Model.Image, Model.Image,
DeployNode, DeployNode
null, );
Model.Image.Allocations
);
NavigationManager.NavigateTo($"/server/{server.Uuid}"); NavigationManager.NavigateTo($"/server/{server.Uuid}");
} }