hammer_cli_csv 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/config/cli_config.yml +9 -24
- data/lib/hammer_cli_csv/activation_keys.rb +220 -95
- data/lib/hammer_cli_csv/architectures.rb +7 -11
- data/lib/hammer_cli_csv/base.rb +67 -41
- data/lib/hammer_cli_csv/compute_profiles.rb +11 -15
- data/lib/hammer_cli_csv/compute_resources.rb +11 -15
- data/lib/hammer_cli_csv/containers.rb +10 -12
- data/lib/hammer_cli_csv/content_hosts.rb +285 -203
- data/lib/hammer_cli_csv/content_view_filters.rb +32 -36
- data/lib/hammer_cli_csv/content_views.rb +33 -37
- data/lib/hammer_cli_csv/csv.rb +17 -1
- data/lib/hammer_cli_csv/domains.rb +15 -19
- data/lib/hammer_cli_csv/export.rb +13 -5
- data/lib/hammer_cli_csv/host_collections.rb +20 -22
- data/lib/hammer_cli_csv/host_groups.rb +73 -65
- data/lib/hammer_cli_csv/hosts.rb +30 -34
- data/lib/hammer_cli_csv/import.rb +24 -10
- data/lib/hammer_cli_csv/installation_media.rb +74 -0
- data/lib/hammer_cli_csv/job_templates.rb +37 -41
- data/lib/hammer_cli_csv/lifecycle_environments.rb +15 -19
- data/lib/hammer_cli_csv/locations.rb +4 -6
- data/lib/hammer_cli_csv/operating_systems.rb +17 -21
- data/lib/hammer_cli_csv/organizations.rb +11 -13
- data/lib/hammer_cli_csv/partition_tables.rb +17 -21
- data/lib/hammer_cli_csv/products.rb +200 -92
- data/lib/hammer_cli_csv/provisioning_templates.rb +19 -23
- data/lib/hammer_cli_csv/puppet_environments.rb +8 -12
- data/lib/hammer_cli_csv/puppet_facts.rb +20 -24
- data/lib/hammer_cli_csv/puppet_reports.rb +47 -51
- data/lib/hammer_cli_csv/reports.rb +6 -10
- data/lib/hammer_cli_csv/roles.rb +12 -16
- data/lib/hammer_cli_csv/settings.rb +8 -6
- data/lib/hammer_cli_csv/smart_proxies.rb +9 -13
- data/lib/hammer_cli_csv/splice.rb +1 -3
- data/lib/hammer_cli_csv/subnets.rb +24 -28
- data/lib/hammer_cli_csv/subscriptions.rb +39 -91
- data/lib/hammer_cli_csv/sync_plans.rb +20 -24
- data/lib/hammer_cli_csv/users.rb +25 -29
- data/lib/hammer_cli_csv/utils/subscriptions.rb +130 -0
- data/lib/hammer_cli_csv/version.rb +1 -1
- data/lib/hammer_cli_csv.rb +2 -2
- data/test/csv_test.rb +32 -0
- data/test/csv_test_helper.rb +17 -2
- data/test/data/content-hosts.csv +3 -2
- data/test/data/hosts.csv +0 -11
- data/test/data/settings.csv +1 -0
- data/test/data/setup/content-hosts.csv +1 -0
- data/test/data/setup/content-views.csv +2 -0
- data/test/data/setup/lifecycle-environments.csv +5 -0
- data/test/data/setup/locations.csv +6 -0
- data/test/data/setup/organizations.csv +2 -0
- data/test/data/setup/subscriptions.csv +5 -0
- data/test/data/subscriptions.csv +15 -17
- data/test/export_test.rb +27 -0
- data/test/fixtures/vcr_cassettes/apipie.yml +18528 -0
- data/test/fixtures/vcr_cassettes/resources/activation_keys_import/create_and_update.yml +38033 -0
- data/test/fixtures/vcr_cassettes/resources/content_hosts_export/export.yml +18846 -0
- data/test/fixtures/vcr_cassettes/resources/content_hosts_export/export_subscriptions.yml +323 -0
- data/test/fixtures/vcr_cassettes/resources/content_hosts_import/create_and_update.yml +41884 -0
- data/test/fixtures/vcr_cassettes/resources/content_hosts_import/import_single_line.yml +38248 -0
- data/test/fixtures/vcr_cassettes/resources/settings_import/update_settings.yml +18832 -0
- data/test/fixtures/vcr_cassettes/resources/settings_import/update_settings_continue.yml +316 -0
- data/test/fixtures/vcr_cassettes/resources/subscriptions_import/manifest_does_not_exist.yml +18785 -0
- data/test/fixtures/vcr_cassettes/setup/setup_content_views/setup.yml +19090 -0
- data/test/fixtures/vcr_cassettes/setup/setup_lifecycle_environments/setup.yml +924 -0
- data/test/fixtures/vcr_cassettes/setup/setup_locations/setup.yml +21102 -0
- data/test/fixtures/vcr_cassettes/setup/setup_organizations/setup.yml +19278 -0
- data/test/fixtures/vcr_cassettes/setup/setup_subscriptions/setup.yml +419 -0
- data/test/import_test.rb +20 -25
- data/test/resources/activation_keys_test.rb +72 -0
- data/test/resources/content_hosts_test.rb +132 -0
- data/test/resources/settings_test.rb +81 -0
- data/test/resources/subscriptions_test.rb +56 -0
- data/test/setup/setup_content_views.rb +17 -0
- data/test/setup/setup_lifecycle_environments.rb +17 -0
- data/test/setup/setup_locations.rb +17 -0
- data/test/setup/setup_organizations.rb +17 -0
- data/test/setup/setup_subscriptions.rb +20 -0
- data/test/setup/setup_test.rb +10 -0
- data/test/test_runner.rb +175 -0
- data/test/vcr_setup.rb +54 -0
- metadata +77 -13
- data/lib/hammer_cli_csv/exception_handler.rb +0 -42
- data/lib/hammer_cli_csv/installation_medias.rb +0 -77
- data/test/content_hosts_test.rb +0 -61
- data/test/settings_test.rb +0 -30
@@ -14,41 +14,39 @@ module HammerCLICsv
|
|
14
14
|
REPOSITORIES = 'Repositories'
|
15
15
|
RULES = 'Rules'
|
16
16
|
|
17
|
-
def export
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
raise "Unknown filter rule type '#{filter['type']}'"
|
45
|
-
end
|
46
|
-
|
47
|
-
name = filter['name']
|
48
|
-
repositories = export_column(filter, 'repositories', 'name')
|
49
|
-
csv << [name, contentview['name'], organization['name'], filter_type, filter['description'],
|
50
|
-
repositories, rules]
|
17
|
+
def export(csv)
|
18
|
+
csv << [NAME, CONTENTVIEW, ORGANIZATION, TYPE, DESCRIPTION, REPOSITORIES, RULES]
|
19
|
+
@api.resource(:organizations).call(:index, {
|
20
|
+
:per_page => 999999
|
21
|
+
})['results'].each do |organization|
|
22
|
+
next if option_organization && organization['name'] != option_organization
|
23
|
+
|
24
|
+
@api.resource(:content_views).call(:index, {
|
25
|
+
'per_page' => 999999,
|
26
|
+
'organization_id' => organization['id'],
|
27
|
+
'nondefault' => true
|
28
|
+
})['results'].each do |contentview|
|
29
|
+
@api.resource(:content_view_filters).call(:index, {
|
30
|
+
'content_view_id' => contentview['id']
|
31
|
+
})['results'].collect do |filter|
|
32
|
+
filter_type = "#{filter['inclusion'] == true ? 'Include' : 'Exclude'} #{export_filter_type(filter['type'])}"
|
33
|
+
|
34
|
+
rules = nil
|
35
|
+
case filter['type']
|
36
|
+
when /rpm/
|
37
|
+
rules = export_rpm_rules(filter)
|
38
|
+
when /erratum/
|
39
|
+
rules = export_erratum_rules(filter)
|
40
|
+
when /package_group/
|
41
|
+
rules = export_package_group_rules(filter)
|
42
|
+
else
|
43
|
+
raise "Unknown filter rule type '#{filter['type']}'"
|
51
44
|
end
|
45
|
+
|
46
|
+
name = filter['name']
|
47
|
+
repositories = export_column(filter, 'repositories', 'name')
|
48
|
+
csv << [name, contentview['name'], organization['name'], filter_type, filter['description'],
|
49
|
+
repositories, rules]
|
52
50
|
end
|
53
51
|
end
|
54
52
|
end
|
@@ -155,8 +153,6 @@ module HammerCLICsv
|
|
155
153
|
puts 'done' if option_verbose?
|
156
154
|
end
|
157
155
|
|
158
|
-
rescue RuntimeError => e
|
159
|
-
raise "#{e}\n #{line}"
|
160
156
|
end
|
161
157
|
|
162
158
|
private
|
@@ -16,44 +16,42 @@ module HammerCLICsv
|
|
16
16
|
REPOSITORIES = 'Repositories or Composites'
|
17
17
|
ENVIRONMENTS = "Lifecycle Environments"
|
18
18
|
|
19
|
-
def export
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
component['content_view']['name']
|
45
|
-
end
|
19
|
+
def export(csv)
|
20
|
+
csv << [NAME, LABEL, ORGANIZATION, COMPOSITE, REPOSITORIES, ENVIRONMENTS]
|
21
|
+
@api.resource(:organizations).call(:index, {
|
22
|
+
:per_page => 999999
|
23
|
+
})['results'].each do |organization|
|
24
|
+
next if option_organization && organization['name'] != option_organization
|
25
|
+
|
26
|
+
composite_contentviews = []
|
27
|
+
@api.resource(:content_views).call(:index, {
|
28
|
+
'per_page' => 999999,
|
29
|
+
'organization_id' => organization['id'],
|
30
|
+
'nondefault' => true
|
31
|
+
})['results'].each do |contentview|
|
32
|
+
name = contentview['name']
|
33
|
+
label = contentview['label']
|
34
|
+
orgname = organization['name']
|
35
|
+
environments = CSV.generate do |column|
|
36
|
+
column << environment_names(contentview)
|
37
|
+
end
|
38
|
+
environments.delete!("\n")
|
39
|
+
composite = contentview['composite'] == true ? 'Yes' : 'No'
|
40
|
+
if composite == 'Yes'
|
41
|
+
contentviews = CSV.generate do |column|
|
42
|
+
column << contentview['components'].collect do |component|
|
43
|
+
component['content_view']['name']
|
46
44
|
end
|
47
|
-
contentviews.delete!("\n")
|
48
|
-
composite_contentviews << [name, 1, label, orgname, composite, contentviews, environments]
|
49
|
-
else
|
50
|
-
repositories = export_column(contentview, 'repositories', 'name')
|
51
|
-
csv << [name, label, orgname, composite, repositories, environments]
|
52
45
|
end
|
46
|
+
contentviews.delete!("\n")
|
47
|
+
composite_contentviews << [name, 1, label, orgname, composite, contentviews, environments]
|
48
|
+
else
|
49
|
+
repositories = export_column(contentview, 'repositories', 'name')
|
50
|
+
csv << [name, label, orgname, composite, repositories, environments]
|
53
51
|
end
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
end
|
53
|
+
composite_contentviews.each do |contentview|
|
54
|
+
csv << contentview
|
57
55
|
end
|
58
56
|
end
|
59
57
|
end
|
@@ -131,8 +129,6 @@ module HammerCLICsv
|
|
131
129
|
puts _('done') if option_verbose?
|
132
130
|
end
|
133
131
|
|
134
|
-
rescue RuntimeError => e
|
135
|
-
raise "#{e}\n #{line}"
|
136
132
|
end
|
137
133
|
|
138
134
|
def environment_names(contentview)
|
data/lib/hammer_cli_csv/csv.rb
CHANGED
@@ -3,9 +3,25 @@ require 'hammer_cli/exit_codes'
|
|
3
3
|
|
4
4
|
module HammerCLICsv
|
5
5
|
class CsvCommand < HammerCLI::AbstractCommand
|
6
|
+
def help
|
7
|
+
self.class.help(invocation_path, CsvSortedBuilder.new)
|
8
|
+
end
|
9
|
+
|
10
|
+
class CsvSortedBuilder < SortedBuilder
|
11
|
+
def add_list(heading, items)
|
12
|
+
items.delete_if do |item|
|
13
|
+
if item.class == Clamp::Subcommand::Definition
|
14
|
+
!item.subcommand_class.supported?
|
15
|
+
else
|
16
|
+
false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
super(heading, items)
|
20
|
+
end
|
21
|
+
end
|
6
22
|
end
|
7
23
|
|
8
24
|
HammerCLI::MainCommand.subcommand('csv',
|
9
|
-
_('import to
|
25
|
+
_('import to or export from a running foreman server'),
|
10
26
|
HammerCLICsv::CsvCommand)
|
11
27
|
end
|
@@ -12,23 +12,21 @@ module HammerCLICsv
|
|
12
12
|
|
13
13
|
SEPARATOR = ' = '
|
14
14
|
|
15
|
-
def export
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@api.resource(:domains).call(:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
csv << [name, organizations, locations, description, capsule, parameters]
|
31
|
-
end
|
15
|
+
def export(csv)
|
16
|
+
csv << [NAME, ORGANIZATIONS, LOCATIONS, DESCRIPTION, SMART_PROXY, PARAMETERS]
|
17
|
+
search_options = {:per_page => 999999}
|
18
|
+
search_options['search'] = "organization=\"#{option_organization}\"" if option_organization
|
19
|
+
@api.resource(:domains).call(:index, search_options)['results'].each do |domain|
|
20
|
+
domain = @api.resource(:domains).call(:show, {'id' => domain['id']})
|
21
|
+
raise "Domain 'id=#{domain['id']}' not found" if !domain || domain.empty?
|
22
|
+
|
23
|
+
name = domain['name']
|
24
|
+
organizations = option_organization ? option_organization : export_column(domain, 'organizations', 'name')
|
25
|
+
locations = export_column(domain, 'locations', 'name')
|
26
|
+
description = domain['fullname']
|
27
|
+
capsule = foreman_smart_proxy(:id => domain['dns_id'])
|
28
|
+
parameters = export_parameters(domain['parameters'])
|
29
|
+
csv << [name, organizations, locations, description, capsule, parameters]
|
32
30
|
end
|
33
31
|
end
|
34
32
|
|
@@ -92,8 +90,6 @@ module HammerCLICsv
|
|
92
90
|
|
93
91
|
print "done\n" if option_verbose?
|
94
92
|
end
|
95
|
-
rescue RuntimeError => e
|
96
|
-
raise "#{e}\n #{line}"
|
97
93
|
end
|
98
94
|
|
99
95
|
private
|
@@ -4,21 +4,29 @@ module HammerCLICsv
|
|
4
4
|
command_name 'export'
|
5
5
|
desc 'export into directory'
|
6
6
|
|
7
|
+
def self.supported?
|
8
|
+
true
|
9
|
+
end
|
10
|
+
|
7
11
|
option %w(-v --verbose), :flag, _('be verbose')
|
8
12
|
option %w(--threads), 'THREAD_COUNT', _('Number of threads to hammer with'),
|
9
13
|
:default => 1, :hidden => true
|
10
|
-
option '--dir', 'DIRECTORY', _('directory to
|
14
|
+
option '--dir', 'DIRECTORY', _('directory to export to')
|
11
15
|
option %w(--organization), 'ORGANIZATION', _('Only process organization matching this name')
|
12
16
|
|
13
17
|
RESOURCES = %w(
|
14
|
-
organizations locations puppet_environments operating_systems
|
18
|
+
settings organizations locations puppet_environments operating_systems
|
15
19
|
domains architectures partition_tables lifecycle_environments host_collections
|
16
20
|
provisioning_templates
|
17
21
|
subscriptions activation_keys hosts content_hosts reports roles users
|
18
22
|
)
|
23
|
+
SUPPORTED_RESOURCES = %w(
|
24
|
+
settings
|
25
|
+
)
|
19
26
|
RESOURCES.each do |resource|
|
20
27
|
dashed = resource.sub('_', '-')
|
21
|
-
option "--#{dashed}", 'FILE', "csv file for #{dashed}"
|
28
|
+
option "--#{dashed}", 'FILE', "csv file for #{dashed}",
|
29
|
+
:hidden => !SUPPORTED_RESOURCES.include?(resource)
|
22
30
|
end
|
23
31
|
|
24
32
|
def execute
|
@@ -46,7 +54,7 @@ module HammerCLICsv
|
|
46
54
|
:username => @username,
|
47
55
|
:password => @password
|
48
56
|
})
|
49
|
-
skipped_resources = %w( locations puppet_environments operating_systems
|
57
|
+
skipped_resources = %w( settings locations puppet_environments operating_systems
|
50
58
|
domains architectures partition_tables lifecycle_environments
|
51
59
|
provisioning_templates
|
52
60
|
hosts reports )
|
@@ -58,7 +66,7 @@ module HammerCLICsv
|
|
58
66
|
:password => @password,
|
59
67
|
:api_version => 2
|
60
68
|
})
|
61
|
-
skipped_resources =
|
69
|
+
skipped_resources = (RESOURCES - SUPPORTED_RESOURCES)
|
62
70
|
end
|
63
71
|
|
64
72
|
# Swing the hammers
|
@@ -8,29 +8,27 @@ module HammerCLICsv
|
|
8
8
|
LIMIT = 'Limit'
|
9
9
|
DESCRIPTION = 'Description'
|
10
10
|
|
11
|
-
def export
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
systemgroup['description']]
|
21
|
-
end
|
11
|
+
def export(csv)
|
12
|
+
csv << [NAME, ORGANIZATION, LIMIT, DESCRIPTION]
|
13
|
+
if @server_status['release'] == 'Headpin'
|
14
|
+
@headpin.get(:organizations).each do |organization|
|
15
|
+
next if option_organization && organization['name'] != option_organization
|
16
|
+
@headpin.get("organizations/#{organization['label']}/system_groups").each do |systemgroup|
|
17
|
+
csv << [systemgroup['name'], organization['name'],
|
18
|
+
systemgroup['max_systems'].to_i < 0 ? 'Unlimited' : systemgroup['max_systems'],
|
19
|
+
systemgroup['description']]
|
22
20
|
end
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
21
|
+
end
|
22
|
+
else
|
23
|
+
@api.resource(:organizations).call(:index, {'per_page' => 999999})['results'].each do |organization|
|
24
|
+
next if option_organization && organization['name'] != option_organization
|
25
|
+
@api.resource(:host_collections).call(:index, {
|
26
|
+
'organization_id' => organization['id']
|
27
|
+
})['results'].each do |hostcollection|
|
28
|
+
limit = hostcollection['unlimited_content_hosts'] ? 'Unlimited' : hostcollection['max_content_hosts']
|
29
|
+
csv << [hostcollection['name'], organization['name'],
|
30
|
+
limit,
|
31
|
+
hostcollection['description']]
|
34
32
|
end
|
35
33
|
end
|
36
34
|
end
|
@@ -19,96 +19,104 @@ module HammerCLICsv
|
|
19
19
|
PUPPET_PROXY = 'Puppet Proxy'
|
20
20
|
PUPPET_CA_PROXY = 'Puppet CA Proxy'
|
21
21
|
CONTENT_SOURCE = 'Content Source'
|
22
|
+
PASSWORD = 'Password'
|
23
|
+
PUPPET_CLASSES = 'Puppet Classes'
|
22
24
|
|
23
|
-
def export
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
@api.resource(:hostgroups).call(:
|
31
|
-
|
32
|
-
raise "Host Group 'id=#{hostgroup['id']}' not found" if !hostgroup || hostgroup.empty?
|
25
|
+
def export(csv)
|
26
|
+
csv << [NAME, PARENT, ORGANIZATIONS, LOCATIONS, SUBNET, DOMAIN, OPERATING_SYSTEM,
|
27
|
+
ENVIRONMENT, COMPUTE_PROFILE, PARTITION_TABLE, MEDIUM, ARCHITECTURE, REALM,
|
28
|
+
PUPPET_PROXY, PUPPET_CA_PROXY, CONTENT_SOURCE, PASSWORD, PUPPET_CLASSES]
|
29
|
+
search_options = {:per_page => 999999}
|
30
|
+
search_options['search'] = "organization=\"#{option_organization}\"" if option_organization
|
31
|
+
@api.resource(:hostgroups).call(:index, search_options)['results'].each do |hostgroup|
|
32
|
+
hostgroup = @api.resource(:hostgroups).call(:show, {'id' => hostgroup['id']})
|
33
|
+
raise "Host Group 'id=#{hostgroup['id']}' not found" if !hostgroup || hostgroup.empty?
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
csv << [name, parent, organizations, locations, subnet, domain, operating_system,
|
54
|
-
puppet_environment, compute_profile, partition_table, medium, architecture,
|
55
|
-
realm, puppet_proxy, puppet_ca_proxy, content_source]
|
35
|
+
name = hostgroup['name']
|
36
|
+
organizations = export_column(hostgroup, 'organizations', 'name')
|
37
|
+
locations = export_column(hostgroup, 'locations', 'name')
|
38
|
+
subnet = hostgroup['subnet_name']
|
39
|
+
operating_system = hostgroup['operatingsystem_name']
|
40
|
+
domain = hostgroup['domain_name']
|
41
|
+
puppet_environment = hostgroup['environment_name']
|
42
|
+
compute_profile = hostgroup['compute_profile_name']
|
43
|
+
partition_table = hostgroup['ptable_name']
|
44
|
+
medium = hostgroup['medium_name']
|
45
|
+
architecture = hostgroup['architecture_name']
|
46
|
+
realm = hostgroup['realm_name']
|
47
|
+
puppet_proxy = hostgroup['puppet_proxy_id'] ? foreman_host(:id => hostgroup['puppet_proxy_id']) : nil
|
48
|
+
puppet_ca_proxy = hostgroup['puppet_ca_proxy_id'] ? foreman_host(:id => hostgroup['puppet_ca_proxy_id']) : nil
|
49
|
+
content_source = hostgroup['content_source_id'] ? foreman_host(:id => hostgroup['content_source_id']) : nil
|
50
|
+
parent = hostgroup['ancestry'] ? foreman_hostgroup(:id => hostgroup['ancestry']) : nil
|
51
|
+
password = nil
|
52
|
+
puppet_classes = export_column(hostgroup, 'puppetclasses') do |puppet_class|
|
53
|
+
"#{puppet_class['module_name']}/#{puppet_class['name']}"
|
56
54
|
end
|
55
|
+
|
56
|
+
# TODO: http://projects.theforeman.org/issues/6273
|
57
|
+
# API call to get the smart class variable override values
|
58
|
+
|
59
|
+
csv << [name, parent, organizations, locations, subnet, domain, operating_system,
|
60
|
+
puppet_environment, compute_profile, partition_table, medium, architecture,
|
61
|
+
realm, puppet_proxy, puppet_ca_proxy, content_source, password, puppet_classes]
|
57
62
|
end
|
58
63
|
end
|
59
64
|
|
60
65
|
def import
|
61
66
|
@existing = {}
|
62
|
-
@api.resource(:hostgroups).call(:index, {:per_page => 999999})['results'].each do |
|
63
|
-
@existing[
|
67
|
+
@api.resource(:hostgroups).call(:index, {:per_page => 999999})['results'].each do |host_group|
|
68
|
+
@existing[host_group['name']] = host_group['id'] if host_group
|
64
69
|
end
|
65
70
|
|
66
71
|
thread_import do |line|
|
67
|
-
|
72
|
+
create_from_csv(line)
|
68
73
|
end
|
69
74
|
end
|
70
75
|
|
71
|
-
def
|
76
|
+
def create_from_csv(line)
|
72
77
|
return if option_organization && !CSV.parse_line(line[ORGANIZATIONS], {:skip_blanks => true}).include?(option_organization)
|
73
78
|
|
79
|
+
params = {
|
80
|
+
'hostgroup' => {
|
81
|
+
'architecture_id' => foreman_architecture(:name => line[ARCHITECTURE]),
|
82
|
+
'operatingsystem_id' => foreman_operatingsystem(:name => line[OPERATING_SYSTEM]),
|
83
|
+
'medium_id' => foreman_medium(:name => line[MEDIUM]),
|
84
|
+
'ptable_id' => foreman_partitiontable(:name => line[PARTITION_TABLE]),
|
85
|
+
'root_pass' => line[PASSWORD],
|
86
|
+
'organization_ids' => collect_column(line[ORGANIZATIONS]) do |organization|
|
87
|
+
foreman_organization(:name => organization)
|
88
|
+
end,
|
89
|
+
'location_ids' => collect_column(line[LOCATIONS]) do |location|
|
90
|
+
foreman_location(:name => location)
|
91
|
+
end
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
74
95
|
count(line[COUNT]).times do |number|
|
75
96
|
name = namify(line[NAME], number)
|
97
|
+
params['hostgroup']['name'] = name
|
98
|
+
|
76
99
|
if !@existing.include? name
|
77
100
|
print "Creating host group '#{name}'..." if option_verbose?
|
78
|
-
|
79
|
-
|
80
|
-
# 'name' => name,
|
81
|
-
# 'root_pass' => 'changeme',
|
82
|
-
# 'mac' => namify(line[MACADDRESS], number),
|
83
|
-
# 'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
|
84
|
-
# 'location_id' => foreman_location(:name => line[LOCATION]),
|
85
|
-
# 'environment_id' => foreman_environment(:name => line[ENVIRONMENT]),
|
86
|
-
# 'operatingsystem_id' => foreman_operatingsystem(:name => line[OPERATINGSYSTEM]),
|
87
|
-
# 'architecture_id' => foreman_architecture(:name => line[ARCHITECTURE]),
|
88
|
-
# 'domain_id' => foreman_domain(:name => line[DOMAIN]),
|
89
|
-
# 'ptable_id' => foreman_partitiontable(:name => line[PARTITIONTABLE])
|
90
|
-
# }
|
91
|
-
# })
|
101
|
+
hostgroup = @api.resource(:hostgroups).call(:create, params)
|
102
|
+
@existing[name] = hostgroup['id']
|
92
103
|
else
|
93
104
|
print "Updating host '#{name}'..." if option_verbose?
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
# 'architecture_id' => foreman_architecture(:name => line[ARCHITECTURE]),
|
103
|
-
# 'domain_id' => foreman_domain(:name => line[DOMAIN]),
|
104
|
-
# 'ptable_id' => foreman_partitiontable(:name => line[PARTITIONTABLE])
|
105
|
-
# }
|
106
|
-
# })
|
105
|
+
params['id'] = @existing[name]
|
106
|
+
hostgroup = @api.resource(:hostgroups).call(:update, params)
|
107
|
+
end
|
108
|
+
|
109
|
+
# TODO: puppet classes
|
110
|
+
puppetclass_ids = collect_column(line[PUPPET_CLASSES]) do |puppet_class|
|
111
|
+
module_name, name = puppet_class.split('/')
|
112
|
+
foreman_puppet_class(:name => name)
|
107
113
|
end
|
114
|
+
existing_ids = hostgroup['puppet_classes'].collect { |puppet_class| puppet_class['id'] }
|
115
|
+
# DELETE existing_ids - puppetclass_ids
|
116
|
+
# POST puppetclass_ids - existing_ids
|
117
|
+
|
108
118
|
print "done\n" if option_verbose?
|
109
119
|
end
|
110
|
-
rescue RuntimeError => e
|
111
|
-
raise "#{e}\n #{line}"
|
112
120
|
end
|
113
121
|
end
|
114
122
|
end
|
data/lib/hammer_cli_csv/hosts.rb
CHANGED
@@ -22,41 +22,39 @@ module HammerCLICsv
|
|
22
22
|
ENABLED = 'Enabled'
|
23
23
|
MANAGED = 'Managed'
|
24
24
|
|
25
|
-
def export
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
@api.resource(:hosts).call(:
|
33
|
-
|
34
|
-
raise "Host 'id=#{host['id']}' not found" if !host || host.empty?
|
25
|
+
def export(csv)
|
26
|
+
csv << [NAME, ORGANIZATION, LOCATION, ENVIRONMENT, OPERATINGSYSTEM, ARCHITECTURE,
|
27
|
+
MACADDRESS, DOMAIN, PARTITIONTABLE, SUBNET, REALM, MEDIUM, HOSTGROUP,
|
28
|
+
COMPUTERESOURCE, COMPUTEPROFILE, IMAGE, ENABLED, MANAGED]
|
29
|
+
search_options = {:per_page => 999999}
|
30
|
+
search_options['search'] = "organization=\"#{option_organization}\"" if option_organization
|
31
|
+
@api.resource(:hosts).call(:index, search_options)['results'].each do |host|
|
32
|
+
host = @api.resource(:hosts).call(:show, {'id' => host['id']})
|
33
|
+
raise "Host 'id=#{host['id']}' not found" if !host || host.empty?
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
35
|
+
name = host['name']
|
36
|
+
organization = host['organization_name']
|
37
|
+
location = host['location_name']
|
38
|
+
environment = host['environment_name']
|
39
|
+
operatingsystem = host['operatingsystem_name']
|
40
|
+
architecture = host['architecture_name']
|
41
|
+
mac = host['mac']
|
42
|
+
domain = host['domain_name']
|
43
|
+
ptable = host['ptable_name']
|
44
|
+
subnet = host['subnet_name']
|
45
|
+
realm = host['realm_name']
|
46
|
+
medium = host['medium_name']
|
47
|
+
hostgroup = host['hostgroup_name']
|
48
|
+
compute_resource = host['compute_resource_name']
|
49
|
+
compute_profile = host['compute_profile_name']
|
50
|
+
image = host['image_name']
|
52
51
|
|
53
|
-
|
54
|
-
|
52
|
+
enabled = host['enabled'] ? 'Yes' : 'No'
|
53
|
+
managed = host['managed'] ? 'Yes' : 'No'
|
55
54
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
55
|
+
csv << [name, organization, location, environment, operatingsystem, architecture,
|
56
|
+
mac, domain, ptable, subnet, realm, medium, hostgroup, compute_resource,
|
57
|
+
compute_profile, image, enabled, managed]
|
60
58
|
end
|
61
59
|
end
|
62
60
|
|
@@ -110,8 +108,6 @@ module HammerCLICsv
|
|
110
108
|
end
|
111
109
|
print "done\n" if option_verbose?
|
112
110
|
end
|
113
|
-
rescue RuntimeError => e
|
114
|
-
raise "#{e}\n #{line}"
|
115
111
|
end
|
116
112
|
end
|
117
113
|
end
|