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_groups.rb
22 22
      PASSWORD = 'Password'
23 23
      PUPPET_CLASSES = 'Puppet Classes'
24 24

  
25
      def export
26
        CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
27
          csv << [NAME, PARENT, ORGANIZATIONS, LOCATIONS, SUBNET, DOMAIN, OPERATING_SYSTEM,
28
                  ENVIRONMENT, COMPUTE_PROFILE, PARTITION_TABLE, MEDIUM, ARCHITECTURE, REALM,
29
                  PUPPET_PROXY, PUPPET_CA_PROXY, CONTENT_SOURCE, PASSWORD, PUPPET_CLASSES]
30
          search_options = {:per_page => 999999}
31
          search_options['search'] = "organization=\"#{option_organization}\"" if option_organization
32
          @api.resource(:hostgroups).call(:index, search_options)['results'].each do |hostgroup|
33
            hostgroup = @api.resource(:hostgroups).call(:show, {'id' => hostgroup['id']})
34
            raise "Host Group 'id=#{hostgroup['id']}' not found" if !hostgroup || hostgroup.empty?
25
      def export(csv)
26
        csv << [NAME, PARENT, ORGANIZATIONS, LOCATIONS, SUBNET, DOMAIN, OPERATING_SYSTEM,
27
                ENVIRONMENT, COMPUTE_PROFILE, PARTITION_TABLE, MEDIUM, ARCHITECTURE, REALM,
28
                PUPPET_PROXY, PUPPET_CA_PROXY, CONTENT_SOURCE, PASSWORD, PUPPET_CLASSES]
29
        search_options = {:per_page => 999999}
30
        search_options['search'] = "organization=\"#{option_organization}\"" if option_organization
31
        @api.resource(:hostgroups).call(:index, search_options)['results'].each do |hostgroup|
32
          hostgroup = @api.resource(:hostgroups).call(:show, {'id' => hostgroup['id']})
33
          raise "Host Group 'id=#{hostgroup['id']}' not found" if !hostgroup || hostgroup.empty?
35 34

  
36
            name = hostgroup['name']
37
            organizations = export_column(hostgroup, 'organizations', 'name')
38
            locations = export_column(hostgroup, 'locations', 'name')
39
            subnet = hostgroup['subnet_name']
40
            operating_system = hostgroup['operatingsystem_name']
41
            domain = hostgroup['domain_name']
42
            puppet_environment = hostgroup['environment_name']
43
            compute_profile = hostgroup['compute_profile_name']
44
            partition_table = hostgroup['ptable_name']
45
            medium = hostgroup['medium_name']
46
            architecture = hostgroup['architecture_name']
47
            realm = hostgroup['realm_name']
48
            puppet_proxy = hostgroup['puppet_proxy_id'] ? foreman_host(:id => hostgroup['puppet_proxy_id']) : nil
49
            puppet_ca_proxy = hostgroup['puppet_ca_proxy_id'] ? foreman_host(:id => hostgroup['puppet_ca_proxy_id']) : nil
50
            content_source = hostgroup['content_source_id'] ? foreman_host(:id => hostgroup['content_source_id']) : nil
51
            parent = hostgroup['ancestry'] ? foreman_hostgroup(:id => hostgroup['ancestry']) : nil
52
            password = nil
53
            puppet_classes = export_column(hostgroup, 'puppetclasses') do |puppet_class|
54
              "#{puppet_class['module_name']}/#{puppet_class['name']}"
55
            end
35
          name = hostgroup['name']
36
          organizations = export_column(hostgroup, 'organizations', 'name')
37
          locations = export_column(hostgroup, 'locations', 'name')
38
          subnet = hostgroup['subnet_name']
39
          operating_system = hostgroup['operatingsystem_name']
40
          domain = hostgroup['domain_name']
41
          puppet_environment = hostgroup['environment_name']
42
          compute_profile = hostgroup['compute_profile_name']
43
          partition_table = hostgroup['ptable_name']
44
          medium = hostgroup['medium_name']
45
          architecture = hostgroup['architecture_name']
46
          realm = hostgroup['realm_name']
47
          puppet_proxy = hostgroup['puppet_proxy_id'] ? foreman_host(:id => hostgroup['puppet_proxy_id']) : nil
48
          puppet_ca_proxy = hostgroup['puppet_ca_proxy_id'] ? foreman_host(:id => hostgroup['puppet_ca_proxy_id']) : nil
49
          content_source = hostgroup['content_source_id'] ? foreman_host(:id => hostgroup['content_source_id']) : nil
50
          parent = hostgroup['ancestry'] ? foreman_hostgroup(:id => hostgroup['ancestry']) : nil
51
          password = nil
52
          puppet_classes = export_column(hostgroup, 'puppetclasses') do |puppet_class|
53
            "#{puppet_class['module_name']}/#{puppet_class['name']}"
54
          end
56 55

  
57
            # TODO: http://projects.theforeman.org/issues/6273
58
            # API call to get the smart class variable override values
56
          # TODO: http://projects.theforeman.org/issues/6273
57
          # API call to get the smart class variable override values
59 58

  
60
            csv << [name, parent, organizations, locations, subnet, domain, operating_system,
61
                    puppet_environment, compute_profile, partition_table, medium, architecture,
62
                    realm, puppet_proxy, puppet_ca_proxy, content_source, password, puppet_classes]
63
          end
59
          csv << [name, parent, organizations, locations, subnet, domain, operating_system,
60
                  puppet_environment, compute_profile, partition_table, medium, architecture,
61
                  realm, puppet_proxy, puppet_ca_proxy, content_source, password, puppet_classes]
64 62
        end
65 63
      end
66 64

  

Also available in: Unified diff