hammer_cli_csv 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/config/cli_config.yml +2 -0
- data/lib/hammer_cli_csv.rb +4 -11
- data/lib/hammer_cli_csv/activation_keys.rb +7 -21
- data/lib/hammer_cli_csv/architectures.rb +6 -37
- data/lib/hammer_cli_csv/base.rb +177 -21
- data/lib/hammer_cli_csv/compute_profiles.rb +4 -21
- data/lib/hammer_cli_csv/compute_resources.rb +4 -16
- data/lib/hammer_cli_csv/containers.rb +65 -0
- data/lib/hammer_cli_csv/content_hosts.rb +22 -26
- data/lib/hammer_cli_csv/content_view_filters.rb +90 -60
- data/lib/hammer_cli_csv/content_views.rb +4 -17
- data/lib/hammer_cli_csv/csv.rb +0 -12
- data/lib/hammer_cli_csv/domains.rb +74 -38
- data/lib/hammer_cli_csv/exception_handler.rb +0 -11
- data/lib/hammer_cli_csv/export.rb +14 -20
- data/lib/hammer_cli_csv/headpin_api.rb +0 -11
- data/lib/hammer_cli_csv/host_collections.rb +5 -23
- data/lib/hammer_cli_csv/host_groups.rb +115 -0
- data/lib/hammer_cli_csv/hosts.rb +32 -56
- data/lib/hammer_cli_csv/import.rb +46 -24
- data/lib/hammer_cli_csv/installation_medias.rb +4 -15
- data/lib/hammer_cli_csv/job_templates.rb +142 -0
- data/lib/hammer_cli_csv/lifecycle_environments.rb +5 -38
- data/lib/hammer_cli_csv/locations.rb +4 -33
- data/lib/hammer_cli_csv/operating_systems.rb +17 -33
- data/lib/hammer_cli_csv/organizations.rb +13 -41
- data/lib/hammer_cli_csv/partition_tables.rb +66 -54
- data/lib/hammer_cli_csv/products.rb +12 -24
- data/lib/hammer_cli_csv/provisioning_templates.rb +4 -18
- data/lib/hammer_cli_csv/puppet_environments.rb +36 -59
- data/lib/hammer_cli_csv/puppet_facts.rb +36 -58
- data/lib/hammer_cli_csv/puppet_reports.rb +4 -38
- data/lib/hammer_cli_csv/reports.rb +4 -15
- data/lib/hammer_cli_csv/roles.rb +4 -15
- data/lib/hammer_cli_csv/settings.rb +49 -0
- data/lib/hammer_cli_csv/smart_proxies.rb +9 -24
- data/lib/hammer_cli_csv/splice.rb +0 -12
- data/lib/hammer_cli_csv/subnets.rb +10 -21
- data/lib/hammer_cli_csv/subscriptions.rb +21 -24
- data/lib/hammer_cli_csv/sync_plans.rb +4 -19
- data/lib/hammer_cli_csv/users.rb +4 -15
- data/lib/hammer_cli_csv/version.rb +1 -12
- data/test/content_hosts_test.rb +1 -1
- data/test/content_views_test.rb +52 -0
- data/test/data/content-hosts.csv +1 -1
- data/test/data/content-view-filters.csv +1 -1
- data/test/data/content-views.csv +5 -5
- data/test/data/hosts.csv +2 -2
- data/test/data/operating-systems.csv +16 -16
- data/test/data/products.csv +1 -1
- data/test/data/settings.csv +5 -0
- data/test/import_test.rb +79 -0
- metadata +14 -18
@@ -1,20 +1,4 @@
|
|
1
|
-
# Copyright 2013-2014 Red Hat, Inc.
|
2
|
-
#
|
3
|
-
# This software is licensed to you under the GNU General Public
|
4
|
-
# License as published by the Free Software Foundation; either version
|
5
|
-
# 2 of the License (GPLv2) or (at your option) any later version.
|
6
|
-
# There is NO WARRANTY for this software, express or implied,
|
7
|
-
# including the implied warranties of MERCHANTABILITY,
|
8
|
-
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
|
9
|
-
# have received a copy of GPLv2 along with this software; if not, see
|
10
|
-
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
11
|
-
|
12
|
-
require 'hammer_cli'
|
13
|
-
require 'json'
|
14
|
-
require 'csv'
|
15
|
-
|
16
1
|
# TODO: waiting for https://github.com/theforeman/foreman/pull/1326
|
17
|
-
|
18
2
|
module HammerCLICsv
|
19
3
|
class CsvCommand
|
20
4
|
class ComputeProfilesCommand < BaseCommand
|
@@ -28,19 +12,18 @@ module HammerCLICsv
|
|
28
12
|
URL = 'URL'
|
29
13
|
|
30
14
|
def export
|
31
|
-
CSV.open(
|
32
|
-
csv << [NAME,
|
15
|
+
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
|
16
|
+
csv << [NAME, ORGANIZATIONS, LOCATIONS, DESCRIPTION, PROVIDER, URL]
|
33
17
|
@api.resource(:compute_profiles).call(:index, {:per_page => 999999})['results'].each do |compute_profile|
|
34
18
|
puts compute_profile
|
35
19
|
compute_profile = @api.resource(:compute_profiles).call(:show, {'id' => compute_profile['id']})
|
36
20
|
name = compute_profile['name']
|
37
|
-
count = 1
|
38
21
|
organizations = export_column(compute_profile, 'organizations', 'name')
|
39
22
|
locations = export_column(compute_profile, 'locations', 'name')
|
40
23
|
description = compute_profile['description']
|
41
24
|
provider = compute_profile['provider']
|
42
25
|
url = compute_profile['url']
|
43
|
-
csv << [name,
|
26
|
+
csv << [name, organizations, locations, description, provider, url]
|
44
27
|
end
|
45
28
|
end
|
46
29
|
end
|
@@ -57,7 +40,7 @@ module HammerCLICsv
|
|
57
40
|
end
|
58
41
|
|
59
42
|
def create_compute_profiles_from_csv(line)
|
60
|
-
line[COUNT].
|
43
|
+
count(line[COUNT]).times do |number|
|
61
44
|
name = namify(line[NAME], number)
|
62
45
|
if !@existing.include? name
|
63
46
|
print "Creating compute profile '#{name}'..." if option_verbose?
|
@@ -1,14 +1,3 @@
|
|
1
|
-
# Copyright 2013-2014 Red Hat, Inc.
|
2
|
-
#
|
3
|
-
# This software is licensed to you under the GNU General Public
|
4
|
-
# License as published by the Free Software Foundation; either version
|
5
|
-
# 2 of the License (GPLv2) or (at your option) any later version.
|
6
|
-
# There is NO WARRANTY for this software, express or implied,
|
7
|
-
# including the implied warranties of MERCHANTABILITY,
|
8
|
-
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
|
9
|
-
# have received a copy of GPLv2 along with this software; if not, see
|
10
|
-
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
11
|
-
|
12
1
|
require 'hammer_cli'
|
13
2
|
require 'json'
|
14
3
|
require 'csv'
|
@@ -26,19 +15,18 @@ module HammerCLICsv
|
|
26
15
|
URL = 'URL'
|
27
16
|
|
28
17
|
def export
|
29
|
-
CSV.open(
|
30
|
-
csv << [NAME,
|
18
|
+
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
|
19
|
+
csv << [NAME, ORGANIZATIONS, LOCATIONS, DESCRIPTION, PROVIDER, URL]
|
31
20
|
@api.resource(:compute_resources).call(:index, {:per_page => 999999})['results'].each do |compute_resource|
|
32
21
|
compute_resource = @api.resource(:compute_resources).call(:show, {'id' => compute_resource['id']})
|
33
22
|
|
34
23
|
name = compute_resource['name']
|
35
|
-
count = 1
|
36
24
|
organizations = export_column(compute_resource, 'organizations', 'name')
|
37
25
|
locations = export_column(compute_resource, 'locations', 'name')
|
38
26
|
description = compute_resource['description']
|
39
27
|
provider = compute_resource['provider']
|
40
28
|
url = compute_resource['url']
|
41
|
-
csv << [name,
|
29
|
+
csv << [name, organizations, locations, description, provider, url]
|
42
30
|
end
|
43
31
|
end
|
44
32
|
end
|
@@ -55,7 +43,7 @@ module HammerCLICsv
|
|
55
43
|
end
|
56
44
|
|
57
45
|
def create_compute_resources_from_csv(line)
|
58
|
-
line[COUNT].
|
46
|
+
count(line[COUNT]).times do |number|
|
59
47
|
name = namify(line[NAME], number)
|
60
48
|
if !@existing.include? name
|
61
49
|
print "Creating compute resource '#{name}'..." if option_verbose?
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module HammerCLICsv
|
2
|
+
class CsvCommand
|
3
|
+
class ContainersCommand < BaseCommand
|
4
|
+
command_name 'containers'
|
5
|
+
desc 'import or export containers'
|
6
|
+
|
7
|
+
REGISTRY = 'Registry'
|
8
|
+
REPOSITORY = 'Repository:Tag'
|
9
|
+
COMPUTERESOURCE = 'Compute Resource'
|
10
|
+
ATTACH = 'Attach I/O'
|
11
|
+
ENTRYPOINT = 'Entry Point'
|
12
|
+
COMMAND = 'Command'
|
13
|
+
|
14
|
+
def export
|
15
|
+
CSV.open(option_file || '/dev/stdout', 'wb') do |csv|
|
16
|
+
csv << [NAME, REGISTRY, REPOSITORY, COMPUTERESOURCE, ATTACH, ENTRYPOINT, COMMAND]
|
17
|
+
@api.resource(:containers).call(:index, {'per_page' => 999999})['results'].each do |container|
|
18
|
+
csv << [container['name'],
|
19
|
+
container['registry_name'],
|
20
|
+
"#{container['repository_name']}:#{container['tag']}",
|
21
|
+
container['compute_resource_name'],
|
22
|
+
export_attach_types(container),
|
23
|
+
container['entrypoint'],
|
24
|
+
container['command']]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def import
|
30
|
+
@existing = {}
|
31
|
+
|
32
|
+
thread_import do |line|
|
33
|
+
create_containers_from_csv(line)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_containers_from_csv(line)
|
38
|
+
# TODO: containers cannot be updated (no api)
|
39
|
+
# count(line[COUNT]).times do |number|
|
40
|
+
# name = namify(line[NAME], number)
|
41
|
+
# params = { 'id' => foreman_container(:name => name),
|
42
|
+
# 'container' => {
|
43
|
+
# 'name' => name,
|
44
|
+
# 'command' => line[COMMAND]
|
45
|
+
# }
|
46
|
+
# }
|
47
|
+
# print "Updating container '#{name}'..." if option_verbose?
|
48
|
+
# @api.resource(:containers).call(:update, params)
|
49
|
+
# end
|
50
|
+
# print "done\n" if option_verbose?
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def export_attach_types(container)
|
56
|
+
types = []
|
57
|
+
types << 'tty' if container['tty']
|
58
|
+
types << 'stdin' if container['attach_stdin']
|
59
|
+
types << 'stdout' if container['attach_stdout']
|
60
|
+
types << 'stderr' if container['attach_stderr']
|
61
|
+
types.join(',')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -1,14 +1,3 @@
|
|
1
|
-
# Copyright 2013-2014 Red Hat, Inc.
|
2
|
-
#
|
3
|
-
# This software is licensed to you under the GNU General Public
|
4
|
-
# License as published by the Free Software Foundation; either version
|
5
|
-
# 2 of the License (GPLv2) or (at your option) any later version.
|
6
|
-
# There is NO WARRANTY for this software, express or implied,
|
7
|
-
# including the implied warranties of MERCHANTABILITY,
|
8
|
-
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
|
9
|
-
# have received a copy of GPLv2 along with this software; if not, see
|
10
|
-
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
11
|
-
|
12
1
|
module HammerCLICsv
|
13
2
|
class CsvCommand
|
14
3
|
class ContentHostsCommand < BaseCommand
|
@@ -17,8 +6,6 @@ module HammerCLICsv
|
|
17
6
|
command_name 'content-hosts'
|
18
7
|
desc 'import or export content hosts'
|
19
8
|
|
20
|
-
option %w(--organization), 'ORGANIZATION', 'Only process organization matching this name'
|
21
|
-
|
22
9
|
ORGANIZATION = 'Organization'
|
23
10
|
ENVIRONMENT = 'Environment'
|
24
11
|
CONTENTVIEW = 'Content View'
|
@@ -35,8 +22,8 @@ module HammerCLICsv
|
|
35
22
|
SUBSCRIPTIONS = 'Subscriptions'
|
36
23
|
|
37
24
|
def export
|
38
|
-
CSV.open(
|
39
|
-
csv << [NAME,
|
25
|
+
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
|
26
|
+
csv << [NAME, ORGANIZATION, ENVIRONMENT, CONTENTVIEW, HOSTCOLLECTIONS, VIRTUAL, HOST,
|
40
27
|
OPERATINGSYSTEM, ARCHITECTURE, SOCKETS, RAM, CORES, SLA, PRODUCTS, SUBSCRIPTIONS]
|
41
28
|
if @server_status['release'] == 'Headpin'
|
42
29
|
export_sam csv
|
@@ -63,7 +50,6 @@ module HammerCLICsv
|
|
63
50
|
host_subscriptions = @headpin.get("systems/#{host_id}/subscriptions")['entitlements']
|
64
51
|
|
65
52
|
name = host['name']
|
66
|
-
count = 1
|
67
53
|
organization_name = host['owner']['displayName']
|
68
54
|
environment = host['environment']['name']
|
69
55
|
contentview = host['content_view']['name']
|
@@ -95,7 +81,7 @@ module HammerCLICsv
|
|
95
81
|
end
|
96
82
|
subscriptions.delete!("\n")
|
97
83
|
|
98
|
-
csv << [name,
|
84
|
+
csv << [name, organization_name, environment, contentview, hostcollections, virtual, hypervisor,
|
99
85
|
operatingsystem, architecture, sockets, ram, cores, sla, products, subscriptions]
|
100
86
|
end
|
101
87
|
end
|
@@ -114,7 +100,6 @@ module HammerCLICsv
|
|
114
100
|
})
|
115
101
|
|
116
102
|
name = host['name']
|
117
|
-
count = 1
|
118
103
|
organization_name = organization['name']
|
119
104
|
environment = host['environment']['label']
|
120
105
|
contentview = host['content_view']['name']
|
@@ -148,7 +133,7 @@ module HammerCLICsv
|
|
148
133
|
end
|
149
134
|
end
|
150
135
|
subscriptions.delete!("\n")
|
151
|
-
csv << [name,
|
136
|
+
csv << [name, organization_name, environment, contentview, hostcollections, virtual, hypervisor_host,
|
152
137
|
operatingsystem, architecture, sockets, ram, cores, sla, products, subscriptions]
|
153
138
|
end
|
154
139
|
end
|
@@ -164,7 +149,7 @@ module HammerCLICsv
|
|
164
149
|
end
|
165
150
|
|
166
151
|
def import_remotely
|
167
|
-
params = {'content' => ::File.new(::File.expand_path(
|
152
|
+
params = {'content' => ::File.new(::File.expand_path(option_file), 'rb')}
|
168
153
|
headers = {:content_type => 'multipart/form-data', :multipart => true}
|
169
154
|
task_progress(@api.resource(:csv).call(:import_content_hosts, params, headers))
|
170
155
|
end
|
@@ -185,8 +170,8 @@ module HammerCLICsv
|
|
185
170
|
'guest_ids' => guest_ids
|
186
171
|
})
|
187
172
|
end
|
173
|
+
puts _('done') if option_verbose?
|
188
174
|
end
|
189
|
-
puts _('done') if option_verbose?
|
190
175
|
end
|
191
176
|
|
192
177
|
def create_content_hosts_from_csv(line)
|
@@ -204,7 +189,7 @@ module HammerCLICsv
|
|
204
189
|
(total / 20 + 2).to_i.times do |page|
|
205
190
|
@api.resource(:systems).call(:index, {
|
206
191
|
'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
|
207
|
-
'page' => page,
|
192
|
+
'page' => page + 1,
|
208
193
|
'per_page' => 20
|
209
194
|
})['results'].each do |host|
|
210
195
|
@existing[line[ORGANIZATION]][host['name']] = host['uuid'] if host
|
@@ -212,7 +197,7 @@ module HammerCLICsv
|
|
212
197
|
end
|
213
198
|
end
|
214
199
|
|
215
|
-
line[COUNT].
|
200
|
+
count(line[COUNT]).times do |number|
|
216
201
|
name = namify(line[NAME], number)
|
217
202
|
|
218
203
|
if !@existing[line[ORGANIZATION]].include? name
|
@@ -314,10 +299,9 @@ module HammerCLICsv
|
|
314
299
|
end
|
315
300
|
|
316
301
|
def update_subscriptions(host_id, line)
|
317
|
-
existing_subscriptions = @api.resource(:
|
318
|
-
'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
|
302
|
+
existing_subscriptions = @api.resource(:systems).call(:subscriptions, {
|
319
303
|
'per_page' => 999999,
|
320
|
-
'
|
304
|
+
'id' => host_id
|
321
305
|
})['results']
|
322
306
|
if existing_subscriptions.length > 0
|
323
307
|
@api.resource(:subscriptions).call(:destroy, {
|
@@ -326,6 +310,18 @@ module HammerCLICsv
|
|
326
310
|
})
|
327
311
|
end
|
328
312
|
|
313
|
+
# existing_subscriptions = @api.resource(:subscriptions).call(:index, {
|
314
|
+
# 'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
|
315
|
+
# 'per_page' => 999999,
|
316
|
+
# 'system_id' => host_id
|
317
|
+
# })['results']
|
318
|
+
# if existing_subscriptions.length > 0
|
319
|
+
# @api.resource(:subscriptions).call(:destroy, {
|
320
|
+
# 'system_id' => host_id,
|
321
|
+
# 'id' => existing_subscriptions[0]['id']
|
322
|
+
# })
|
323
|
+
# end
|
324
|
+
|
329
325
|
return if line[SUBSCRIPTIONS].nil? || line[SUBSCRIPTIONS].empty?
|
330
326
|
|
331
327
|
subscriptions = CSV.parse_line(line[SUBSCRIPTIONS], {:skip_blanks => true}).collect do |details|
|
@@ -1,14 +1,3 @@
|
|
1
|
-
# Copyright 2013-2014 Red Hat, Inc.
|
2
|
-
#
|
3
|
-
# This software is licensed to you under the GNU General Public
|
4
|
-
# License as published by the Free Software Foundation; either version
|
5
|
-
# 2 of the License (GPLv2) or (at your option) any later version.
|
6
|
-
# There is NO WARRANTY for this software, express or implied,
|
7
|
-
# including the implied warranties of MERCHANTABILITY,
|
8
|
-
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
|
9
|
-
# have received a copy of GPLv2 along with this software; if not, see
|
10
|
-
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
|
11
|
-
|
12
1
|
# NOTE:
|
13
2
|
# rpm -qa --queryformat "%{NAME}|=|%{VERSION}-%{RELEASE},"
|
14
3
|
|
@@ -18,8 +7,6 @@ module HammerCLICsv
|
|
18
7
|
command_name 'content-view-filters'
|
19
8
|
desc 'import or export content-view-filters'
|
20
9
|
|
21
|
-
option %w(--organization), 'ORGANIZATION', 'Only process organization matching this name'
|
22
|
-
|
23
10
|
CONTENTVIEW = 'Content View'
|
24
11
|
ORGANIZATION = 'Organization'
|
25
12
|
DESCRIPTION = 'Description'
|
@@ -28,14 +15,13 @@ module HammerCLICsv
|
|
28
15
|
RULES = 'Rules'
|
29
16
|
|
30
17
|
def export
|
31
|
-
CSV.open(
|
32
|
-
csv << [NAME,
|
18
|
+
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
|
19
|
+
csv << [NAME, CONTENTVIEW, ORGANIZATION, TYPE, DESCRIPTION, REPOSITORIES, RULES]
|
33
20
|
@api.resource(:organizations).call(:index, {
|
34
21
|
:per_page => 999999
|
35
22
|
})['results'].each do |organization|
|
36
23
|
next if option_organization && organization['name'] != option_organization
|
37
24
|
|
38
|
-
composite_contentviews = []
|
39
25
|
@api.resource(:content_views).call(:index, {
|
40
26
|
'per_page' => 999999,
|
41
27
|
'organization_id' => organization['id'],
|
@@ -44,34 +30,23 @@ module HammerCLICsv
|
|
44
30
|
@api.resource(:content_view_filters).call(:index, {
|
45
31
|
'content_view_id' => contentview['id']
|
46
32
|
})['results'].collect do |filter|
|
47
|
-
filter_type = "#{filter['inclusion'] == true ? 'Include' : 'Exclude'} #{filter['type']}"
|
33
|
+
filter_type = "#{filter['inclusion'] == true ? 'Include' : 'Exclude'} #{export_filter_type(filter['type'])}"
|
48
34
|
|
35
|
+
rules = nil
|
49
36
|
case filter['type']
|
50
37
|
when /rpm/
|
51
|
-
rules =
|
52
|
-
column << filter['rules'].collect do |rule|
|
53
|
-
if rule['version']
|
54
|
-
"#{rule['name']}|=|#{rule['version']}"
|
55
|
-
elsif rule['min_version'] && rule['max_version']
|
56
|
-
"#{rule['name']}|-|#{rule['min_version']},#{rule['max_version']}"
|
57
|
-
elsif rule['min_version']
|
58
|
-
"#{rule['name']}|>|#{rule['min_version']}"
|
59
|
-
elsif rule['max_version']
|
60
|
-
"#{rule['name']}|<|#{rule['max_version']}"
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
rules.delete!("\n")
|
38
|
+
rules = export_rpm_rules(filter)
|
65
39
|
when /erratum/
|
40
|
+
rules = export_erratum_rules(filter)
|
66
41
|
when /package_group/
|
42
|
+
rules = export_package_group_rules(filter)
|
67
43
|
else
|
68
44
|
raise "Unknown filter rule type '#{filter['type']}'"
|
69
45
|
end
|
70
|
-
#puts "#{filter['type']} -> #{rule}"
|
71
46
|
|
72
|
-
name =
|
47
|
+
name = filter['name']
|
73
48
|
repositories = export_column(filter, 'repositories', 'name')
|
74
|
-
csv << [name,
|
49
|
+
csv << [name, contentview['name'], organization['name'], filter_type, filter['description'],
|
75
50
|
repositories, rules]
|
76
51
|
end
|
77
52
|
end
|
@@ -87,6 +62,7 @@ module HammerCLICsv
|
|
87
62
|
end
|
88
63
|
end
|
89
64
|
|
65
|
+
# rubocop:disable CyclomaticComplexity
|
90
66
|
def create_filters_from_csv(line)
|
91
67
|
return if option_organization && line[ORGANIZATION] != option_organization
|
92
68
|
|
@@ -105,40 +81,39 @@ module HammerCLICsv
|
|
105
81
|
katello_repository(line[ORGANIZATION], :name => repository)
|
106
82
|
end
|
107
83
|
|
108
|
-
line[COUNT].
|
109
|
-
|
84
|
+
count(line[COUNT]).times do |number|
|
85
|
+
filter_name = namify(line[NAME], number)
|
110
86
|
|
111
|
-
filter_id = @existing_filters[line[ORGANIZATION]][line[CONTENTVIEW]][
|
87
|
+
filter_id = @existing_filters[line[ORGANIZATION]][line[CONTENTVIEW]][filter_name]
|
88
|
+
filter_type = import_filter_type(line[TYPE])
|
112
89
|
if !filter_id
|
113
|
-
print "Creating filter '#{
|
90
|
+
print "Creating filter '#{filter_name}' for content view filter '#{line[CONTENTVIEW]}'..." if option_verbose?
|
114
91
|
filter_id = @api.resource(:content_view_filters).call(:create, {
|
115
92
|
'content_view_id' => katello_contentview(line[ORGANIZATION], :name => line[CONTENTVIEW]),
|
116
|
-
'name' =>
|
93
|
+
'name' => filter_name,
|
117
94
|
'description' => line[DESCRIPTION],
|
118
|
-
'type' => filter_type
|
95
|
+
'type' => filter_type,
|
119
96
|
'inclusion' => filter_inclusion?(line[TYPE]),
|
120
97
|
'repository_ids' => repository_ids
|
121
98
|
})['id']
|
122
|
-
@existing_filters[line[ORGANIZATION]][
|
99
|
+
@existing_filters[line[ORGANIZATION]][filter_name] = filter_id
|
123
100
|
else
|
124
|
-
print "Updating filter '#{
|
101
|
+
print "Updating filter '#{filter_name}' for content view filter '#{line[CONTENTVIEW]}'..." if option_verbose?
|
125
102
|
@api.resource(:content_view_filters).call(:update, {
|
126
103
|
'id' => filter_id,
|
127
104
|
'description' => line[DESCRIPTION],
|
128
|
-
'type' => filter_type
|
105
|
+
'type' => filter_type,
|
129
106
|
'inclusion' => filter_inclusion?(line[TYPE]),
|
130
107
|
'repository_ids' => repository_ids
|
131
108
|
})
|
132
109
|
end
|
133
110
|
|
134
|
-
|
135
|
-
@existing_rules[line[ORGANIZATION]] ||= {}
|
136
|
-
@existing_rules[line[ORGANIZATION]][line[CONTENTVIEW]] ||= {}
|
111
|
+
existing_rules = {}
|
137
112
|
@api.resource(:content_view_filter_rules).call(:index, {
|
138
113
|
'per_page' => 999999,
|
139
114
|
'content_view_filter_id' => filter_id
|
140
115
|
})['results'].each do |rule|
|
141
|
-
|
116
|
+
existing_rules[rule['name']] = rule
|
142
117
|
end
|
143
118
|
|
144
119
|
collect_column(line[RULES]) do |rule|
|
@@ -147,29 +122,29 @@ module HammerCLICsv
|
|
147
122
|
'content_view_filter_id' => filter_id,
|
148
123
|
'name' => name
|
149
124
|
}
|
150
|
-
if type == '
|
151
|
-
|
152
|
-
|
125
|
+
if type == 'all'
|
126
|
+
# empty
|
127
|
+
elsif type == '='
|
128
|
+
params['version'] = version
|
153
129
|
elsif type == '<'
|
154
|
-
params['
|
155
|
-
params['max_version'] = version
|
130
|
+
params['max_version'] = version
|
156
131
|
elsif type == '>'
|
157
|
-
params['
|
158
|
-
params['min_version'] = version
|
132
|
+
params['min_version'] = version
|
159
133
|
elsif type == '-'
|
160
|
-
|
161
|
-
min_version, max_version = version.split(',')
|
134
|
+
min_version, max_version = version.split(',')
|
162
135
|
params['min_version'] = min_version
|
163
136
|
params['max_version'] = max_version
|
137
|
+
elsif filter_type == 'package_group'
|
138
|
+
params['uuid'] = name # TODO: this is not right
|
164
139
|
else
|
165
140
|
raise "Unknown type '#{type}' from '#{line[RULES]}'"
|
166
141
|
end
|
167
142
|
|
168
|
-
rule =
|
143
|
+
rule = existing_rules[name]
|
169
144
|
if !rule
|
170
145
|
print "." if option_verbose?
|
171
146
|
rule = @api.resource(:content_view_filter_rules).call(:create, params)
|
172
|
-
|
147
|
+
existing_rules[rule['name']] = rule
|
173
148
|
else
|
174
149
|
print "." if option_verbose?
|
175
150
|
params['id'] = rule['id']
|
@@ -186,9 +161,23 @@ module HammerCLICsv
|
|
186
161
|
|
187
162
|
private
|
188
163
|
|
189
|
-
def
|
190
|
-
|
164
|
+
def import_filter_type(type)
|
165
|
+
case type.split[1..-1].join(' ')
|
166
|
+
when /packages/i
|
191
167
|
'rpm'
|
168
|
+
when /package groups/i
|
169
|
+
'package_group'
|
170
|
+
else
|
171
|
+
'unknown'
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def export_filter_type(type)
|
176
|
+
case type.split[1]
|
177
|
+
when /rpm/i
|
178
|
+
'Packages'
|
179
|
+
when /package_group/i
|
180
|
+
'Package Groups'
|
192
181
|
else
|
193
182
|
'unknown'
|
194
183
|
end
|
@@ -201,6 +190,47 @@ module HammerCLICsv
|
|
201
190
|
false
|
202
191
|
end
|
203
192
|
end
|
193
|
+
|
194
|
+
def export_rpm_rules(filter)
|
195
|
+
rules = CSV.generate do |column|
|
196
|
+
column << filter['rules'].collect do |rule|
|
197
|
+
if rule['version']
|
198
|
+
"#{rule['name']}|=|#{rule['version']}"
|
199
|
+
elsif rule['min_version'] && rule['max_version']
|
200
|
+
"#{rule['name']}|-|#{rule['min_version']},#{rule['max_version']}"
|
201
|
+
elsif rule['min_version']
|
202
|
+
"#{rule['name']}|>|#{rule['min_version']}"
|
203
|
+
elsif rule['max_version']
|
204
|
+
"#{rule['name']}|<|#{rule['max_version']}"
|
205
|
+
else
|
206
|
+
"#{rule['name']}|all"
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
rules.delete!("\n")
|
211
|
+
end
|
212
|
+
|
213
|
+
def export_erratum_rules(filter)
|
214
|
+
rules = CSV.generate do |column|
|
215
|
+
rule = filter['rules'][0]
|
216
|
+
conditions = []
|
217
|
+
conditions << "start = #{DateTime.parse(rule['start_date']).strftime('%F')}" if rule['start_date']
|
218
|
+
conditions << "end = #{DateTime.parse(rule['end_date']).strftime('%F')}" if rule['end_date']
|
219
|
+
conditions << "types = #{rule['types'].join(',')}" if rule['types']
|
220
|
+
conditions << "errata = #{rule['errata_id']}" if rule['errata_id']
|
221
|
+
column << conditions
|
222
|
+
end
|
223
|
+
rules.delete!("\n")
|
224
|
+
end
|
225
|
+
|
226
|
+
def export_package_group_rules(filter)
|
227
|
+
rules = CSV.generate do |column|
|
228
|
+
column << filter['rules'].collect do |rule|
|
229
|
+
rule['name']
|
230
|
+
end
|
231
|
+
end
|
232
|
+
rules.delete!("\n")
|
233
|
+
end
|
204
234
|
end
|
205
235
|
end
|
206
236
|
end
|