Class: Pvectl::Commands::CreateContainer
- Inherits:
-
Object
- Object
- Pvectl::Commands::CreateContainer
- Includes:
- CreateResourceCommand, SharedConfigParsers
- Defined in:
- lib/pvectl/commands/create_container.rb,
sig/pvectl/commands/create_container.rbs
Overview
Handler for the pvectl create container command.
Includes CreateResourceCommand for shared workflow and overrides template methods with container-specific behavior.
Instance Method Summary collapse
-
#build_create_service(connection, task_repo) ⇒ Services::CreateContainer
Container creation service.
-
#build_params_from_flags ⇒ Hash
Extracts CLI options into a service params hash.
-
#build_wizard ⇒ Object
Container creation wizard.
- #display_resource_summary(params) ⇒ void
- #output_result(result) ⇒ void
-
#perform_create ⇒ Integer
Validates flags and performs flag-based creation.
-
#required_params_missing? ⇒ Boolean
True if --hostname is missing.
-
#resource_id_label ⇒ String
Human label for container IDs.
-
#resource_label ⇒ String
Human label for container resources.
-
#truncate_template(template) ⇒ String
Truncates long template paths for display.
Methods included from SharedConfigParsers
#build_ct_config_params, #build_vm_config_params, #parse_ct_mountpoints, #parse_ct_nets, #parse_vm_cloud_init, #parse_vm_disks, #parse_vm_nets
Methods included from CreateResourceCommand
#display_summary, #display_summary_and_confirm, #execute, included, #initialize, #interactive_mode?, #load_config, #perform_create_with_params, #perform_interactive, #resolve_default_node, #service_options, #usage_error
Instance Method Details
#build_create_service(connection, task_repo) ⇒ Services::CreateContainer
43 44 45 46 47 48 49 50 |
# File 'lib/pvectl/commands/create_container.rb', line 43 def build_create_service(connection, task_repo) ct_repo = Pvectl::Repositories::Container.new(connection) Pvectl::Services::CreateContainer.new( container_repository: ct_repo, task_repository: task_repo, options: ) end |
#build_params_from_flags ⇒ Hash
Extracts CLI options into a service params hash.
Delegates container config parsing to SharedConfigParsers#build_ct_config_params, then adds create-specific parameters.
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/pvectl/commands/create_container.rb', line 82 def build_params_from_flags params = build_ct_config_params params[:hostname] = [:hostname] params[:node] = [:node] || resolve_default_node params[:ostemplate] = [:ostemplate] params[:description] = [:description] params[:pool] = [:pool] ctid = @args.first params[:ctid] = ctid.to_i if ctid params.compact end |
#build_wizard ⇒ Object
36 37 38 |
# File 'lib/pvectl/commands/create_container.rb', line 36 def build_wizard Pvectl::Wizards::CreateContainer.new(, ) end |
#display_resource_summary(params) ⇒ void
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/pvectl/commands/create_container.rb', line 98 def display_resource_summary(params) $stdout.puts " Hostname: #{params[:hostname]}" $stdout.puts " Node: #{params[:node] || '(from context)'}" $stdout.puts " Template: #{truncate_template(params[:ostemplate])}" $stdout.puts " CPU: #{params[:cores] || 1} cores" if params[:cores] $stdout.puts " Memory: #{params[:memory] || 512} MB" $stdout.puts " Swap: #{params[:swap] || 512} MB" if params[:rootfs] $stdout.puts " Root FS: #{params[:rootfs][:storage]}, #{params[:rootfs][:size]}" end if params[:mountpoints] params[:mountpoints].each_with_index do |mp, i| $stdout.puts " Mount#{i}: #{mp[:storage]}, #{mp[:size]} -> #{mp[:mp]}" end end if params[:nets] params[:nets].each_with_index do |net, i| ip_info = net[:ip] ? ", #{net[:ip]}" : "" $stdout.puts " Net#{i}: #{net[:bridge]}, #{net[:name] || 'eth0'}#{ip_info}" end end $stdout.puts " Unpriv: #{params[:privileged] ? 'No' : 'Yes'}" $stdout.puts " Features: #{params[:features]}" if params[:features] $stdout.puts " Tags: #{params[:tags]}" if params[:tags] $stdout.puts " Pool: #{params[:pool]}" if params[:pool] end |
#output_result(result) ⇒ void
54 55 56 57 58 59 60 61 62 |
# File 'lib/pvectl/commands/create_container.rb', line 54 def output_result(result) presenter = Pvectl::Presenters::ContainerOperationResult.new format = [:output] || "table" color_flag = [:color] formatter = Pvectl::Formatters::Registry.for(format) output = formatter.format([result], presenter, color: color_flag) puts output end |
#perform_create ⇒ Integer
Validates flags and performs flag-based creation.
67 68 69 70 71 72 73 |
# File 'lib/pvectl/commands/create_container.rb', line 67 def perform_create return usage_error("--hostname is required") unless [:hostname] return usage_error("--ostemplate is required") unless [:ostemplate] return usage_error("--rootfs is required") unless [:rootfs] super end |
#required_params_missing? ⇒ Boolean
31 32 33 |
# File 'lib/pvectl/commands/create_container.rb', line 31 def required_params_missing? ![:hostname] end |
#resource_id_label ⇒ String
26 27 28 |
# File 'lib/pvectl/commands/create_container.rb', line 26 def resource_id_label "CTID" end |
#resource_label ⇒ String
21 22 23 |
# File 'lib/pvectl/commands/create_container.rb', line 21 def resource_label "container" end |
#truncate_template(template) ⇒ String
Truncates long template paths for display.
133 134 135 136 137 138 |
# File 'lib/pvectl/commands/create_container.rb', line 133 def truncate_template(template) return template unless template parts = template.split("/") parts.last || template end |