Class: HammerCLICsv::CsvCommand::PartitionTablesCommand
- Inherits:
-
BaseCommand
- Object
- HammerCLI::Apipie::Command
- BaseCommand
- HammerCLICsv::CsvCommand::PartitionTablesCommand
show all
- Defined in:
- lib/hammer_cli_csv/partition_tables.rb
Constant Summary
collapse
- OSFAMILY =
'OS Family'
- OPERATINGSYSTEMS =
'Operating Systems'
- LAYOUT =
'Layout'
Constants inherited
from BaseCommand
BaseCommand::COUNT, BaseCommand::NAME
Instance Method Summary
collapse
Methods inherited from BaseCommand
#associate_locations, #associate_organizations, #build_os_name, #check_server_status, #collect_column, #execute, #export_column, #foreman_architecture, #foreman_domain, #foreman_environment, #foreman_filter, #foreman_location, #foreman_operatingsystem, #foreman_organization, #foreman_partitiontable, #foreman_permission, #foreman_role, #foreman_template_kind, #hammer, #hammer_context, #katello_contentview, #katello_hostcollection, #katello_repository, #katello_subscription, #labelize, #lifecycle_environment, #namify, #pluralize, #split_os_name, #thread_import
Instance Method Details
#create_ptables_from_csv(line) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/hammer_cli_csv/partition_tables.rb', line 63
def create_ptables_from_csv(line)
line[COUNT].to_i.times do |number|
name = namify(line[NAME], number)
operatingsystem_ids = CSV.parse_line(line[OPERATINGSYSTEMS]).collect do |operatingsystem_name|
foreman_operatingsystem(:name => operatingsystem_name)
end if line[OPERATINGSYSTEMS]
if !@existing.include? name
print "Creating ptable '#{name}'... " if option_verbose?
@api.resource(:ptables).call(:create, {
'ptable' => {
'name' => name,
'os_family' => line[OSFAMILY],
'operatingsystem_ids' => operatingsystem_ids,
'layout' => line[LAYOUT]
}
})
else
print "Updating ptable '#{name}'..." if option_verbose?
@api.resource(:ptables).call(:update, {
'id' => @existing[name],
'ptable' => {
'name' => name,
'os_family' => line[OSFAMILY],
'operatingsystem_ids' => operatingsystem_ids,
'layout' => line[LAYOUT]
}
})
end
print "done\n" if option_verbose?
end
rescue RuntimeError => e
raise "#{e}\n #{line}"
end
|
#export ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/hammer_cli_csv/partition_tables.rb', line 38
def export
CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
csv << [NAME, COUNT, OSFAMILY, OPERATINGSYSTEMS, LAYOUT]
@api.resource(:ptables).call(:index, {:per_page => 999999})['results'].each do |ptable|
ptable = @api.resource(:ptables).call(:show, {'id' => ptable['id']})
name = ptable['name']
count = 1
osfamily = ptable['os_family']
layout = ptable['layout']
csv << [name, count, osfamily, layout]
end
end
end
|
#import ⇒ Object
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/hammer_cli_csv/partition_tables.rb', line 52
def import
@existing = {}
@api.resource(:ptables).call(:index, {:per_page => 999999})['results'].each do |ptable|
@existing[ptable['name']] = ptable['id'] if ptable
end
thread_import do |line|
create_ptables_from_csv(line)
end
end
|