1 |
c4dbc7a3
|
Tom McKay
|
module HammerCLICsv
|
2 |
|
|
class CsvCommand
|
3 |
|
|
class ContainersCommand < BaseCommand
|
4 |
|
|
command_name 'containers'
|
5 |
|
|
desc 'import or export containers'
|
6 |
|
|
|
7 |
|
|
REGISTRY = 'Registry'
|
8 |
|
|
REPOSITORY = 'Repository:Tag'
|
9 |
|
|
COMPUTERESOURCE = 'Compute Resource'
|
10 |
|
|
ATTACH = 'Attach I/O'
|
11 |
|
|
ENTRYPOINT = 'Entry Point'
|
12 |
|
|
COMMAND = 'Command'
|
13 |
|
|
|
14 |
c06f1783
|
Tom McKay
|
def export(csv)
|
15 |
|
|
csv << [NAME, REGISTRY, REPOSITORY, COMPUTERESOURCE, ATTACH, ENTRYPOINT, COMMAND]
|
16 |
6498291e
|
Tom McKay
|
@api.resource(:containers).call(:index, {
|
17 |
|
|
'per_page' => 999999,
|
18 |
|
|
'search' => option_search
|
19 |
|
|
})['results'].each do |container|
|
20 |
c06f1783
|
Tom McKay
|
csv << [container['name'],
|
21 |
|
|
container['registry_name'],
|
22 |
|
|
"#{container['repository_name']}:#{container['tag']}",
|
23 |
|
|
container['compute_resource_name'],
|
24 |
|
|
export_attach_types(container),
|
25 |
|
|
container['entrypoint'],
|
26 |
|
|
container['command']]
|
27 |
c4dbc7a3
|
Tom McKay
|
end
|
28 |
|
|
end
|
29 |
|
|
|
30 |
|
|
def import
|
31 |
|
|
@existing = {}
|
32 |
|
|
|
33 |
|
|
thread_import do |line|
|
34 |
|
|
create_containers_from_csv(line)
|
35 |
|
|
end
|
36 |
|
|
end
|
37 |
|
|
|
38 |
|
|
def create_containers_from_csv(line)
|
39 |
|
|
|
40 |
02387fb5
|
Tom McKay
|
|
41 |
c4dbc7a3
|
Tom McKay
|
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
end
|
53 |
|
|
|
54 |
|
|
private
|
55 |
|
|
|
56 |
|
|
def export_attach_types(container)
|
57 |
|
|
types = []
|
58 |
|
|
types << 'tty' if container['tty']
|
59 |
|
|
types << 'stdin' if container['attach_stdin']
|
60 |
|
|
types << 'stdout' if container['attach_stdout']
|
61 |
|
|
types << 'stderr' if container['attach_stderr']
|
62 |
|
|
types.join(',')
|
63 |
|
|
end
|
64 |
|
|
end
|
65 |
|
|
end
|
66 |
|
|
end |