Class: HammerCLICsv::CsvCommand::ContentViewsCommand
- Inherits:
-
BaseCommand
- Object
- HammerCLI::Apipie::Command
- BaseCommand
- HammerCLICsv::CsvCommand::ContentViewsCommand
show all
- Defined in:
- lib/hammer_cli_csv/content_views.rb
Constant Summary
collapse
- ORGANIZATION =
'Organization'
- DESCRIPTION =
'Description'
- COMPOSITE =
'Composite'
- REPOSITORIES =
'Repositories'
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_contentviews_from_csv(line) ⇒ Object
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
75
76
77
78
79
80
81
82
83
|
# File 'lib/hammer_cli_csv/content_views.rb', line 35
def create_contentviews_from_csv(line)
if !@existing_contentviews[line[ORGANIZATION]]
@existing_contentviews[line[ORGANIZATION]] ||= {}
@api.resource(:content_views)\
.call(:index, {
'per_page' => 999999,
'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
'nondefault' => true
})['results'].each do |contentview|
@existing_contentviews[line[ORGANIZATION]][contentview['name']] = contentview['id'] if contentview
end
end
repository_ids = collect_column(line[REPOSITORIES]) do |repository|
katello_repository(line[ORGANIZATION], :name => repository)
end
line[COUNT].to_i.times do |number|
name = namify(line[NAME], number)
composite = line[COMPOSITE] == 'Yes' ? true : false
contentview_id = @existing_contentviews[line[ORGANIZATION]][name]
if !contentview_id
print "Creating content view '#{name}'..." if option_verbose?
contentview_id = @api.resource(:content_views)\
.call(:create, {
'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
'name' => name,
'label' => labelize(name),
'description' => line[DESCRIPTION],
'composite' => composite,
'repository_ids' => repository_ids
})['id']
@existing_contentviews[line[ORGANIZATION]][name] = contentview_id
else
print "Updating content view '#{name}'..." if option_verbose?
@api.resource(:content_views)\
.call(:update, {
'id' => contentview_id,
'description' => line[DESCRIPTION],
'repository_ids' => repository_ids
})
end
puts 'done' if option_verbose?
end
rescue RuntimeError => e
raise "#{e}\n #{line}"
end
|
#export ⇒ Object
23
24
25
|
# File 'lib/hammer_cli_csv/content_views.rb', line 23
def export
end
|
#import ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/hammer_cli_csv/content_views.rb', line 27
def import
@existing_contentviews = {}
thread_import do |line|
create_contentviews_from_csv(line)
end
end
|