Revision c06f1783
Added by Thomas McKay over 6 years ago
lib/hammer_cli_csv/puppet_reports.rb | ||
---|---|---|
19 | 19 |
PRODUCTS = 'Products' |
20 | 20 |
SUBSCRIPTIONS = 'Subscriptions' |
21 | 21 |
|
22 |
def export |
|
23 |
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv| |
|
24 |
csv << [NAME, ORGANIZATION, ENVIRONMENT, CONTENTVIEW, SYSTEMGROUPS, VIRTUAL, HOST, |
|
25 |
OPERATINGSYSTEM, ARCHITECTURE, SOCKETS, RAM, CORES, SLA, PRODUCTS, SUBSCRIPTIONS] |
|
26 |
@api.resource(:organizations).call(:index, { |
|
27 |
:per_page => 999999 |
|
28 |
})['results'].each do |organization| |
|
29 |
@api.resource(:systems).call(:index, { |
|
30 |
'per_page' => 999999, |
|
31 |
'organization_id' => organization['id'] |
|
32 |
})['results'].each do |system| |
|
33 |
system = @api.resource(:systems).call(:show, { |
|
34 |
'id' => system['uuid'], |
|
35 |
'fields' => 'full' |
|
36 |
}) |
|
37 |
|
|
38 |
name = system['name'] |
|
39 |
organization_label = organization['label'] |
|
40 |
environment = system['environment']['label'] |
|
41 |
contentview = system['content_view']['name'] |
|
42 |
hostcollections = CSV.generate do |column| |
|
43 |
column << system['systemGroups'].collect do |hostcollection| |
|
44 |
hostcollection['name'] |
|
45 |
end |
|
22 |
def export(csv) |
|
23 |
csv << [NAME, ORGANIZATION, ENVIRONMENT, CONTENTVIEW, SYSTEMGROUPS, VIRTUAL, HOST, |
|
24 |
OPERATINGSYSTEM, ARCHITECTURE, SOCKETS, RAM, CORES, SLA, PRODUCTS, SUBSCRIPTIONS] |
|
25 |
@api.resource(:organizations).call(:index, { |
|
26 |
:per_page => 999999 |
|
27 |
})['results'].each do |organization| |
|
28 |
@api.resource(:systems).call(:index, { |
|
29 |
'per_page' => 999999, |
|
30 |
'organization_id' => organization['id'] |
|
31 |
})['results'].each do |system| |
|
32 |
system = @api.resource(:systems).call(:show, { |
|
33 |
'id' => system['uuid'], |
|
34 |
'fields' => 'full' |
|
35 |
}) |
|
36 |
|
|
37 |
name = system['name'] |
|
38 |
organization_label = organization['label'] |
|
39 |
environment = system['environment']['label'] |
|
40 |
contentview = system['content_view']['name'] |
|
41 |
hostcollections = CSV.generate do |column| |
|
42 |
column << system['systemGroups'].collect do |hostcollection| |
|
43 |
hostcollection['name'] |
|
46 | 44 |
end |
47 |
hostcollections.delete!("\n")
|
|
48 |
virtual = system['facts']['virt.is_guest'] == 'true' ? 'Yes' : 'No'
|
|
49 |
host = system['host']
|
|
50 |
operatingsystem = "#{system['facts']['distribution.name']} " if system['facts']['distribution.name']
|
|
51 |
operatingsystem += system['facts']['distribution.version'] if system['facts']['distribution.version']
|
|
52 |
architecture = system['facts']['uname.machine']
|
|
53 |
sockets = system['facts']['cpu.cpu_socket(s)']
|
|
54 |
ram = system['facts']['memory.memtotal']
|
|
55 |
cores = system['facts']['cpu.core(s)_per_socket']
|
|
56 |
sla = ''
|
|
57 |
products = CSV.generate do |column|
|
|
58 |
column << system['installedProducts'].collect do |product|
|
|
59 |
"#{product['productId']}|#{product['productName']}"
|
|
60 |
end
|
|
45 |
end
|
|
46 |
hostcollections.delete!("\n")
|
|
47 |
virtual = system['facts']['virt.is_guest'] == 'true' ? 'Yes' : 'No'
|
|
48 |
host = system['host']
|
|
49 |
operatingsystem = "#{system['facts']['distribution.name']} " if system['facts']['distribution.name']
|
|
50 |
operatingsystem += system['facts']['distribution.version'] if system['facts']['distribution.version']
|
|
51 |
architecture = system['facts']['uname.machine']
|
|
52 |
sockets = system['facts']['cpu.cpu_socket(s)']
|
|
53 |
ram = system['facts']['memory.memtotal']
|
|
54 |
cores = system['facts']['cpu.core(s)_per_socket']
|
|
55 |
sla = ''
|
|
56 |
products = CSV.generate do |column|
|
|
57 |
column << system['installedProducts'].collect do |product|
|
|
58 |
"#{product['productId']}|#{product['productName']}"
|
|
61 | 59 |
end |
62 |
products.delete!("\n")
|
|
63 |
subscriptions = CSV.generate do |column|
|
|
64 |
column << @api.resource(:subscriptions).call(:index, {
|
|
65 |
'system_id' => system['uuid']
|
|
66 |
})['results'].collect do |subscription|
|
|
67 |
"#{subscription['product_id']}|#{subscription['product_name']}"
|
|
68 |
end
|
|
60 |
end
|
|
61 |
products.delete!("\n")
|
|
62 |
subscriptions = CSV.generate do |column|
|
|
63 |
column << @api.resource(:subscriptions).call(:index, {
|
|
64 |
'system_id' => system['uuid']
|
|
65 |
})['results'].collect do |subscription|
|
|
66 |
"#{subscription['product_id']}|#{subscription['product_name']}"
|
|
69 | 67 |
end |
70 |
subscriptions.delete!("\n") |
|
71 |
csv << [name, organization_label, environment, contentview, hostcollections, virtual, host, |
|
72 |
operatingsystem, architecture, sockets, ram, cores, sla, products, subscriptions] |
|
73 | 68 |
end |
69 |
subscriptions.delete!("\n") |
|
70 |
csv << [name, organization_label, environment, contentview, hostcollections, virtual, host, |
|
71 |
operatingsystem, architecture, sockets, ram, cores, sla, products, subscriptions] |
|
74 | 72 |
end |
75 | 73 |
end |
76 | 74 |
end |
Also available in: Unified diff
fixes #15743 - import and export of subscriptions one-per-line