Class: HammerCLICsv::CsvCommand::OperatingSystemsCommand
- Inherits:
-
BaseCommand
- Object
- HammerCLI::Apipie::Command
- BaseCommand
- HammerCLICsv::CsvCommand::OperatingSystemsCommand
show all
- Defined in:
- lib/hammer_cli_csv/operating_systems.rb
Constant Summary
collapse
- FAMILY =
'Family'
- DESCRIPTION =
'Description'
- PASSWORD_HASH =
'Password Hash'
- PARTITION_TABLES =
'Partition Tables'
- ARCHITECTURES =
'Architectures'
- MEDIA =
'Media'
- PROVISIONING_TEMPLATES =
'Provisioning Templates'
- PARAMETERS =
'Parameters'
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_operatingsystems_from_csv(line) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/hammer_cli_csv/operating_systems.rb', line 51
def create_operatingsystems_from_csv(line)
params = {
'operatingsystem' => {
'family' => line[FAMILY],
'description' => line[DESCRIPTION],
'password_hash' => line[PASSWORD_HASH]
}
}
params['operatingsystem']['architecture_ids'] = collect_column(line[ARCHITECTURES]) do |name|
foreman_architecture(:name => name)
end
count(line[COUNT]).times do |number|
name = namify(line[NAME], number)
(osname, major, minor) = split_os_name(name)
params['operatingsystem']['name'] = osname
params['operatingsystem']['major'] = major
params['operatingsystem']['minor'] = minor
if !@existing.include? name
print "Creating operating system '#{name}'..." if option_verbose?
@api.resource(:operatingsystems).call(:create, params)
else
print "Updating operating system '#{name}'..." if option_verbose?
params['id'] = @existing[name]
@api.resource(:operatingsystems).call(:update, params)
end
print "done\n" if option_verbose?
end
end
|
#export(csv) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/hammer_cli_csv/operating_systems.rb', line 16
def export(csv)
csv << [NAME, DESCRIPTION, FAMILY, PASSWORD_HASH, PARTITION_TABLES, ARCHITECTURES, MEDIA,
PROVISIONING_TEMPLATES, PARAMETERS]
@api.resource(:operatingsystems).call(:index, {
:per_page => 999999,
:search => option_search
})['results'].each do |operatingsystem_id|
operatingsystem = @api.resource(:operatingsystems).call(:show, {:id => operatingsystem_id['id']})
name = build_os_name(operatingsystem['name'], operatingsystem['major'], operatingsystem['minor'])
description = operatingsystem['description']
family = operatingsystem['family']
password_hash = operatingsystem['password_hash']
partition_tables = export_column(operatingsystem, 'ptables', 'name')
architectures = export_column(operatingsystem, 'architectures', 'name')
media = export_column(operatingsystem, 'media', 'name')
partition_tables = export_column(operatingsystem, 'ptables', 'name')
parameters = export_column(operatingsystem, 'parameters') do |parameter|
"#{parameter['name']}|#{parameter['value']}"
end
csv << [name, description, family, password_hash, partition_tables, architectures,
media, partition_tables, parameters]
end
end
|
#import ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/hammer_cli_csv/operating_systems.rb', line 40
def import
@existing = {}
@api.resource(:operatingsystems).call(:index, {:per_page => 999999})['results'].each do |operatingsystem|
@existing[build_os_name(operatingsystem['name'], operatingsystem['major'], operatingsystem['minor'])] = operatingsystem['id'] if operatingsystem
end
thread_import do |line|
create_operatingsystems_from_csv(line)
end
end
|