Class: Pvectl::Parsers::LxcNetConfig
- Inherits:
-
Object
- Object
- Pvectl::Parsers::LxcNetConfig
- Defined in:
- lib/pvectl/parsers/lxc_net_config.rb
Overview
Parses and formats LXC network configurations for Proxmox containers.
LXC network format differs from QEMU: uses name/type instead of model, and supports IP configuration directly in the network spec.
Constant Summary collapse
- VALID_KEYS =
All recognized LXC network configuration keys.
%w[bridge name ip gw ip6 gw6 tag firewall mtu rate type].freeze
- REQUIRED_KEYS =
Keys that must be present in every network configuration.
%w[bridge].freeze
- OPTIONAL_FLAGS =
Optional flags appended to the Proxmox API string.
%w[ip gw ip6 gw6 tag firewall mtu rate].freeze
Class Method Summary collapse
-
.parse(string) ⇒ Hash<Symbol, String>
Parses a comma-separated key=value LXC net config string into a Hash.
-
.to_proxmox(config) ⇒ String
Converts a parsed LXC net config Hash to a Proxmox API string.
Class Method Details
.parse(string) ⇒ Hash<Symbol, String>
Parses a comma-separated key=value LXC net config string into a Hash.
39 40 41 42 43 44 45 |
# File 'lib/pvectl/parsers/lxc_net_config.rb', line 39 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 LXC net config Hash to a Proxmox API string.
The Proxmox API expects LXC network specifications in the format “name=eth0,bridge=vmbr0,,type=veth”. Name defaults to “eth0” and type defaults to “veth” when not specified.
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/pvectl/parsers/lxc_net_config.rb', line 63 def self.to_proxmox(config) name = config[:name] || "eth0" type = config[:type] || "veth" parts = ["name=#{name}", "bridge=#{config[:bridge]}"] OPTIONAL_FLAGS.each do |flag| parts << "#{flag}=#{config[flag.to_sym]}" if config[flag.to_sym] end parts << "type=#{type}" parts.join(",") end |