Project

General

Profile

Download (2.01 KB) Statistics
| Branch: | Tag: | Revision:

hammer-cli-csv / lib / hammer_cli_csv / containers.rb @ f4fb9c20

1
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
      def export(csv)
15
        csv << [NAME, REGISTRY, REPOSITORY, COMPUTERESOURCE, ATTACH, ENTRYPOINT, COMMAND]
16
        @api.resource(:containers).call(:index, {'per_page' => 999999})['results'].each do |container|
17
          csv << [container['name'],
18
                  container['registry_name'],
19
                  "#{container['repository_name']}:#{container['tag']}",
20
                  container['compute_resource_name'],
21
                  export_attach_types(container),
22
                  container['entrypoint'],
23
                  container['command']]
24
        end
25
      end
26

    
27
      def import
28
        @existing = {}
29

    
30
        thread_import do |line|
31
          create_containers_from_csv(line)
32
        end
33
      end
34

    
35
      def create_containers_from_csv(line)
36
        # TODO: containers cannot be updated (no api)
37
        # count(line[COUNT]).times do |number|
38
        #   name = namify(line[NAME], number)
39
        #   params =  { 'id' => foreman_container(:name => name),
40
        #               'container' => {
41
        #                 'name' => name,
42
        #                 'command' => line[COMMAND]
43
        #               }
44
        #             }
45
        #   print "Updating container '#{name}'..." if option_verbose?
46
        #   @api.resource(:containers).call(:update, params)
47
        # end
48
        # print "done\n" if option_verbose?
49
      end
50

    
51
      private
52

    
53
      def export_attach_types(container)
54
        types = []
55
        types << 'tty' if container['tty']
56
        types << 'stdin' if container['attach_stdin']
57
        types << 'stdout' if container['attach_stdout']
58
        types << 'stderr' if container['attach_stderr']
59
        types.join(',')
60
      end
61
    end
62
  end
63
end