Class: Pvectl::Repositories::Subscription

Inherits:
Base
  • Object
show all
Defined in:
lib/pvectl/repositories/subscription.rb,
sig/pvectl/repositories/subscription.rbs

Overview

Repository for Proxmox subscription information per node.

Wraps the GET /nodes/{node}/subscription endpoint and aggregates subscription records across all nodes in the cluster.

Examples:

Listing subscriptions across the cluster

repo = Subscription.new(connection)
repo.list.each { |s| puts "#{s.node}: #{s.status} #{s.level}" }

See Also:

Instance Attribute Summary

Attributes inherited from Base

#connection

Instance Method Summary collapse

Methods inherited from Base

#extract_data, #initialize, #models_from, #unwrap

Constructor Details

This class inherits a constructor from Pvectl::Repositories::Base

Instance Method Details

#build_model(data, node_name) ⇒ Models::Subscription

Builds a Subscription model from API data plus the node name.

Parameters:

  • API response payload (already extracted from :data wrapper)

  • node the record belongs to

Returns:



45
46
47
48
# File 'lib/pvectl/repositories/subscription.rb', line 45

def build_model(data, node_name)
  attrs = (data || {}).merge(node: node_name)
  Models::Subscription.new(attrs)
end

#fetch_for(node_name) ⇒ Models::Subscription

Fetches one node's subscription, recovering from API errors gracefully.

Parameters:

Returns:



68
69
70
71
72
73
74
# File 'lib/pvectl/repositories/subscription.rb', line 68

def fetch_for(node_name)
  response = connection.client["nodes/#{node_name}/subscription"].get
  data = extract_data(response)
  build_model(data, node_name)
rescue StandardError => e
  build_model({ status: "unreachable", message: e.message }, node_name)
end

#get(node) ⇒ Models::Subscription

Fetches the subscription record for a single node.

Parameters:

  • node name

Returns:



34
35
36
# File 'lib/pvectl/repositories/subscription.rb', line 34

def get(node)
  fetch_for(node)
end

#list(node: nil) ⇒ Array<Models::Subscription>

Lists subscription records for cluster nodes.

Returns one Subscription per online node. Offline / unreachable nodes return a Subscription with status="unreachable" so the output remains stable instead of silently dropping rows.

Parameters:

  • (defaults to: nil)

    filter to a single node (otherwise all online nodes)

  • (defaults to: nil)

Returns:



25
26
27
28
# File 'lib/pvectl/repositories/subscription.rb', line 25

def list(node: nil)
  node_names = node ? [node] : online_node_names
  node_names.map { |name| fetch_for(name) }
end

#online_node_namesArray<String>

Returns names of all online nodes in the cluster.

Returns:



55
56
57
58
59
60
61
62
# File 'lib/pvectl/repositories/subscription.rb', line 55

def online_node_names
  response = connection.client["nodes"].get
  nodes = unwrap(response)
  nodes
    .select { |n| n[:status].nil? || n[:status] == "online" }
    .map { |n| n[:node] || n[:name] }
    .compact
end