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/host_collections.rb
8 8
      LIMIT = 'Limit'
9 9
      DESCRIPTION = 'Description'
10 10

  
11
      def export
12
        CSV.open(option_file || '/dev/stdout', 'wb') do |csv|
13
          csv << [NAME, ORGANIZATION, LIMIT, DESCRIPTION]
14
          if @server_status['release'] == 'Headpin'
15
            @headpin.get(:organizations).each do |organization|
16
              next if option_organization && organization['name'] != option_organization
17
              @headpin.get("organizations/#{organization['label']}/system_groups").each do |systemgroup|
18
                csv << [systemgroup['name'], organization['name'],
19
                        systemgroup['max_systems'].to_i < 0 ? 'Unlimited' : systemgroup['max_systems'],
20
                        systemgroup['description']]
21
              end
11
      def export(csv)
12
        csv << [NAME, ORGANIZATION, LIMIT, DESCRIPTION]
13
        if @server_status['release'] == 'Headpin'
14
          @headpin.get(:organizations).each do |organization|
15
            next if option_organization && organization['name'] != option_organization
16
            @headpin.get("organizations/#{organization['label']}/system_groups").each do |systemgroup|
17
              csv << [systemgroup['name'], organization['name'],
18
                      systemgroup['max_systems'].to_i < 0 ? 'Unlimited' : systemgroup['max_systems'],
19
                      systemgroup['description']]
22 20
            end
23
          else
24
            @api.resource(:organizations).call(:index, {'per_page' => 999999})['results'].each do |organization|
25
              next if option_organization && organization['name'] != option_organization
26
              @api.resource(:host_collections).call(:index, {
27
                  'organization_id' => organization['id']
28
              })['results'].each do |hostcollection|
29
                limit = hostcollection['unlimited_content_hosts'] ? 'Unlimited' : hostcollection['max_content_hosts']
30
                csv << [hostcollection['name'], organization['name'],
31
                        limit,
32
                        hostcollection['description']]
33
              end
21
          end
22
        else
23
          @api.resource(:organizations).call(:index, {'per_page' => 999999})['results'].each do |organization|
24
            next if option_organization && organization['name'] != option_organization
25
            @api.resource(:host_collections).call(:index, {
26
                'organization_id' => organization['id']
27
            })['results'].each do |hostcollection|
28
              limit = hostcollection['unlimited_content_hosts'] ? 'Unlimited' : hostcollection['max_content_hosts']
29
              csv << [hostcollection['name'], organization['name'],
30
                      limit,
31
                      hostcollection['description']]
34 32
            end
35 33
          end
36 34
        end

Also available in: Unified diff