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
@@ -0,0 +1,49 @@
|
|
1
|
+
module HammerCLICsv
|
2
|
+
class CsvCommand
|
3
|
+
class SettingsCommand < BaseCommand
|
4
|
+
command_name 'settings'
|
5
|
+
desc 'import or export settings'
|
6
|
+
|
7
|
+
VALUE = 'Value'
|
8
|
+
|
9
|
+
def export
|
10
|
+
CSV.open(option_file || '/dev/stdout', 'wb') do |csv|
|
11
|
+
csv << [NAME, VALUE]
|
12
|
+
@api.resource(:settings).call(:index, {'per_page' => 999999})['results'].each do |setting|
|
13
|
+
csv << [setting['name'], setting['value']]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def import
|
19
|
+
@existing = {}
|
20
|
+
|
21
|
+
thread_import do |line|
|
22
|
+
create_settings_from_csv(line)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_settings_from_csv(line)
|
27
|
+
count(line[COUNT]).times do |number|
|
28
|
+
name = namify(line[NAME], number)
|
29
|
+
params = { 'id' => get_setting_id(name),
|
30
|
+
'setting' => {
|
31
|
+
'value' => line[VALUE]
|
32
|
+
}
|
33
|
+
}
|
34
|
+
print "Updating setting '#{name}'..." if option_verbose?
|
35
|
+
@api.resource(:settings).call(:update, params)
|
36
|
+
end
|
37
|
+
print "done\n" if option_verbose?
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def get_setting_id(name)
|
43
|
+
results = @api.resource(:settings).call(:index, { :search => "name=\"#{name}\"" })['results']
|
44
|
+
raise "Setting '#{name}' not found" if !results || results.empty?
|
45
|
+
results[0]['id']
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,18 +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
|
-
require 'hammer_cli'
|
13
|
-
require 'json'
|
14
|
-
require 'csv'
|
15
|
-
|
16
1
|
module HammerCLICsv
|
17
2
|
class CsvCommand
|
18
3
|
class SmartProxiesCommand < BaseCommand
|
@@ -25,16 +10,15 @@ module HammerCLICsv
|
|
25
10
|
LIFECYCLE_ENVIRONMENTS = 'Lifecycle Environments'
|
26
11
|
|
27
12
|
def export
|
28
|
-
CSV.open(
|
29
|
-
csv << [NAME,
|
13
|
+
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
|
14
|
+
csv << [NAME, ORGANIZATIONS, LOCATIONS, URL, LIFECYCLE_ENVIRONMENTS]
|
30
15
|
@api.resource(:smart_proxies).call(:index, {:per_page => 999999})['results'].each do |smart_proxy|
|
31
16
|
smart_proxy = @api.resource(:smart_proxies).call(:show, {'id' => smart_proxy['id']})
|
32
17
|
name = smart_proxy['name']
|
33
|
-
count = 1
|
34
18
|
organizations = export_column(smart_proxy, 'organizations', 'name')
|
35
19
|
locations = export_column(smart_proxy, 'locations', 'name')
|
36
20
|
url = smart_proxy['url']
|
37
|
-
csv << [name,
|
21
|
+
csv << [name, organizations, locations, url]
|
38
22
|
end
|
39
23
|
end
|
40
24
|
end
|
@@ -51,9 +35,10 @@ module HammerCLICsv
|
|
51
35
|
end
|
52
36
|
|
53
37
|
def create_smart_proxies_from_csv(line)
|
54
|
-
line[COUNT].
|
38
|
+
count(line[COUNT]).times do |number|
|
55
39
|
name = namify(line[NAME], number)
|
56
|
-
|
40
|
+
id = @existing[line[URL]]
|
41
|
+
if id.nil?
|
57
42
|
print "Creating smart proxy '#{name}'..." if option_verbose?
|
58
43
|
id = @api.resource(:smart_proxies).call(:create, {
|
59
44
|
'smart_proxy' => {
|
@@ -63,13 +48,13 @@ module HammerCLICsv
|
|
63
48
|
})['id']
|
64
49
|
else
|
65
50
|
print "Updating smart proxy '#{name}'..." if option_verbose?
|
66
|
-
|
67
|
-
'id' =>
|
51
|
+
@api.resource(:smart_proxies).call(:update, {
|
52
|
+
'id' => id,
|
68
53
|
'smart_proxy' => {
|
69
54
|
'name' => name,
|
70
55
|
'url' => line[URL]
|
71
56
|
}
|
72
|
-
})
|
57
|
+
})
|
73
58
|
end
|
74
59
|
|
75
60
|
# Update associated resources
|
@@ -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 'openssl'
|
13
2
|
require 'date'
|
14
3
|
|
@@ -18,7 +7,6 @@ module HammerCLICsv
|
|
18
7
|
command_name 'splice'
|
19
8
|
desc 'import Satellite-5 splice data'
|
20
9
|
|
21
|
-
option %w(--organization), 'ORGANIZATION', 'Only process organization matching this name'
|
22
10
|
option %w(--dir), 'DIR',
|
23
11
|
'Directory of Splice exported CSV files (default pwd)'
|
24
12
|
option %w(--mapping-dir), 'DIR',
|
@@ -1,18 +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
|
-
require 'hammer_cli'
|
13
|
-
require 'json'
|
14
|
-
require 'csv'
|
15
|
-
|
16
1
|
module HammerCLICsv
|
17
2
|
class CsvCommand
|
18
3
|
class SubnetsCommand < BaseCommand
|
@@ -35,15 +20,14 @@ module HammerCLICsv
|
|
35
20
|
VLAN_ID = 'VLAN ID'
|
36
21
|
|
37
22
|
def export
|
38
|
-
CSV.open(
|
39
|
-
csv << [NAME,
|
23
|
+
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
|
24
|
+
csv << [NAME, ORGANIZATIONS, LOCATIONS, NETWORK, NETWORK_MASK,
|
40
25
|
NETWORK_FROM, NETWORK_TO, DOMAINS, GATEWAY, DHCP_PROXY, TFTP_PROXY, DNS_PROXY,
|
41
26
|
DNS_PRIMARY, DNS_SECONDARY, VLAN_ID]
|
42
27
|
@api.resource(:subnets).call(:index, {:per_page => 999999})['results'].each do |subnet|
|
43
28
|
subnet = @api.resource(:subnets).call(:show, {'id' => subnet['id']})
|
44
29
|
|
45
30
|
name = subnet['name']
|
46
|
-
count = 1
|
47
31
|
organizations = export_column(subnet, 'organizations', 'name')
|
48
32
|
locations = export_column(subnet, 'locations', 'name')
|
49
33
|
network = subnet['network']
|
@@ -58,7 +42,7 @@ module HammerCLICsv
|
|
58
42
|
dns_primary = subnet['dns_primary']
|
59
43
|
dns_secondary = subnet['dns_secondary']
|
60
44
|
vlan_id = subnet['vlanid']
|
61
|
-
csv << [name,
|
45
|
+
csv << [name, organizations, locations, network, network_mask,
|
62
46
|
network_from, network_to, domains, gateway, dhcp_proxy, tftp_proxy, dns_proxy,
|
63
47
|
dns_primary, dns_secondary, vlan_id]
|
64
48
|
end
|
@@ -81,13 +65,18 @@ module HammerCLICsv
|
|
81
65
|
foreman_domain(:name => domain)
|
82
66
|
end
|
83
67
|
|
84
|
-
line[COUNT].
|
68
|
+
count(line[COUNT]).times do |number|
|
85
69
|
name = namify(line[NAME], number)
|
86
70
|
if !@existing.include? name
|
87
71
|
print "Creating subnet '#{name}'..." if option_verbose?
|
88
72
|
id = @api.resource(:subnets).call(:create, {
|
89
73
|
'subnet' => {
|
90
|
-
|
74
|
+
'name' => name,
|
75
|
+
'network' => line[NETWORK],
|
76
|
+
'mask' => line[NETWORK_MASK],
|
77
|
+
#'from' => line[NETWORK_FROM],
|
78
|
+
#'to' => line[NETWORK_TO],
|
79
|
+
#'domain_ids' => line[DOMAINS]
|
91
80
|
}
|
92
81
|
})['id']
|
93
82
|
else
|
@@ -1,23 +1,9 @@
|
|
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
|
-
|
13
1
|
module HammerCLICsv
|
14
2
|
class CsvCommand
|
15
3
|
class SubscriptionsCommand < BaseCommand
|
16
4
|
command_name 'subscriptions'
|
17
5
|
desc 'import or export subscriptions'
|
18
6
|
|
19
|
-
option %w(--organization), 'ORGANIZATION', 'Only process organization matching this name'
|
20
|
-
|
21
7
|
ORGANIZATION = 'Organization'
|
22
8
|
MANIFEST = 'Manifest File'
|
23
9
|
CONTENT_SET = 'Content Set'
|
@@ -25,8 +11,8 @@ module HammerCLICsv
|
|
25
11
|
RELEASE = 'Release'
|
26
12
|
|
27
13
|
def export
|
28
|
-
CSV.open(
|
29
|
-
csv << [NAME,
|
14
|
+
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
|
15
|
+
csv << [NAME, ORGANIZATION, MANIFEST, CONTENT_SET, ARCH, RELEASE]
|
30
16
|
@api.resource(:organizations).call(:index, {:per_page => 999999})['results'].each do |organization|
|
31
17
|
next if option_organization && organization['name'] != option_organization
|
32
18
|
@api.resource(:products).call(:index, {
|
@@ -34,7 +20,7 @@ module HammerCLICsv
|
|
34
20
|
'organization_id' => organization['id'],
|
35
21
|
'enabled' => true
|
36
22
|
})['results'].each do |product|
|
37
|
-
if product['
|
23
|
+
if product['redhat']
|
38
24
|
name = product['name']
|
39
25
|
@api.resource(:repository_sets).call(:index, {
|
40
26
|
'per_page' => 999999,
|
@@ -46,7 +32,7 @@ module HammerCLICsv
|
|
46
32
|
name_split = repository['name'].split(' ')
|
47
33
|
arch = name_split[-2]
|
48
34
|
release = name_split[-1]
|
49
|
-
csv << [name,
|
35
|
+
csv << [name, organization['name'], nil, content_set, arch, release]
|
50
36
|
end
|
51
37
|
end
|
52
38
|
end
|
@@ -65,7 +51,12 @@ module HammerCLICsv
|
|
65
51
|
end
|
66
52
|
end
|
67
53
|
|
54
|
+
# FIXME: TODO remove this rubocop
|
55
|
+
# rubocop:disable CyclomaticComplexity
|
68
56
|
def enable_products_from_csv(line)
|
57
|
+
organization = line[ORGANIZATION] || option_organization
|
58
|
+
raise "Organization is required in either input CSV or by option --organization" if organization.nil? || organization.empty?
|
59
|
+
line[ORGANIZATION] = organization
|
69
60
|
return if option_organization && line[ORGANIZATION] != option_organization
|
70
61
|
|
71
62
|
results = @api.resource(:products).call(:index, {
|
@@ -75,7 +66,7 @@ module HammerCLICsv
|
|
75
66
|
})['results']
|
76
67
|
raise "No match for product '#{line[NAME]}'" if results.length == 0
|
77
68
|
raise "Multiple matches for product '#{line[NAME]}'" if results.length != 1
|
78
|
-
product = results[0]
|
69
|
+
product = @api.resource(:products).call(:show, {'id' => results[0]['id']})
|
79
70
|
|
80
71
|
results = @api.resource(:repository_sets).call(:index, {
|
81
72
|
'per_page' => 999999,
|
@@ -88,7 +79,11 @@ module HammerCLICsv
|
|
88
79
|
repository_set = results[0]
|
89
80
|
|
90
81
|
repository = repository_set['repositories'].find do |repo|
|
91
|
-
|
82
|
+
if line[RELEASE].nil? || line[RELEASE].empty?
|
83
|
+
repo['name'].end_with?("#{line[ARCH]}")
|
84
|
+
else
|
85
|
+
repo['name'].end_with?("#{line[ARCH]} #{line[RELEASE]}")
|
86
|
+
end
|
92
87
|
end
|
93
88
|
|
94
89
|
if repository.nil?
|
@@ -98,12 +93,14 @@ module HammerCLICsv
|
|
98
93
|
end
|
99
94
|
raise "No match for content set '#{line[CONTENT_SET]}'" if !product_content
|
100
95
|
|
101
|
-
|
96
|
+
params = {
|
102
97
|
'id' => product_content['content']['id'],
|
103
98
|
'product_id' => product['id'],
|
104
|
-
'basearch' => line[ARCH]
|
105
|
-
|
106
|
-
|
99
|
+
'basearch' => line[ARCH]
|
100
|
+
}
|
101
|
+
params['releasever'] = line[RELEASE] unless line[RELEASE].nil? || line[RELEASE].empty?
|
102
|
+
|
103
|
+
@api.resource(:repository_sets).call(:enable, params)
|
107
104
|
puts 'done' if option_verbose?
|
108
105
|
else
|
109
106
|
puts "Repository #{repository['name']} already enabled" if option_verbose?
|
@@ -1,23 +1,9 @@
|
|
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
|
-
|
13
1
|
module HammerCLICsv
|
14
2
|
class CsvCommand
|
15
3
|
class SyncPlansCommand < BaseCommand
|
16
4
|
command_name 'sync-plans'
|
17
5
|
desc 'import or export repository sync plans'
|
18
6
|
|
19
|
-
option %w(--organization), 'ORGANIZATION', 'Only process organization matching this name'
|
20
|
-
|
21
7
|
ORGANIZATION = 'Organization'
|
22
8
|
DESCRIPTION = 'Description'
|
23
9
|
ENABLED = 'Enabled'
|
@@ -26,8 +12,8 @@ module HammerCLICsv
|
|
26
12
|
PRODUCTS = 'Products'
|
27
13
|
|
28
14
|
def export
|
29
|
-
CSV.open(
|
30
|
-
csv << [NAME,
|
15
|
+
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
|
16
|
+
csv << [NAME, ORGANIZATION, DESCRIPTION, ENABLED, STARTDATE, INTERVAL, PRODUCTS]
|
31
17
|
|
32
18
|
@api.resource(:organizations).call(:index, {:per_page => 999999})['results'].each do |organization|
|
33
19
|
next if option_organization && organization['name'] != option_organization
|
@@ -37,7 +23,6 @@ module HammerCLICsv
|
|
37
23
|
'organization_id' => foreman_organization(:name => organization['name'])
|
38
24
|
})['results'].each do |sync_plan|
|
39
25
|
name = sync_plan['name']
|
40
|
-
count = 1
|
41
26
|
organization_name = organization['name']
|
42
27
|
description = sync_plan['description']
|
43
28
|
enabled = sync_plan['enabled'] ? 'Yes' : 'No'
|
@@ -49,7 +34,7 @@ module HammerCLICsv
|
|
49
34
|
end
|
50
35
|
end
|
51
36
|
products.delete!("\n")
|
52
|
-
csv << [name,
|
37
|
+
csv << [name, organization_name, description, enabled, start_date, interval,
|
53
38
|
products]
|
54
39
|
end
|
55
40
|
end
|
@@ -77,7 +62,7 @@ module HammerCLICsv
|
|
77
62
|
end
|
78
63
|
end
|
79
64
|
|
80
|
-
line[COUNT].
|
65
|
+
count(line[COUNT]).times do |number|
|
81
66
|
name = namify(line[NAME], number)
|
82
67
|
if !@existing[line[ORGANIZATION]].include? name
|
83
68
|
print "Creating sync plan '#{name}'..." if option_verbose?
|
data/lib/hammer_cli_csv/users.rb
CHANGED
@@ -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 UsersCommand < BaseCommand
|
@@ -24,8 +13,8 @@ module HammerCLICsv
|
|
24
13
|
ROLES = 'Roles'
|
25
14
|
|
26
15
|
def export
|
27
|
-
CSV.open(
|
28
|
-
csv << [NAME,
|
16
|
+
CSV.open(option_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
|
17
|
+
csv << [NAME, FIRSTNAME, LASTNAME, EMAIL, ORGANIZATIONS, LOCATIONS, ADMIN, ROLES]
|
29
18
|
@api.resource(:users).call(:index, {:per_page => 999999})['results'].each do |user|
|
30
19
|
if user['organizations']
|
31
20
|
organizations = CSV.generate do |column|
|
@@ -53,7 +42,7 @@ module HammerCLICsv
|
|
53
42
|
end
|
54
43
|
admin = user['admin'] ? 'Yes' : 'No'
|
55
44
|
if user['login'] != 'admin' && !user['login'].start_with?('hidden-')
|
56
|
-
csv << [user['login'],
|
45
|
+
csv << [user['login'], user['firstname'], user['lastname'], user['mail'],
|
57
46
|
organizations, locations, admin, roles]
|
58
47
|
end
|
59
48
|
end
|
@@ -72,7 +61,7 @@ module HammerCLICsv
|
|
72
61
|
end
|
73
62
|
|
74
63
|
def create_users_from_csv(line)
|
75
|
-
line[COUNT].
|
64
|
+
count(line[COUNT]).times do |number|
|
76
65
|
name = namify(line[NAME], number)
|
77
66
|
|
78
67
|
roles = collect_column(line[ROLES]) do |role|
|
@@ -1,16 +1,5 @@
|
|
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
|
def self.version
|
14
|
-
@version ||= Gem::Version.new('1.0.
|
3
|
+
@version ||= Gem::Version.new('1.0.2')
|
15
4
|
end
|
16
5
|
end
|
data/test/content_hosts_test.rb
CHANGED
@@ -17,7 +17,7 @@ describe 'content-hosts' do
|
|
17
17
|
file.rewind
|
18
18
|
|
19
19
|
stdout,stderr = capture {
|
20
|
-
hammer.run(%W{csv content-hosts --verbose --
|
20
|
+
hammer.run(%W{csv content-hosts --verbose --file #{file.path}})
|
21
21
|
}
|
22
22
|
stderr.must_equal ''
|
23
23
|
stdout[0..-2].must_equal "Creating content host '#{hostname}'...done\nUpdating hypervisor and guest associations...done"
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'csv_test_helper')
|
2
|
+
|
3
|
+
require 'stringio'
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
describe 'content-views' do
|
7
|
+
extend CommandTestHelper
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
HammerCLI::Settings.load_from_file 'test/config.yml'
|
11
|
+
end
|
12
|
+
|
13
|
+
context "import" do
|
14
|
+
it "hammer csv content-views --verbose --file does-not-exist" do
|
15
|
+
stdout,stderr = capture {
|
16
|
+
hammer.run(%W{csv content-views --verbose --file does-not-exist})
|
17
|
+
}
|
18
|
+
stdout.must_equal ''
|
19
|
+
stderr[0..-2].must_equal('Error: No such file or directory - does-not-exist')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "hammer csv content-views --verbose --file tempfile" do
|
23
|
+
contentview = "contentview#{rand(10000)}"
|
24
|
+
file = Tempfile.new('content_views_test')
|
25
|
+
file.write("Name,Count,Organization,Description,Composite,Repositories,Lifecycle Environments\n")
|
26
|
+
file.write("#{contentview},1,Mega Corporation,Katello - The Sysadmin's Fortress,No,Default_Organization_View,Library\n")
|
27
|
+
file.rewind
|
28
|
+
|
29
|
+
stdout,stderr = capture {
|
30
|
+
hammer.run(%W{csv content-views --verbose --file #{file.path}})
|
31
|
+
}
|
32
|
+
stdout[0..-2].must_equal "Creating content view '#{contentview}'...done"
|
33
|
+
|
34
|
+
file.unlink
|
35
|
+
end
|
36
|
+
|
37
|
+
it "hammer csv content-views --verbose --file tempfile (no Count column)" do
|
38
|
+
contentview = "contentview#{rand(10000)}"
|
39
|
+
file = Tempfile.new('content_views_test')
|
40
|
+
file.write("Name,Organization,Description,Composite,Repositories,Lifecycle Environments\n")
|
41
|
+
file.write("#{contentview},Mega Corporation,Katello - The Sysadmin's Fortress,No,Default_Organization_View,Library\n")
|
42
|
+
file.rewind
|
43
|
+
|
44
|
+
stdout,stderr = capture {
|
45
|
+
hammer.run(%W{csv content-views --verbose --file #{file.path}})
|
46
|
+
}
|
47
|
+
stdout[0..-2].must_equal "Creating content view '#{contentview}'...done"
|
48
|
+
|
49
|
+
file.unlink
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|