Project

General

Profile

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

hammer-cli-csv / lib / hammer_cli_csv / subscriptions.rb @ 9d9e4494

1
# Copyright (c) 2013 Red Hat
2
#
3
# MIT License
4
#
5
# Permission is hereby granted, free of charge, to any person obtaining
6
# a copy of this software and associated documentation files (the
7
# "Software"), to deal in the Software without restriction, including
8
# without limitation the rights to use, copy, modify, merge, publish,
9
# distribute, sublicense, and/or sell copies of the Software, and to
10
# permit persons to whom the Software is furnished to do so, subject to
11
# the following conditions:
12
#
13
# The above copyright notice and this permission notice shall be
14
# included in all copies or substantial portions of the Software.
15
#
16
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
#
24
#
25
# -= Systems CSV =-
26
#
27
# Columns
28
#   Name
29
#     - System name
30
#     - May contain '%d' which will be replaced with current iteration number of Count
31
#     - eg. "os%d" -> "os1"
32
#   Count
33
#     - Number of times to iterate on this line of the CSV file
34

    
35

    
36
require 'hammer_cli'
37
require 'katello_api'
38
require 'foreman_api'
39
require 'json'
40
require 'csv'
41
require 'uri'
42

    
43
module HammerCLICsv
44
  class SubscriptionsCommand < BaseCommand
45

    
46
    ORGANIZATION = 'Organization'
47
    MANIFEST = 'Manifest File'
48

    
49
    def export
50
      # TODO
51
    end
52

    
53
    def import
54
      thread_import do |line|
55
        create_subscriptions_from_csv(line)
56
      end
57
    end
58

    
59
    def create_subscriptions_from_csv(line)
60
      puts "TODO: import #{line[MANIFEST]} into organization #{line[ORGANIZATION]}"
61
    rescue RuntimeError => e
62
      raise RuntimeError.new("#{e}\n       #{line}")
63
    end
64
  end
65

    
66
  HammerCLI::MainCommand.subcommand("csv:subscriptions", "import subscriptions", HammerCLICsv::SubscriptionsCommand)
67
end