Skip to content

Commit

Permalink
Merge pull request #98 from franklupo/main
Browse files Browse the repository at this point in the history
Fix snap size
  • Loading branch information
franklupo authored Mar 27, 2024
2 parents b704087 + 521e903 commit fb1d474
Show file tree
Hide file tree
Showing 23 changed files with 127 additions and 76 deletions.
7 changes: 7 additions & 0 deletions Corsinvest.ProxmoxVE.Admin.sln
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "cmd", "cmd", "{974C975A-9A4
EndProject
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}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docker", "Docker", "{37CEAF31-E743-4DE3-B81E-A8BDBC6C2B8A}"
ProjectSection(SolutionItems) = preProject
src\Docker\.dockerignore = src\Docker\.dockerignore
src\Docker\Dockerfile = src\Docker\Dockerfile
src\Docker\README.md = src\Docker\README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<AHPropertyColumn T="AutoSnapInfo" TProperty="string" Property="a => a.Label" Grouping="true">
<GroupTemplate>
<span style="font-weight:bold">
@L["Label"]: @context.Grouping.Key (@context.Grouping.Count()) - Size: @FormatHelper.FromBytes(context.Grouping.Sum(a => a.Size))
@L["Label"]: @context.Grouping.Key (@context.Grouping.Count()) - Size: @FormatHelper.FromBytes(context.Grouping.Sum(a => a.SnapshotsSize))
</span>
</GroupTemplate>
</AHPropertyColumn>
Expand Down
14 changes: 2 additions & 12 deletions src/Corsinvest.ProxmoxVE.Admin.AutoSnap/Components/Status.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public partial class Status
private readonly AggregateDefinition<AutoSnapInfo> SizeAggregation = new()
{
Type = AggregateType.Custom,
CustomAggregate = x => $"Total: {FormatHelper.FromBytes(x.Sum(a => a.Size))}"
CustomAggregate = x => $"Total: {FormatHelper.FromBytes(x.Sum(a => a.SnapshotsSize))}"
};

protected override void OnInitialized()
Expand Down Expand Up @@ -55,17 +55,7 @@ protected override void OnInitialized()
var data = await Helper.GetInfo(client, options, LoggerFactory, vmIdsOrNames);
//snapshot size
var disks = await PveClientService.GetDisksInfo(client, (await PveClientService.GetCurrentClusterOptionsAsync())!);
foreach (var item in data)
{
item.Size = disks.Where(a => a.VmId == item.VmId)
.SelectMany(a => a.Snapshots)
.Where(a => a.Name == item.Name && !a.Replication)
.Select(a => a.Size)
.DefaultIfEmpty(0)
.Sum();
}
await PveAdminHelper.MapSnapshotSize(client, PveClientService, data, false, true);
return data;
};
Expand Down
10 changes: 7 additions & 3 deletions src/Corsinvest.ProxmoxVE.Admin.AutoSnap/Models/AutoSnapInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
* SPDX-FileCopyrightText: Copyright Corsinvest Srl
* SPDX-License-Identifier: AGPL-3.0-only
*/
using Corsinvest.ProxmoxVE.Admin.Core.Models;
using Corsinvest.ProxmoxVE.Api.Shared.Models.Vm;
using Corsinvest.ProxmoxVE.Api.Shared.Utils;
using System.ComponentModel;

namespace Corsinvest.ProxmoxVE.Admin.AutoSnap.Models;

internal class AutoSnapInfo
internal class AutoSnapInfo : INode, IVmId, ISnapshotsSize, IName
{
public string Node { get; set; } = default!;
public long VmId { get; set; }
Expand All @@ -20,8 +21,11 @@ internal class AutoSnapInfo
public string Label { get; set; } = default!;
public string Description { get; set; } = default!;
public bool VmStatus { get; set; }
public double Size { get; set; }

[Display(Name = "Snapshots Size")]
[DisplayFormat(DataFormatString = "{0:" + FormatHelper.FormatBytes + "}")]
public double SnapshotsSize { get; set; }

[DisplayName("Size")]
public string TextSize => FormatHelper.FromBytes(Size);
public string TextSize => FormatHelper.FromBytes(SnapshotsSize);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
using Corsinvest.AppHero.Core.Domain.Contracts;
using Corsinvest.ProxmoxVE.Admin.Core.Helpers;
using Corsinvest.ProxmoxVE.Admin.Core.Models;
using Corsinvest.ProxmoxVE.Admin.Core.Services.DiskInfo;
using Corsinvest.ProxmoxVE.Admin.Core.UI.ProxmoxVE.Cluster;
Expand Down Expand Up @@ -93,22 +94,8 @@ private async Task<IEnumerable<ClusterResourceVmExtraInfo>> GetResources()

if (ClusterOptions.CalculateSnapshotSize)
{
Disks = (await PveClientService.GetDisksInfo(PveClient, ClusterOptions))
.OrderBy(a => a.Type)
.ThenBy(a => a.Host)
.ThenBy(a => a.SpaceName)
.ToList();

foreach (var item in data)
{
item.SnapshotsSize = Disks.Where(a => a.VmId == item.VmId)
.SelectMany(a => a.Snapshots)
.Where(a => !a.Replication)
.Select(a => a.Size)
.DefaultIfEmpty(0)
.Sum();
}

//snapshot size
Disks = await PveAdminHelper.MapSnapshotSize(PveClient, PveClientService, data, false, false);
StateHasChanged();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="Blazored.SessionStorage" Version="2.4.0" />
<PackageReference Include="Corsinvest.ProxmoxVE.Api.Extension" Version="8.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.3" />
<PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="8.102.2" />
<PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="8.102.2.1" />
<PackageReference Include="SSH.NET" Version="2024.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.3" />
</ItemGroup>
Expand Down
34 changes: 32 additions & 2 deletions src/Corsinvest.ProxmoxVE.Admin.Core/Helpers/PveAdminHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
using Corsinvest.AppHero.Core.Modularity;
using Corsinvest.ProxmoxVE.Admin.Core.Models;
using Corsinvest.ProxmoxVE.Admin.Core.Modularity;
using Corsinvest.ProxmoxVE.Api;
using Corsinvest.ProxmoxVE.Api.Shared.Models.Cluster;
Expand Down Expand Up @@ -101,12 +102,41 @@ public static async Task<string> GetSupportInfo(PveClient client)
if (!string.IsNullOrEmpty(subscription.Key))
{
var data = subscription.Key.Split("-");
level = NodeHelper.DecodeLevelSupport(data[0][^1]+"").ToString();
}
level = NodeHelper.DecodeLevelSupport(data[0][^1] + "").ToString();
}

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

return rows.JoinAsString(Environment.NewLine);
}

public static async Task<IEnumerable<Services.DiskInfo.DiskInfoBase>> MapSnapshotSize<T>(PveClient client,
IPveClientService pveClientService,
IEnumerable<T> items,
bool includeReplication,
bool filterByName)
where T : ISnapshotsSize, INode, IVmId
{
//snapshot size
var disks = await pveClientService.GetDisksInfo(client, (await pveClientService.GetCurrentClusterOptionsAsync())!);

foreach (var item in items)
{
var aa = disks.Where(a => a.VmId == item.VmId
&& (!a.HostContainSnapshot || a.Host == item.Node))
.ToArray();

item.SnapshotsSize = disks.Where(a => a.VmId == item.VmId
&& (!a.HostContainSnapshot || a.Host == item.Node))
.SelectMany(a => a.Snapshots)
.Where(a => !a.Replication, !includeReplication)
.Where(a => a.Name == ((IName)item).Name, filterByName)
.Select(a => a.Size)
.DefaultIfEmpty(0)
.Sum();
}

return disks;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Corsinvest.ProxmoxVE.Admin.Core.Models;

public class ClusterResourceVmExtraInfo : ClusterResource, IClusterResourceVmOsInfo
public class ClusterResourceVmExtraInfo : ClusterResource, IClusterResourceVmOsInfo, INode, IVmId, ISnapshotsSize
{
[Display(Name = "Snapshots Size")]
[DisplayFormat(DataFormatString = "{0:" + FormatHelper.FormatBytes + "}")]
Expand Down
10 changes: 10 additions & 0 deletions src/Corsinvest.ProxmoxVE.Admin.Core/Models/IName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-FileCopyrightText: Copyright Corsinvest Srl
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Corsinvest.ProxmoxVE.Admin.Core.Models;

public interface IName
{
string Name { get; set; }
}
12 changes: 12 additions & 0 deletions src/Corsinvest.ProxmoxVE.Admin.Core/Models/INode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* SPDX-FileCopyrightText: Copyright Corsinvest Srl
* SPDX-License-Identifier: AGPL-3.0-only
*/
using Markdig.Helpers;

namespace Corsinvest.ProxmoxVE.Admin.Core.Models;

public interface INode
{
string Node { get; set; }
}
14 changes: 14 additions & 0 deletions src/Corsinvest.ProxmoxVE.Admin.Core/Models/ISnapshotsSize.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* SPDX-FileCopyrightText: Copyright Corsinvest Srl
* SPDX-License-Identifier: AGPL-3.0-only
*/
using Corsinvest.ProxmoxVE.Api.Shared.Utils;

namespace Corsinvest.ProxmoxVE.Admin.Core.Models;

public interface ISnapshotsSize
{
[Display(Name = "Snapshots Size")]
[DisplayFormat(DataFormatString = "{0:" + FormatHelper.FormatBytes + "}")]
double SnapshotsSize { get; set; }
}
10 changes: 10 additions & 0 deletions src/Corsinvest.ProxmoxVE.Admin.Core/Models/IVmId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* SPDX-FileCopyrightText: Copyright Corsinvest Srl
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Corsinvest.ProxmoxVE.Admin.Core.Models;

public interface IVmId
{
long VmId { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ClusterOptions
[Display(Name = "Timeout (millisec)")]
public int Timeout { get; set; } = 1000;

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

public bool UseApiToken { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,12 @@

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

public class CephDiskInfo : DiskInfoBase
public class CephDiskInfo(string storage, string pool, long vmId, string disk, string monitorHosts)
: DiskInfoBase(vmId, disk, monitorHosts, pool, false)
{
public CephDiskInfo(string storage, string pool, long vmId, string disk, string monitorHosts)
: base(vmId, disk, monitorHosts, pool)
{
Storage = storage;
Pool = pool;
MonitorHosts = monitorHosts;
}

public string Storage { get; }
public string Pool { get; }
public string MonitorHosts { get; }
public string Storage { get; } = storage;
public string Pool { get; } = pool;
public string MonitorHosts { get; } = monitorHosts;
public override string Type => "Ceph";

class ImageSnapshot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
*/
namespace Corsinvest.ProxmoxVE.Admin.Core.Services.DiskInfo;

public abstract class DiskInfoBase(long vmId, string disk, string host, string spaceName)
public abstract class DiskInfoBase(long vmId, string disk, string host, string spaceName,bool hostContainSnapshot)
{
public long VmId { get; } = vmId;
public string Disk { get; } = disk;
public string Host { get; } = host;
public bool HostContainSnapshot { get; }= hostContainSnapshot;
public string SpaceName { get; } = spaceName;
public abstract string Type { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@

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

public class ZfsDiskInfo : DiskInfoBase
public class ZfsDiskInfo(string ipAddress, string path, long vmId, string disk, string host, string spaceName)
: DiskInfoBase(vmId, disk, host, spaceName, true)
{
public ZfsDiskInfo(string ipAddress, string path, long vmId, string disk, string host, string spaceName) :
base(vmId, disk, host, spaceName)
{
IpAddress = ipAddress;
Path = path;
}

public string IpAddress { get; }
public string Path { get; }
public string IpAddress { get; } = ipAddress;
public string Path { get; } = path;
public override string Type => "ZFS";

public static async Task<IEnumerable<ZfsDiskInfo>> Read(PveClient client, ClusterOptions clusterOptions)
Expand Down Expand Up @@ -60,7 +54,7 @@ public static async Task<IEnumerable<ZfsDiskInfo>> Read(PveClient client, Cluste
fullPath[0],
long.Parse(diskVm.Split('-')[1]),
diskVm,
ipAddress,
host,
spaceName);

//check if exists
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,4 @@ public async Task<IEnumerable<DiskInfoBase>> GetDisksInfo(PveClient client, Clus

return ret;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private async Task ValueChanged(string value)
{
await PveClientService.SetCurrentClusterNameAsync(value);
CurrentClusterName = value;
if (_refresh) { NavigationManager.NavigateTo(NavigationManager.Uri, true); }
if (_refresh) { NavigationManager.Refresh(true); }
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* SPDX-FileCopyrightText: Copyright Corsinvest Srl
* SPDX-License-Identifier: AGPL-3.0-only
*@
@using Corsinvest.AppHero.Core.MudBlazorUI.Style
@using Corsinvest.ProxmoxVE.Admin.Core.Services.DiskInfo

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

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

private RenderFragment RenderTable(bool replication) => __builder =>
{
@if (replication)
{
<MudText>
<div class="d-flex">
<div class="d-flex gap-3">
<MudIcon Icon="@PveBlazorHelper.Icons.Replication" />
Replication
</div>
Expand All @@ -49,10 +50,10 @@
}

<MudSimpleTable Style="overflow-x: auto;"
Bordered="@UIOptions.Theme.Table.IsBordered"
Striped="@UIOptions.Theme.Table.IsStriped"
Hover="@UIOptions.Theme.Table.IsHoverable"
Dense="@UIOptions.Theme.Table.IsDense">
Bordered="@UIOptions.Value.Theme.Table.IsBordered"
Striped="@UIOptions.Value.Theme.Table.IsStriped"
Hover="@UIOptions.Value.Theme.Table.IsHoverable"
Dense="@UIOptions.Value.Theme.Table.IsDense">
<thead>
<tr>
<th>Type</th>
Expand Down
2 changes: 1 addition & 1 deletion src/Corsinvest.ProxmoxVE.Admin/wwwroot/doc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Powered by Corsinvest Srl
:icons: font
:pve-name: Proxmox VE
:app-name: cv4pve-admin
:app-version: v1.0.1
:app-version: v1.1.0
:app-url-site: https://www.corsinvest.it/cv4pve-admin
:company-url: https://www.corsinvest.it
:company-name: Corsinvest Srl
Expand Down
Loading

0 comments on commit fb1d474

Please sign in to comment.