Class: OsCtl::Image::Cli::Containers
- Inherits:
-
Command
- Object
- Lib::Cli::Command
- Command
- OsCtl::Image::Cli::Containers
show all
- Defined in:
- lib/osctl/image/cli/containers.rb
Constant Summary
collapse
- FIELDS =
%i[
pool
id
type
distribution
version
].freeze
Instance Method Summary
collapse
Methods inherited from Command
#initialize, run
Instance Method Details
#delete ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/osctl/image/cli/containers.rb', line 37
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
58
59
60
61
62
63
64
65
|
# File 'lib/osctl/image/cli/containers.rb', line 58
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
|
# 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)
fmt_opts = {
layout: :columns,
cols: param_selector.parse_option(opts[:output]),
sort: opts[:sort] && param_selector.parse_option(opts[:sort]),
header: !opts['hide-header']
}
OsCtl::Lib::Cli::OutputFormatter.print(cts, **fmt_opts)
end
|