Class: HammerCLICsv::CsvCommand::ArchitecturesCommand
- Inherits:
-
BaseCommand
- Object
- HammerCLI::Apipie::Command
- BaseCommand
- HammerCLICsv::CsvCommand::ArchitecturesCommand
show all
- Defined in:
- lib/hammer_cli_csv/architectures.rb
Constant Summary
collapse
- OPERATINGSYSTEMS =
'Operating Systems'
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_architectures_from_csv(line) ⇒ Object
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
|
# File 'lib/hammer_cli_csv/architectures.rb', line 33
def create_architectures_from_csv(line)
count(line[COUNT]).times do |number|
name = namify(line[NAME], number)
architecture_id = @existing[name]
operatingsystem_ids = CSV.parse_line(line[OPERATINGSYSTEMS]).collect do |operatingsystem_name|
foreman_operatingsystem(:name => operatingsystem_name)
end
if !architecture_id
print "Creating architecture '#{name}'..." if option_verbose?
architecture_id = @api.resource(:architectures).call(:create, {
'architecture' => {
'name' => name,
'operatingsystem_ids' => operatingsystem_ids
}
})
else
print "Updating architecture '#{name}'..." if option_verbose?
@api.resource(:architectures).call(:update, {
'id' => architecture_id,
'architecture' => {
'name' => name,
'operatingsystem_ids' => operatingsystem_ids
}
})
end
print "done\n" if option_verbose?
end
end
|
#export(csv) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/hammer_cli_csv/architectures.rb', line 9
def export(csv)
csv << [NAME, OPERATINGSYSTEMS]
@api.resource(:architectures).call(:index, {
:per_page => 999999,
:search => option_search
})['results'].each do |architecture|
architecture = @api.resource(:architectures).call(:show, {:id => architecture['id']})
name = architecture['name']
operatingsystems = export_column(architecture, 'operatingsystems', 'title')
csv << [name, operatingsystems]
end
end
|
#import ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/hammer_cli_csv/architectures.rb', line 22
def import
@existing = {}
@api.resource(:architectures).call(:index, {:per_page => 999999})['results'].each do |architecture|
@existing[architecture['name']] = architecture['id'] if architecture
end
thread_import do |line|
create_architectures_from_csv(line)
end
end
|