Skip to content

Commit fb1d474

Browse files
authored
Merge pull request #98 from franklupo/main
Fix snap size
2 parents b704087 + 521e903 commit fb1d474

File tree

23 files changed

+127
-76
lines changed

23 files changed

+127
-76
lines changed

Corsinvest.ProxmoxVE.Admin.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "cmd", "cmd", "{974C975A-9A4
5757
EndProject
5858
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Corsinvest.ProxmoxVE.Admin.ReplicationTrend", "src\Corsinvest.ProxmoxVE.Admin.ReplicationTrend\Corsinvest.ProxmoxVE.Admin.ReplicationTrend.csproj", "{24D3D8B6-5268-4890-815A-27C29C7D72D0}"
5959
EndProject
60+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docker", "Docker", "{37CEAF31-E743-4DE3-B81E-A8BDBC6C2B8A}"
61+
ProjectSection(SolutionItems) = preProject
62+
src\Docker\.dockerignore = src\Docker\.dockerignore
63+
src\Docker\Dockerfile = src\Docker\Dockerfile
64+
src\Docker\README.md = src\Docker\README.md
65+
EndProjectSection
66+
EndProject
6067
Global
6168
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6269
Debug|Any CPU = Debug|Any CPU

src/Corsinvest.ProxmoxVE.Admin.AutoSnap/Components/Status.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<AHPropertyColumn T="AutoSnapInfo" TProperty="string" Property="a => a.Label" Grouping="true">
3131
<GroupTemplate>
3232
<span style="font-weight:bold">
33-
@L["Label"]: @context.Grouping.Key (@context.Grouping.Count()) - Size: @FormatHelper.FromBytes(context.Grouping.Sum(a => a.Size))
33+
@L["Label"]: @context.Grouping.Key (@context.Grouping.Count()) - Size: @FormatHelper.FromBytes(context.Grouping.Sum(a => a.SnapshotsSize))
3434
</span>
3535
</GroupTemplate>
3636
</AHPropertyColumn>

src/Corsinvest.ProxmoxVE.Admin.AutoSnap/Components/Status.razor.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public partial class Status
2525
private readonly AggregateDefinition<AutoSnapInfo> SizeAggregation = new()
2626
{
2727
Type = AggregateType.Custom,
28-
CustomAggregate = x => $"Total: {FormatHelper.FromBytes(x.Sum(a => a.Size))}"
28+
CustomAggregate = x => $"Total: {FormatHelper.FromBytes(x.Sum(a => a.SnapshotsSize))}"
2929
};
3030

3131
protected override void OnInitialized()
@@ -55,17 +55,7 @@ protected override void OnInitialized()
5555
var data = await Helper.GetInfo(client, options, LoggerFactory, vmIdsOrNames);
5656

5757
//snapshot size
58-
var disks = await PveClientService.GetDisksInfo(client, (await PveClientService.GetCurrentClusterOptionsAsync())!);
59-
60-
foreach (var item in data)
61-
{
62-
item.Size = disks.Where(a => a.VmId == item.VmId)
63-
.SelectMany(a => a.Snapshots)
64-
.Where(a => a.Name == item.Name && !a.Replication)
65-
.Select(a => a.Size)
66-
.DefaultIfEmpty(0)
67-
.Sum();
68-
}
58+
await PveAdminHelper.MapSnapshotSize(client, PveClientService, data, false, true);
6959

7060
return data;
7161
};

src/Corsinvest.ProxmoxVE.Admin.AutoSnap/Models/AutoSnapInfo.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
* SPDX-FileCopyrightText: Copyright Corsinvest Srl
33
* SPDX-License-Identifier: AGPL-3.0-only
44
*/
5+
using Corsinvest.ProxmoxVE.Admin.Core.Models;
56
using Corsinvest.ProxmoxVE.Api.Shared.Models.Vm;
67
using Corsinvest.ProxmoxVE.Api.Shared.Utils;
78
using System.ComponentModel;
89

910
namespace Corsinvest.ProxmoxVE.Admin.AutoSnap.Models;
1011

11-
internal class AutoSnapInfo
12+
internal class AutoSnapInfo : INode, IVmId, ISnapshotsSize, IName
1213
{
1314
public string Node { get; set; } = default!;
1415
public long VmId { get; set; }
@@ -20,8 +21,11 @@ internal class AutoSnapInfo
2021
public string Label { get; set; } = default!;
2122
public string Description { get; set; } = default!;
2223
public bool VmStatus { get; set; }
23-
public double Size { get; set; }
24+
25+
[Display(Name = "Snapshots Size")]
26+
[DisplayFormat(DataFormatString = "{0:" + FormatHelper.FormatBytes + "}")]
27+
public double SnapshotsSize { get; set; }
2428

2529
[DisplayName("Size")]
26-
public string TextSize => FormatHelper.FromBytes(Size);
30+
public string TextSize => FormatHelper.FromBytes(SnapshotsSize);
2731
}

src/Corsinvest.ProxmoxVE.Admin.ClusterStatus/Components/RenderIndex.razor.cs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* SPDX-License-Identifier: AGPL-3.0-only
44
*/
55
using Corsinvest.AppHero.Core.Domain.Contracts;
6+
using Corsinvest.ProxmoxVE.Admin.Core.Helpers;
67
using Corsinvest.ProxmoxVE.Admin.Core.Models;
78
using Corsinvest.ProxmoxVE.Admin.Core.Services.DiskInfo;
89
using Corsinvest.ProxmoxVE.Admin.Core.UI.ProxmoxVE.Cluster;
@@ -93,22 +94,8 @@ private async Task<IEnumerable<ClusterResourceVmExtraInfo>> GetResources()
9394

9495
if (ClusterOptions.CalculateSnapshotSize)
9596
{
96-
Disks = (await PveClientService.GetDisksInfo(PveClient, ClusterOptions))
97-
.OrderBy(a => a.Type)
98-
.ThenBy(a => a.Host)
99-
.ThenBy(a => a.SpaceName)
100-
.ToList();
101-
102-
foreach (var item in data)
103-
{
104-
item.SnapshotsSize = Disks.Where(a => a.VmId == item.VmId)
105-
.SelectMany(a => a.Snapshots)
106-
.Where(a => !a.Replication)
107-
.Select(a => a.Size)
108-
.DefaultIfEmpty(0)
109-
.Sum();
110-
}
111-
97+
//snapshot size
98+
Disks = await PveAdminHelper.MapSnapshotSize(PveClient, PveClientService, data, false, false);
11299
StateHasChanged();
113100
}
114101

src/Corsinvest.ProxmoxVE.Admin.Core/Corsinvest.ProxmoxVE.Admin.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<PackageReference Include="Blazored.SessionStorage" Version="2.4.0" />
1515
<PackageReference Include="Corsinvest.ProxmoxVE.Api.Extension" Version="8.1.4" />
1616
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.3" />
17-
<PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="8.102.2" />
17+
<PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="8.102.2.1" />
1818
<PackageReference Include="SSH.NET" Version="2024.0.0" />
1919
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.3" />
2020
</ItemGroup>

src/Corsinvest.ProxmoxVE.Admin.Core/Helpers/PveAdminHelper.cs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* SPDX-License-Identifier: AGPL-3.0-only
44
*/
55
using Corsinvest.AppHero.Core.Modularity;
6+
using Corsinvest.ProxmoxVE.Admin.Core.Models;
67
using Corsinvest.ProxmoxVE.Admin.Core.Modularity;
78
using Corsinvest.ProxmoxVE.Api;
89
using Corsinvest.ProxmoxVE.Api.Shared.Models.Cluster;
@@ -101,12 +102,41 @@ public static async Task<string> GetSupportInfo(PveClient client)
101102
if (!string.IsNullOrEmpty(subscription.Key))
102103
{
103104
var data = subscription.Key.Split("-");
104-
level = NodeHelper.DecodeLevelSupport(data[0][^1]+"").ToString();
105-
}
105+
level = NodeHelper.DecodeLevelSupport(data[0][^1] + "").ToString();
106+
}
106107

107108
rows.Add($"{item.Node}: {subscription.Serverid} {level}");
108109
}
109110

110111
return rows.JoinAsString(Environment.NewLine);
111112
}
113+
114+
public static async Task<IEnumerable<Services.DiskInfo.DiskInfoBase>> MapSnapshotSize<T>(PveClient client,
115+
IPveClientService pveClientService,
116+
IEnumerable<T> items,
117+
bool includeReplication,
118+
bool filterByName)
119+
where T : ISnapshotsSize, INode, IVmId
120+
{
121+
//snapshot size
122+
var disks = await pveClientService.GetDisksInfo(client, (await pveClientService.GetCurrentClusterOptionsAsync())!);
123+
124+
foreach (var item in items)
125+
{
126+
var aa = disks.Where(a => a.VmId == item.VmId
127+
&& (!a.HostContainSnapshot || a.Host == item.Node))
128+
.ToArray();
129+
130+
item.SnapshotsSize = disks.Where(a => a.VmId == item.VmId
131+
&& (!a.HostContainSnapshot || a.Host == item.Node))
132+
.SelectMany(a => a.Snapshots)
133+
.Where(a => !a.Replication, !includeReplication)
134+
.Where(a => a.Name == ((IName)item).Name, filterByName)
135+
.Select(a => a.Size)
136+
.DefaultIfEmpty(0)
137+
.Sum();
138+
}
139+
140+
return disks;
141+
}
112142
}

src/Corsinvest.ProxmoxVE.Admin.Core/Models/ClusterResourceVmExtraInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Corsinvest.ProxmoxVE.Admin.Core.Models;
1010

11-
public class ClusterResourceVmExtraInfo : ClusterResource, IClusterResourceVmOsInfo
11+
public class ClusterResourceVmExtraInfo : ClusterResource, IClusterResourceVmOsInfo, INode, IVmId, ISnapshotsSize
1212
{
1313
[Display(Name = "Snapshots Size")]
1414
[DisplayFormat(DataFormatString = "{0:" + FormatHelper.FormatBytes + "}")]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright Corsinvest Srl
3+
* SPDX-License-Identifier: AGPL-3.0-only
4+
*/
5+
namespace Corsinvest.ProxmoxVE.Admin.Core.Models;
6+
7+
public interface IName
8+
{
9+
string Name { get; set; }
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright Corsinvest Srl
3+
* SPDX-License-Identifier: AGPL-3.0-only
4+
*/
5+
using Markdig.Helpers;
6+
7+
namespace Corsinvest.ProxmoxVE.Admin.Core.Models;
8+
9+
public interface INode
10+
{
11+
string Node { get; set; }
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright Corsinvest Srl
3+
* SPDX-License-Identifier: AGPL-3.0-only
4+
*/
5+
using Corsinvest.ProxmoxVE.Api.Shared.Utils;
6+
7+
namespace Corsinvest.ProxmoxVE.Admin.Core.Models;
8+
9+
public interface ISnapshotsSize
10+
{
11+
[Display(Name = "Snapshots Size")]
12+
[DisplayFormat(DataFormatString = "{0:" + FormatHelper.FormatBytes + "}")]
13+
double SnapshotsSize { get; set; }
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright Corsinvest Srl
3+
* SPDX-License-Identifier: AGPL-3.0-only
4+
*/
5+
namespace Corsinvest.ProxmoxVE.Admin.Core.Models;
6+
7+
public interface IVmId
8+
{
9+
long VmId { get; set; }
10+
}

src/Corsinvest.ProxmoxVE.Admin.Core/Options/ClusterOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ClusterOptions
2020
[Display(Name = "Timeout (millisec)")]
2121
public int Timeout { get; set; } = 1000;
2222

23-
[Display(Name = "Calculate snapshot size (require time)")]
23+
[Display(Name = "Calculate snapshot size (require ssh configuration)")]
2424
public bool CalculateSnapshotSize { get; set; }
2525

2626
public bool UseApiToken { get; set; }

src/Corsinvest.ProxmoxVE.Admin.Core/Services/DiskInfo/CephDiskInfo.cs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,12 @@
88

99
namespace Corsinvest.ProxmoxVE.Admin.Core.Services.DiskInfo;
1010

11-
public class CephDiskInfo : DiskInfoBase
11+
public class CephDiskInfo(string storage, string pool, long vmId, string disk, string monitorHosts)
12+
: DiskInfoBase(vmId, disk, monitorHosts, pool, false)
1213
{
13-
public CephDiskInfo(string storage, string pool, long vmId, string disk, string monitorHosts)
14-
: base(vmId, disk, monitorHosts, pool)
15-
{
16-
Storage = storage;
17-
Pool = pool;
18-
MonitorHosts = monitorHosts;
19-
}
20-
21-
public string Storage { get; }
22-
public string Pool { get; }
23-
public string MonitorHosts { get; }
14+
public string Storage { get; } = storage;
15+
public string Pool { get; } = pool;
16+
public string MonitorHosts { get; } = monitorHosts;
2417
public override string Type => "Ceph";
2518

2619
class ImageSnapshot

src/Corsinvest.ProxmoxVE.Admin.Core/Services/DiskInfo/DiskInfoBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
*/
55
namespace Corsinvest.ProxmoxVE.Admin.Core.Services.DiskInfo;
66

7-
public abstract class DiskInfoBase(long vmId, string disk, string host, string spaceName)
7+
public abstract class DiskInfoBase(long vmId, string disk, string host, string spaceName,bool hostContainSnapshot)
88
{
99
public long VmId { get; } = vmId;
1010
public string Disk { get; } = disk;
1111
public string Host { get; } = host;
12+
public bool HostContainSnapshot { get; }= hostContainSnapshot;
1213
public string SpaceName { get; } = spaceName;
1314
public abstract string Type { get; }
1415

src/Corsinvest.ProxmoxVE.Admin.Core/Services/DiskInfo/ZfsDiskInfo.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,11 @@
99

1010
namespace Corsinvest.ProxmoxVE.Admin.Core.Services.DiskInfo;
1111

12-
public class ZfsDiskInfo : DiskInfoBase
12+
public class ZfsDiskInfo(string ipAddress, string path, long vmId, string disk, string host, string spaceName)
13+
: DiskInfoBase(vmId, disk, host, spaceName, true)
1314
{
14-
public ZfsDiskInfo(string ipAddress, string path, long vmId, string disk, string host, string spaceName) :
15-
base(vmId, disk, host, spaceName)
16-
{
17-
IpAddress = ipAddress;
18-
Path = path;
19-
}
20-
21-
public string IpAddress { get; }
22-
public string Path { get; }
15+
public string IpAddress { get; } = ipAddress;
16+
public string Path { get; } = path;
2317
public override string Type => "ZFS";
2418

2519
public static async Task<IEnumerable<ZfsDiskInfo>> Read(PveClient client, ClusterOptions clusterOptions)
@@ -60,7 +54,7 @@ public static async Task<IEnumerable<ZfsDiskInfo>> Read(PveClient client, Cluste
6054
fullPath[0],
6155
long.Parse(diskVm.Split('-')[1]),
6256
diskVm,
63-
ipAddress,
57+
host,
6458
spaceName);
6559

6660
//check if exists

src/Corsinvest.ProxmoxVE.Admin.Core/Services/PveClientService.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,4 @@ public async Task<IEnumerable<DiskInfoBase>> GetDisksInfo(PveClient client, Clus
196196

197197
return ret;
198198
}
199-
200-
201199
}

src/Corsinvest.ProxmoxVE.Admin.Core/UI/Layout/SelectCluster.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private async Task ValueChanged(string value)
5555
{
5656
await PveClientService.SetCurrentClusterNameAsync(value);
5757
CurrentClusterName = value;
58-
if (_refresh) { NavigationManager.NavigateTo(NavigationManager.Uri, true); }
58+
if (_refresh) { NavigationManager.Refresh(true); }
5959
}
6060
else
6161
{

src/Corsinvest.ProxmoxVE.Admin.Core/UI/ProxmoxVE/Cluster/Snapshots.razor

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* SPDX-FileCopyrightText: Copyright Corsinvest Srl
33
* SPDX-License-Identifier: AGPL-3.0-only
44
*@
5+
@using Corsinvest.AppHero.Core.MudBlazorUI.Style
56
@using Corsinvest.ProxmoxVE.Admin.Core.Services.DiskInfo
67

78
@inherits AHComponentBase
@@ -25,14 +26,14 @@
2526
{
2627
[Parameter] public IEnumerable<DiskInfoBase> Disks { get; set; } = [];
2728

28-
[Inject] public Corsinvest.AppHero.Core.MudBlazorUI.Style.UIOptions UIOptions { get; set; } = default!;
29+
[Inject] public IOptionsSnapshot<UIOptions> UIOptions { get; set; } = default!;
2930

3031
private RenderFragment RenderTable(bool replication) => __builder =>
3132
{
3233
@if (replication)
3334
{
3435
<MudText>
35-
<div class="d-flex">
36+
<div class="d-flex gap-3">
3637
<MudIcon Icon="@PveBlazorHelper.Icons.Replication" />
3738
Replication
3839
</div>
@@ -49,10 +50,10 @@
4950
}
5051

5152
<MudSimpleTable Style="overflow-x: auto;"
52-
Bordered="@UIOptions.Theme.Table.IsBordered"
53-
Striped="@UIOptions.Theme.Table.IsStriped"
54-
Hover="@UIOptions.Theme.Table.IsHoverable"
55-
Dense="@UIOptions.Theme.Table.IsDense">
53+
Bordered="@UIOptions.Value.Theme.Table.IsBordered"
54+
Striped="@UIOptions.Value.Theme.Table.IsStriped"
55+
Hover="@UIOptions.Value.Theme.Table.IsHoverable"
56+
Dense="@UIOptions.Value.Theme.Table.IsDense">
5657
<thead>
5758
<tr>
5859
<th>Type</th>

src/Corsinvest.ProxmoxVE.Admin/wwwroot/doc/index.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Powered by Corsinvest Srl
1111
:icons: font
1212
:pve-name: Proxmox VE
1313
:app-name: cv4pve-admin
14-
:app-version: v1.0.1
14+
:app-version: v1.1.0
1515
:app-url-site: https://www.corsinvest.it/cv4pve-admin
1616
:company-url: https://www.corsinvest.it
1717
:company-name: Corsinvest Srl

0 commit comments

Comments
 (0)