Class: Pvectl::Parsers::LxcMountConfig
- Inherits:
-
Object
- Object
- Pvectl::Parsers::LxcMountConfig
- Defined in:
- lib/pvectl/parsers/lxc_mount_config.rb
Overview
Parses and formats LXC mount configurations for Proxmox containers.
Handles rootfs and mountpoint (mp0, mp1, …) configuration strings. Format: key=value pairs separated by commas.
Constant Summary collapse
- VALID_KEYS =
All recognized mount configuration keys.
%w[storage size mp acl backup quota replicate ro shared].freeze
- REQUIRED_KEYS =
Keys that must be present in every mount configuration.
%w[storage size].freeze
- OPTIONAL_FLAGS =
Optional flags appended to the Proxmox API string.
%w[acl backup quota replicate ro shared].freeze
Class Method Summary collapse
-
.parse(string) ⇒ Hash<Symbol, String>
Parses a comma-separated key=value mount config string into a Hash.
-
.to_proxmox(config) ⇒ String
Converts a parsed mount config Hash to a Proxmox API string.
Class Method Details
.parse(string) ⇒ Hash<Symbol, String>
Parses a comma-separated key=value mount config string into a Hash.
41 42 43 44 45 46 47 |
# File 'lib/pvectl/parsers/lxc_mount_config.rb', line 41 def self.parse(string) pairs = string.split(",").map { |pair| pair.strip.split("=", 2).map(&:strip) } config = pairs.to_h { |k, v| [k.to_sym, v] } validate!(config) config end |
.to_proxmox(config) ⇒ String
Converts a parsed mount config Hash to a Proxmox API string.
The Proxmox API expects mount specifications in the format “storage:size[,flag=val]”. Size is extracted as a numeric value (without the “G” suffix).
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/pvectl/parsers/lxc_mount_config.rb', line 65 def self.to_proxmox(config) size_num = config[:size].to_s.gsub(/[^0-9]/, "") parts = ["#{config[:storage]}:#{size_num}"] parts << "mp=#{config[:mp]}" if config[:mp] OPTIONAL_FLAGS.each do |flag| parts << "#{flag}=#{config[flag.to_sym]}" if config[flag.to_sym] end parts.join(",") end |