Module: Pvectl::Commands::SharedConfigParsers
- Included in:
- CloneContainer, CloneVm, CreateContainer, CreateVm
- Defined in:
- lib/pvectl/commands/shared_config_parsers.rb
Overview
Shared parser methods for CLI flag values.
Provides reusable methods that parse –disk, –net, –cloud-init, –mp flags through their respective Parsers. Included by create and clone commands to avoid parser logic duplication.
Expects @options (a Hash of CLI flag values) to be available in the including class.
Instance Method Summary collapse
-
#build_ct_config_params ⇒ Hash<Symbol, untyped>
Builds a container config parameters hash from CLI options.
-
#build_vm_config_params ⇒ Hash<Symbol, untyped>
Builds a VM config parameters hash from CLI options.
-
#parse_ct_mountpoints ⇒ Array<Hash<Symbol, String>>
Parses LXC mountpoint configuration strings through the LxcMountConfig parser.
-
#parse_ct_nets ⇒ Array<Hash<Symbol, String>>
Parses LXC network configuration strings through the LxcNetConfig parser.
-
#parse_vm_cloud_init ⇒ Hash<Symbol, untyped>
Parses cloud-init configuration string and converts to Proxmox params.
-
#parse_vm_disks ⇒ Array<Hash<Symbol, String>>
Parses VM disk configuration strings through the DiskConfig parser.
-
#parse_vm_nets ⇒ Array<Hash<Symbol, String>>
Parses VM network configuration strings through the NetConfig parser.
Instance Method Details
#build_ct_config_params ⇒ Hash<Symbol, untyped>
Builds a container config parameters hash from CLI options.
Extracts container-specific configuration keys from @options, parsing rootfs, mountpoint, and network flags through their respective parsers. Nil values are compacted out.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/pvectl/commands/shared_config_parsers.rb', line 104 def build_ct_config_params params = { cores: @options[:cores], memory: @options[:memory], swap: @options[:swap], tags: @options[:tags], features: @options[:features], password: @options[:password], ssh_public_keys: @options[:"ssh-public-keys"], onboot: @options[:onboot], startup: @options[:startup] } params[:rootfs] = Parsers::LxcMountConfig.parse(@options[:rootfs]) if @options[:rootfs] params[:mountpoints] = parse_ct_mountpoints if @options[:mp] params[:nets] = parse_ct_nets if @options[:net] params[:privileged] = @options[:privileged] params.compact end |
#build_vm_config_params ⇒ Hash<Symbol, untyped>
Builds a VM config parameters hash from CLI options.
Extracts VM-specific configuration keys from @options, parsing disk, network, and cloud-init flags through their respective parsers. Nil values are compacted out.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/pvectl/commands/shared_config_parsers.rb', line 70 def build_vm_config_params params = { cores: @options[:cores], sockets: @options[:sockets], cpu_type: @options[:"cpu-type"], numa: @options[:numa], memory: @options[:memory], balloon: @options[:balloon], scsihw: @options[:scsihw], cdrom: @options[:cdrom], bios: @options[:bios], boot_order: @options[:"boot-order"], machine: @options[:machine], efidisk: @options[:efidisk], agent: @options[:agent], ostype: @options[:ostype], tags: @options[:tags] } params[:disks] = parse_vm_disks if @options[:disk] params[:nets] = parse_vm_nets if @options[:net] params[:cloud_init] = parse_vm_cloud_init if @options[:"cloud-init"] params.compact end |
#parse_ct_mountpoints ⇒ Array<Hash<Symbol, String>>
Parses LXC mountpoint configuration strings through the LxcMountConfig parser.
50 51 52 |
# File 'lib/pvectl/commands/shared_config_parsers.rb', line 50 def parse_ct_mountpoints Array(@options[:mp]).map { |m| Parsers::LxcMountConfig.parse(m) } end |
#parse_ct_nets ⇒ Array<Hash<Symbol, String>>
Parses LXC network configuration strings through the LxcNetConfig parser.
58 59 60 |
# File 'lib/pvectl/commands/shared_config_parsers.rb', line 58 def parse_ct_nets Array(@options[:net]).map { |n| Parsers::LxcNetConfig.parse(n) } end |
#parse_vm_cloud_init ⇒ Hash<Symbol, untyped>
Parses cloud-init configuration string and converts to Proxmox params.
41 42 43 44 |
# File 'lib/pvectl/commands/shared_config_parsers.rb', line 41 def parse_vm_cloud_init config = Parsers::CloudInitConfig.parse(@options[:"cloud-init"]) Parsers::CloudInitConfig.to_proxmox_params(config) end |
#parse_vm_disks ⇒ Array<Hash<Symbol, String>>
Parses VM disk configuration strings through the DiskConfig parser.
25 26 27 |
# File 'lib/pvectl/commands/shared_config_parsers.rb', line 25 def parse_vm_disks Array(@options[:disk]).map { |d| Parsers::DiskConfig.parse(d) } end |