Class: OsCtl::Image::Cli::Containers
- Inherits:
-
Cli::Command
- Object
- Cli::Command
- OsCtl::Image::Cli::Containers
- Defined in:
- lib/osctl/image/cli/containers.rb
Constant Summary collapse
- FIELDS =
%i[ pool id type distribution version ].freeze
Instance Method Summary collapse
Instance Method Details
#delete ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/osctl/image/cli/containers.rb', line 46 def delete client = OsCtldClient.new cts = get_cts(client) cts.select! { |ct| ct[:type] == opts[:type] } if opts[:type] cts.select! { |ct| args.include?(ct[:id]) } if args.any? unless opts[:force] puts 'The following containers will be deleted:' cts.each { |ct| puts " #{ct[:pool]}:#{ct[:id]}" } $stdout.write('Continue? [y/N]: ') $stdout.flush return if $stdin.readline.strip != 'y' end cts.each do |ct| client.delete_container(ct[:id]) end end |
#get_cts(client) ⇒ Object (protected)
67 68 69 70 71 72 73 74 |
# File 'lib/osctl/image/cli/containers.rb', line 67 def get_cts(client) cts = client.list_containers.select do |ct| ct.has_key?(:'org.vpsadminos.osctl-image:type') end.map do |ct| ct[:type] = ct[:'org.vpsadminos.osctl-image:type'] ct end end |
#list ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/osctl/image/cli/containers.rb', line 15 def list param_selector = OsCtl::Lib::Cli::ParameterSelector.new( all_params: FIELDS ) if opts[:list] puts param_selector return end cts = get_cts(OsCtldClient.new) cols = param_selector.parse_option(opts[:output]) sort = opts[:sort] && param_selector.parse_option(opts[:sort]) if sort sort.each do |v| cols << v unless cols.include?(v) end end fmt_opts = { layout: :columns, cols:, sort:, header: !opts['hide-header'] } OsCtl::Lib::Cli::OutputFormatter.print(cts, **fmt_opts) end |