Project

General

Profile

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

hammer-cli-csv / lib / hammer_cli_csv / subscriptions.rb @ 8c7ba4af

1
# Copyright 2013-2014 Red Hat, Inc.
2
#
3
# This software is licensed to you under the GNU General Public
4
# License as published by the Free Software Foundation; either version
5
# 2 of the License (GPLv2) or (at your option) any later version.
6
# There is NO WARRANTY for this software, express or implied,
7
# including the implied warranties of MERCHANTABILITY,
8
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
9
# have received a copy of GPLv2 along with this software; if not, see
10
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
11

    
12
#
13
# -= Systems CSV =-
14
#
15
# Columns
16
#   Name
17
#     - System name
18
#     - May contain '%d' which will be replaced with current iteration number of Count
19
#     - eg. "os%d" -> "os1"
20
#   Count
21
#     - Number of times to iterate on this line of the CSV file
22

    
23
require 'hammer_cli'
24
require 'json'
25
require 'csv'
26
require 'uri'
27

    
28
module HammerCLICsv
29
  class CsvCommand
30
    class SubscriptionsCommand < BaseCommand
31
      command_name 'subscriptions'
32
      desc         'import or export subscriptions'
33

    
34
      ORGANIZATION = 'Organization'
35
      MANIFEST = 'Manifest File'
36

    
37
      def export
38
        # TODO
39
      end
40

    
41
      def import
42
        thread_import do |line|
43
          create_subscriptions_from_csv(line)
44
        end
45
      end
46

    
47
      def create_subscriptions_from_csv(line)
48
        args = %W{ subscription upload --file #{ line[MANIFEST] }
49
                   --organization-id #{ foreman_organization(:name => line[ORGANIZATION]) } }
50
        hammer.run(args)
51
      rescue RuntimeError => e
52
        raise "#{e}\n       #{line}"
53
      end
54

    
55
      def ctx
56
        {
57
          :interactive => false,
58
          :username => 'admin',
59
          :password => 'changeme'
60
        }
61
      end
62

    
63
      def hammer(context = nil)
64
        HammerCLI::MainCommand.new('', context || ctx)
65
      end
66

    
67
    end
68
  end
69
end