mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-12-01 01:52:30 +01:00
Replace the rejected global host-network proposal with the unchanged private namespace on every platform, including native linux-386. Carry successful rows and omitted VMIDs through operation v2 without clearing degraded health or renewing omitted measurements; retain strict complete-only v1 compatibility. Restart the installer-owned helper only after isolated-unit and socket checks, and document the unresolved pmxcfs IPC limitation rather than claiming PVE recovery. Change-source: pulse-maintainer
89 lines
3.3 KiB
Go
89 lines
3.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/agenthelper"
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/hostagent"
|
|
agentshost "github.com/rcourtman/pulse-go-rewrite/pkg/agents/host"
|
|
)
|
|
|
|
// localSMARTProvider reuses the canonical SMART collector inside the
|
|
// network-isolated helper process. Its protocol request has no path or
|
|
// argument fields; device discovery and command construction remain entirely
|
|
// provider-owned.
|
|
type localSMARTProvider struct{}
|
|
|
|
func (localSMARTProvider) Snapshot(ctx context.Context) (json.RawMessage, error) {
|
|
disks, err := hostagent.CollectSMARTLocal(ctx, nil)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("collect SMART snapshot: %w", err)
|
|
}
|
|
result, err := json.Marshal(struct {
|
|
Disks []hostagent.DiskSMART `json:"disks"`
|
|
}{Disks: disks})
|
|
if err != nil {
|
|
return nil, fmt.Errorf("encode SMART snapshot: %w", err)
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
// localProxmoxProvider runs the existing bounded node-local inventory as one
|
|
// typed operation. The collector cannot select a VMID, filesystem path,
|
|
// command, or pct argument across the helper boundary.
|
|
type localProxmoxProvider struct {
|
|
collect func(context.Context) hostagent.ProxmoxLXCFilesystemCollectionResult
|
|
}
|
|
|
|
func (p localProxmoxProvider) LXCFilesystems(ctx context.Context) (json.RawMessage, error) {
|
|
return p.lxcFilesystems(ctx, false)
|
|
}
|
|
|
|
func (p localProxmoxProvider) LXCFilesystemsV2(ctx context.Context) (json.RawMessage, error) {
|
|
return p.lxcFilesystems(ctx, true)
|
|
}
|
|
|
|
func (p localProxmoxProvider) lxcFilesystems(ctx context.Context, allowPartial bool) (json.RawMessage, error) {
|
|
collect := p.collect
|
|
if collect == nil {
|
|
collect = hostagent.CollectProxmoxLXCFilesystemsLocalResult
|
|
}
|
|
collection := collect(ctx)
|
|
if collection.Degraded && (!allowPartial || collection.Inventory == nil) {
|
|
return nil, &agenthelper.ProviderError{
|
|
Code: agenthelper.ErrorProviderUnavailable,
|
|
Message: "Proxmox LXC filesystem inventory is incomplete",
|
|
Retryable: true,
|
|
}
|
|
}
|
|
if collection.Inventory != nil {
|
|
if err := collection.Inventory.ValidateCollection(); err != nil ||
|
|
(allowPartial && collection.Inventory.Status == "") ||
|
|
(collection.Degraded != (collection.Inventory.Status == agentshost.ProxmoxLXCCollectionPartial)) ||
|
|
collection.FailedContainers != len(collection.Inventory.OmittedVMIDs) {
|
|
return nil, &agenthelper.ProviderError{Code: agenthelper.ErrorProviderUnavailable, Message: "Proxmox LXC filesystem inventory has invalid completeness", Retryable: true}
|
|
}
|
|
}
|
|
// V1 decoders are strict: do not add even complete-status fields to their
|
|
// response. A partial result never reaches an older collector as healthy.
|
|
if !allowPartial && collection.Inventory != nil {
|
|
legacy := struct {
|
|
Containers []agentshost.ProxmoxLXCContainer `json:"containers"`
|
|
CollectedAt time.Time `json:"collectedAt"`
|
|
}{collection.Inventory.Containers, collection.Inventory.CollectedAt}
|
|
return json.Marshal(struct {
|
|
Inventory any `json:"inventory"`
|
|
}{legacy})
|
|
}
|
|
result, err := json.Marshal(struct {
|
|
Inventory *agentshost.ProxmoxLXCInventory `json:"inventory"`
|
|
}{Inventory: collection.Inventory})
|
|
if err != nil {
|
|
return nil, fmt.Errorf("encode Proxmox LXC filesystem inventory: %w", err)
|
|
}
|
|
return result, nil
|
|
}
|