Class: HammerCLICsv::CsvCommand::PuppetReportsCommand
- Inherits:
-
BaseCommand
- Object
- HammerCLI::Apipie::Command
- BaseCommand
- HammerCLICsv::CsvCommand::PuppetReportsCommand
show all
- Defined in:
- lib/hammer_cli_csv/puppet_reports.rb
Constant Summary
collapse
- ORGANIZATION =
'Organization'
- ENVIRONMENT =
'Environment'
- CONTENTVIEW =
'Content View'
- SYSTEMGROUPS =
'System Groups'
- VIRTUAL =
'Virtual'
- HOST =
'Host'
- OPERATINGSYSTEM =
'OS'
- ARCHITECTURE =
'Arch'
- SOCKETS =
'Sockets'
- RAM =
'RAM'
- CORES =
'Cores'
- SLA =
'SLA'
- PRODUCTS =
'Products'
- SUBSCRIPTIONS =
'Subscriptions'
Constants inherited
from BaseCommand
BaseCommand::COUNT, BaseCommand::NAME
Instance Method Summary
collapse
Methods inherited from BaseCommand
#apipie_check_param, #associate_locations, #associate_organizations, #authenticate_request, #build_os_name, #check_server_status, #collect_column, #count, #execute, #export_column, #foreman_architecture, #foreman_container, #foreman_domain, #foreman_environment, #foreman_filter, #foreman_host, #foreman_hostgroup, #foreman_location, #foreman_medium, #foreman_operatingsystem, #foreman_organization, #foreman_partitiontable, #foreman_permission, #foreman_provisioning_template, #foreman_role, #foreman_smart_proxy, #foreman_template_kind, #hammer, #hammer_context, #help, help_columns, #katello_contentview, #katello_contentviewversion, #katello_hostcollection, #katello_product, #katello_repository, #labelize, #lifecycle_environment, #namify, #pluralize, #split_os_name, #supported?, supported?, #thread_import
#api_connection
Instance Method Details
#create_systems_from_csv(line) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/hammer_cli_csv/puppet_reports.rb', line 94
def create_systems_from_csv(line)
if !@existing[line[ORGANIZATION]]
@existing[line[ORGANIZATION]] = {}
@api.resource(:systems).call(:index, {
'organization_id' => line[ORGANIZATION],
'per_page' => 999999
})['results'].each do |system|
@existing[line[ORGANIZATION]][system['name']] = system['uuid'] if system
end
end
count(line[COUNT]).times do |number|
name = namify(line[NAME], number)
if !@existing[line[ORGANIZATION]].include? name
print "Creating system '#{name}'..." if option_verbose?
system_id = @api.resource(:systems).call(:create, {
'name' => name,
'organization_id' => line[ORGANIZATION],
'environment_id' => lifecycle_environment(line[ORGANIZATION], :name => line[ENVIRONMENT]),
'content_view_id' => lifecycle_contentview(line[ORGANIZATION], :name => line[CONTENTVIEW]),
'facts' => facts(line),
'installed_products' => products(line),
'type' => 'system'
})['uuid']
@existing[line[ORGANIZATION]][name] = system_id
else
print "Updating system '#{name}'..." if option_verbose?
puts line
system_id = @api.resource(:systems).call(:update, {
'id' => @existing[line[ORGANIZATION]][name],
'name' => name,
'environment_id' => katello_environment(line[ORGANIZATION], :name => line[ENVIRONMENT]),
'content_view_id' => katello_contentview(line[ORGANIZATION], :name => line[CONTENTVIEW]),
'facts' => facts(line),
'installed_products' => products(line)
})['uuid']
end
if line[VIRTUAL] == 'Yes' && line[HOST]
raise "Host system '#{line[HOST]}' not found" if !@existing[line[ORGANIZATION]][line[HOST]]
@host_guests[@existing[line[ORGANIZATION]][line[HOST]]] ||= []
@host_guests[@existing[line[ORGANIZATION]][line[HOST]]] << system_id
end
set_host_collections(system_id, line)
puts 'done' if option_verbose?
end
end
|
#export(csv) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/hammer_cli_csv/puppet_reports.rb', line 22
def export(csv)
csv << [NAME, ORGANIZATION, ENVIRONMENT, CONTENTVIEW, SYSTEMGROUPS, VIRTUAL, HOST,
OPERATINGSYSTEM, ARCHITECTURE, SOCKETS, RAM, CORES, SLA, PRODUCTS, SUBSCRIPTIONS]
@api.resource(:organizations).call(:index, {
:per_page => 999999
})['results'].each do |organization|
@api.resource(:systems).call(:index, {
'per_page' => 999999,
'organization_id' => organization['id']
})['results'].each do |system|
system = @api.resource(:systems).call(:show, {
'id' => system['uuid'],
'fields' => 'full'
})
name = system['name']
organization_label = organization['label']
environment = system['environment']['label']
contentview = system['content_view']['name']
hostcollections = CSV.generate do |column|
column << system['systemGroups'].collect do |hostcollection|
hostcollection['name']
end
end
hostcollections.delete!("\n")
virtual = system['facts']['virt.is_guest'] == 'true' ? 'Yes' : 'No'
host = system['host']
operatingsystem = "#{system['facts']['distribution.name']} " if system['facts']['distribution.name']
operatingsystem += system['facts']['distribution.version'] if system['facts']['distribution.version']
architecture = system['facts']['uname.machine']
sockets = system['facts']['cpu.cpu_socket(s)']
ram = system['facts']['memory.memtotal']
cores = system['facts']['cpu.core(s)_per_socket']
sla = ''
products = CSV.generate do |column|
column << system['installedProducts'].collect do |product|
"#{product['productId']}|#{product['productName']}"
end
end
products.delete!("\n")
subscriptions = CSV.generate do |column|
column << @api.resource(:subscriptions).call(:index, {
'system_id' => system['uuid']
})['results'].collect do |subscription|
"#{subscription['product_id']}|#{subscription['product_name']}"
end
end
subscriptions.delete!("\n")
csv << [name, organization_label, environment, contentview, hostcollections, virtual, host,
operatingsystem, architecture, sockets, ram, cores, sla, products, subscriptions]
end
end
end
|
#import ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/hammer_cli_csv/puppet_reports.rb', line 76
def import
@existing = {}
@host_guests = {}
thread_import do |line|
create_systems_from_csv(line)
end
print 'Updating host and guest associations...' if option_verbose?
@host_guests.each do |host_id, guest_ids|
@api.resource(:systems).call(:update, {
'id' => host_id,
'guest_ids' => guest_ids
})
end
puts 'done' if option_verbose?
end
|