Class: Pvectl::Repositories::TimeConfig

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

Overview

Repository for Proxmox node time and timezone settings.

Wraps the /nodes/{node}/time API endpoint:

  • GET fetches {time, localtime, timezone}
  • PUT sets the timezone (the only writable field)

Examples:

Fetching time

repo = TimeConfig.new(connection)
config = repo.fetch("pve1")
config.timezone #=> "Europe/Warsaw"

Setting timezone

repo.set_timezone("pve1", "UTC")

See Also:

Instance Attribute Summary

Attributes inherited from Base

#connection

Instance Method Summary collapse

Methods inherited from Base

#extract_data, #get, #initialize, #list, #models_from, #unwrap

Constructor Details

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

Instance Method Details

#build_model(data) ⇒ Models::TimeConfig

Builds TimeConfig model from API data.



48
49
50
# File 'lib/pvectl/repositories/time_config.rb', line 48

def build_model(data)
  Models::TimeConfig.new(data)
end

#fetch(node_name) ⇒ Models::TimeConfig

Fetches time and timezone settings for a node.



26
27
28
29
30
# File 'lib/pvectl/repositories/time_config.rb', line 26

def fetch(node_name)
  response = connection.client["nodes/#{node_name}/time"].get
  data = extract_data(response) || {}
  build_model(data.merge(node_name: node_name))
end

#set_timezone(node_name, timezone) ⇒ nil

Sets the timezone on a node.



37
38
39
40
# File 'lib/pvectl/repositories/time_config.rb', line 37

def set_timezone(node_name, timezone)
  connection.client["nodes/#{node_name}/time"].put(timezone: timezone)
  nil
end