Project

General

Profile

Revision c06f1783

Added by Thomas McKay over 6 years ago

fixes #15743 - import and export of subscriptions one-per-line

View differences:

lib/hammer_cli_csv/sync_plans.rb
11 11
      INTERVAL = 'Interval'
12 12
      PRODUCTS = 'Products'
13 13

  
14
      def export
15
        CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
16
          csv << [NAME, ORGANIZATION, DESCRIPTION, ENABLED, STARTDATE, INTERVAL, PRODUCTS]
14
      def export(csv)
15
        csv << [NAME, ORGANIZATION, DESCRIPTION, ENABLED, STARTDATE, INTERVAL, PRODUCTS]
17 16

  
18
          @api.resource(:organizations).call(:index, {:per_page => 999999})['results'].each do |organization|
19
            next if option_organization && organization['name'] != option_organization
17
        @api.resource(:organizations).call(:index, {:per_page => 999999})['results'].each do |organization|
18
          next if option_organization && organization['name'] != option_organization
20 19

  
21
            @api.resource(:sync_plans).call(:index, {
22
                 'per_page' => 999999,
23
                 'organization_id' => foreman_organization(:name => organization['name'])
24
            })['results'].each do |sync_plan|
25
              name = sync_plan['name']
26
              organization_name = organization['name']
27
              description = sync_plan['description']
28
              enabled = sync_plan['enabled'] ? 'Yes' : 'No'
29
              start_date = sync_plan['sync_date']
30
              interval = sync_plan['interval']
31
              products = CSV.generate do |column|
32
                column << sync_plan['products'].collect do |product|
33
                  product['name']
34
                end
20
          @api.resource(:sync_plans).call(:index, {
21
               'per_page' => 999999,
22
               'organization_id' => foreman_organization(:name => organization['name'])
23
          })['results'].each do |sync_plan|
24
            name = sync_plan['name']
25
            organization_name = organization['name']
26
            description = sync_plan['description']
27
            enabled = sync_plan['enabled'] ? 'Yes' : 'No'
28
            start_date = sync_plan['sync_date']
29
            interval = sync_plan['interval']
30
            products = CSV.generate do |column|
31
              column << sync_plan['products'].collect do |product|
32
                product['name']
35 33
              end
36
              products.delete!("\n")
37
              csv << [name, organization_name, description, enabled, start_date, interval,
38
                      products]
39 34
            end
35
            products.delete!("\n")
36
            csv << [name, organization_name, description, enabled, start_date, interval,
37
                    products]
40 38
          end
41 39
        end
42 40
      end

Also available in: Unified diff