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/hosts.rb
22 22
      ENABLED = 'Enabled'
23 23
      MANAGED = 'Managed'
24 24

  
25
      def export
26
        CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
27
          csv << [NAME, ORGANIZATION, LOCATION, ENVIRONMENT, OPERATINGSYSTEM, ARCHITECTURE,
28
                  MACADDRESS, DOMAIN, PARTITIONTABLE, SUBNET, REALM, MEDIUM, HOSTGROUP,
29
                  COMPUTERESOURCE, COMPUTEPROFILE, IMAGE, ENABLED, MANAGED]
30
          search_options = {:per_page => 999999}
31
          search_options['search'] = "organization=\"#{option_organization}\"" if option_organization
32
          @api.resource(:hosts).call(:index, search_options)['results'].each do |host|
33
            host = @api.resource(:hosts).call(:show, {'id' => host['id']})
34
            raise "Host 'id=#{host['id']}' not found" if !host || host.empty?
25
      def export(csv)
26
        csv << [NAME, ORGANIZATION, LOCATION, ENVIRONMENT, OPERATINGSYSTEM, ARCHITECTURE,
27
                MACADDRESS, DOMAIN, PARTITIONTABLE, SUBNET, REALM, MEDIUM, HOSTGROUP,
28
                COMPUTERESOURCE, COMPUTEPROFILE, IMAGE, ENABLED, MANAGED]
29
        search_options = {:per_page => 999999}
30
        search_options['search'] = "organization=\"#{option_organization}\"" if option_organization
31
        @api.resource(:hosts).call(:index, search_options)['results'].each do |host|
32
          host = @api.resource(:hosts).call(:show, {'id' => host['id']})
33
          raise "Host 'id=#{host['id']}' not found" if !host || host.empty?
35 34

  
36
            name = host['name']
37
            organization = host['organization_name']
38
            location = host['location_name']
39
            environment = host['environment_name']
40
            operatingsystem = host['operatingsystem_name']
41
            architecture = host['architecture_name']
42
            mac = host['mac']
43
            domain = host['domain_name']
44
            ptable = host['ptable_name']
45
            subnet = host['subnet_name']
46
            realm = host['realm_name']
47
            medium = host['medium_name']
48
            hostgroup = host['hostgroup_name']
49
            compute_resource = host['compute_resource_name']
50
            compute_profile = host['compute_profile_name']
51
            image = host['image_name']
35
          name = host['name']
36
          organization = host['organization_name']
37
          location = host['location_name']
38
          environment = host['environment_name']
39
          operatingsystem = host['operatingsystem_name']
40
          architecture = host['architecture_name']
41
          mac = host['mac']
42
          domain = host['domain_name']
43
          ptable = host['ptable_name']
44
          subnet = host['subnet_name']
45
          realm = host['realm_name']
46
          medium = host['medium_name']
47
          hostgroup = host['hostgroup_name']
48
          compute_resource = host['compute_resource_name']
49
          compute_profile = host['compute_profile_name']
50
          image = host['image_name']
52 51

  
53
            enabled = host['enabled'] ? 'Yes' : 'No'
54
            managed = host['managed'] ? 'Yes' : 'No'
52
          enabled = host['enabled'] ? 'Yes' : 'No'
53
          managed = host['managed'] ? 'Yes' : 'No'
55 54

  
56
            csv << [name, organization, location, environment, operatingsystem, architecture,
57
                    mac, domain, ptable, subnet, realm, medium, hostgroup, compute_resource,
58
                    compute_profile, image, enabled, managed]
59
          end
55
          csv << [name, organization, location, environment, operatingsystem, architecture,
56
                  mac, domain, ptable, subnet, realm, medium, hostgroup, compute_resource,
57
                  compute_profile, image, enabled, managed]
60 58
        end
61 59
      end
62 60

  

Also available in: Unified diff