Class: HammerCLICsv::CsvCommand::SubscriptionsCommand
- Inherits:
-
BaseCommand
- Object
- HammerCLI::Apipie::Command
- BaseCommand
- HammerCLICsv::CsvCommand::SubscriptionsCommand
show all
- Defined in:
- lib/hammer_cli_csv/subscriptions.rb
Constant Summary
collapse
- ORGANIZATION =
'Organization'
- MANIFEST =
'Manifest File'
- CONTENT_SET =
'Content Set'
- ARCH =
'Arch'
- RELEASE =
'Release'
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_contentviewversion, #katello_hostcollection, #katello_product, #katello_repository, #katello_subscription, #labelize, #lifecycle_environment, #namify, #pluralize, #split_os_name, #thread_import
Instance Method Details
#enable_products_from_csv(line) ⇒ Object
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/hammer_cli_csv/subscriptions.rb', line 68
def enable_products_from_csv(line)
return if option_organization && line[ORGANIZATION] != option_organization
results = @api.resource(:products).call(:index, {
'per_page' => 999999,
'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
'name' => line[NAME]
})['results']
raise "No match for product '#{line[NAME]}'" if results.length == 0
raise "Multiple matches for product '#{line[NAME]}'" if results.length != 1
product = results[0]
results = @api.resource(:repository_sets).call(:index, {
'per_page' => 999999,
'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
'product_id' => product['id'],
'name' => line[CONTENT_SET]
})['results']
raise "No match for content set '#{line[CONTENT_SET]}'" if results.length == 0
raise "Multiple matches for content set '#{line[CONTENT_SET]}'" if results.length != 1
repository_set = results[0]
repository = repository_set['repositories'].find do |repo|
repo['name'].end_with?("#{line[ARCH]} #{line[RELEASE]}")
end
if repository.nil?
print "Enabling repository #{line[CONTENT_SET]} #{line[ARCH]} #{line[RELEASE]}..." if option_verbose?
product_content = product['product_content'].find do |content|
content['content']['name'] == line[CONTENT_SET]
end
raise "No match for content set '#{line[CONTENT_SET]}'" if !product_content
@api.resource(:repository_sets).call(:enable, {
'id' => product_content['content']['id'],
'product_id' => product['id'],
'basearch' => line[ARCH],
'releasever' => line[RELEASE]
})
puts 'done' if option_verbose?
else
puts "Repository #{repository['name']} already enabled" if option_verbose?
end
end
|
#export ⇒ Object
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
|
# File 'lib/hammer_cli_csv/subscriptions.rb', line 27
def export
CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
csv << [NAME, COUNT, ORGANIZATION, MANIFEST, CONTENT_SET, ARCH, RELEASE]
@api.resource(:organizations).call(:index, {:per_page => 999999})['results'].each do |organization|
next if option_organization && organization['name'] != option_organization
@api.resource(:products).call(:index, {
'per_page' => 999999,
'organization_id' => organization['id'],
'enabled' => true
})['results'].each do |product|
if product['provider']['name'] == 'Red Hat'
name = product['name']
@api.resource(:repository_sets).call(:index, {
'per_page' => 999999,
'organization_id' => organization['id'],
'product_id' => product['id']
})['results'].each do |repository_set|
content_set = repository_set['name']
repository_set['repositories'].each do |repository|
name_split = repository['name'].split(' ')
arch = name_split[-2]
release = name_split[-1]
csv << [name, 1, organization['name'], nil, content_set, arch, release]
end
end
end
end
end
end
end
|
#import ⇒ Object
58
59
60
61
62
63
64
65
66
|
# File 'lib/hammer_cli_csv/subscriptions.rb', line 58
def import
thread_import do |line|
if line[MANIFEST] && !line[MANIFEST].empty?
import_manifest_from_csv(line)
else
enable_products_from_csv(line)
end
end
end
|
#import_manifest_from_csv(line) ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/hammer_cli_csv/subscriptions.rb', line 113
def import_manifest_from_csv(line)
args = %W{
--server #{ @server } --username #{ @username } --password #{ @password }
subscription upload --file #{ line[MANIFEST] }
--organization-id #{ foreman_organization(:name => line[ORGANIZATION]) }
}
hammer.run(args)
rescue RuntimeError => e
raise "#{e}\n #{line}"
end
|