hammer_cli_csv 0.0.6 → 1.0.0
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/lib/hammer_cli_csv/activation_keys.rb +57 -65
- data/lib/hammer_cli_csv/base.rb +62 -58
- data/lib/hammer_cli_csv/compute_profiles.rb +13 -15
- data/lib/hammer_cli_csv/compute_resources.rb +13 -15
- data/lib/hammer_cli_csv/content_hosts.rb +105 -86
- data/lib/hammer_cli_csv/content_view_filters.rb +73 -31
- data/lib/hammer_cli_csv/content_views.rb +109 -26
- data/lib/hammer_cli_csv/export.rb +64 -18
- data/lib/hammer_cli_csv/host_collections.rb +35 -33
- data/lib/hammer_cli_csv/hosts.rb +20 -20
- data/lib/hammer_cli_csv/i18n.rb +24 -0
- data/lib/hammer_cli_csv/lifecycle_environments.rb +28 -34
- data/lib/hammer_cli_csv/operating_systems.rb +17 -35
- data/lib/hammer_cli_csv/organizations.rb +13 -7
- data/lib/hammer_cli_csv/products.rb +46 -55
- data/lib/hammer_cli_csv/provisioning_templates.rb +41 -49
- data/lib/hammer_cli_csv/puppet_reports.rb +43 -52
- data/lib/hammer_cli_csv/reports.rb +23 -27
- data/lib/hammer_cli_csv/roles.rb +25 -25
- data/lib/hammer_cli_csv/smart_proxies.rb +13 -15
- data/lib/hammer_cli_csv/subnets.rb +16 -18
- data/lib/hammer_cli_csv/subscriptions.rb +35 -34
- data/lib/hammer_cli_csv/version.rb +1 -1
- data/test/content_hosts_test.rb +61 -0
- data/test/csv_test_helper.rb +22 -3
- data/test/data/activation-keys.csv +118 -118
- data/test/helpers/command.rb +4 -4
- data/test/helpers/resource_disabled.rb +3 -3
- data/test/hosts_test.rb +1 -1
- data/test/roles_test.rb +2 -2
- data/test/setup_test.rb +14 -14
- metadata +19 -4
- data/test/systems_test.rb +0 -71
@@ -25,21 +25,21 @@ module HammerCLICsv
|
|
25
25
|
def export
|
26
26
|
CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
|
27
27
|
csv << [NAME, COUNT, LABEL, ORGANIZATION, REPOSITORY, REPOSITORY_TYPE, REPOSITORY_URL]
|
28
|
-
@api.resource(:organizations)
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
28
|
+
@api.resource(:organizations).call(:index, {
|
29
|
+
:per_page => 999999
|
30
|
+
})['results'].each do |organization|
|
31
|
+
@api.resource(:products).call(:index, {
|
32
|
+
'per_page' => 999999,
|
33
|
+
'enabled' => true,
|
34
|
+
'organization_id' => organization['id']
|
35
|
+
})['results'].each do |product|
|
36
|
+
unless product['provider']['name'] == 'Red Hat'
|
37
|
+
product['repositories'].each do |repository|
|
38
|
+
repository_type = repository['product_type'] == 'custom' ? 'Custom' : 'Red Hat'
|
39
|
+
repository_type += " #{repository['content_type'].capitalize}"
|
40
|
+
csv << [product['name'], 1, product['label'], organization['name'],
|
41
|
+
repository['name'], repository_type, repository['url']]
|
42
|
+
end
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -58,22 +58,20 @@ module HammerCLICsv
|
|
58
58
|
def create_products_from_csv(line)
|
59
59
|
if !@existing_products[line[ORGANIZATION]]
|
60
60
|
@existing_products[line[ORGANIZATION]] = {}
|
61
|
-
@api.resource(:products)
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
})['results'].each do |product|
|
61
|
+
@api.resource(:products).call(:index, {
|
62
|
+
'per_page' => 999999,
|
63
|
+
'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
|
64
|
+
'enabled' => true
|
65
|
+
})['results'].each do |product|
|
67
66
|
@existing_products[line[ORGANIZATION]][product['name']] = product['id']
|
68
67
|
|
69
|
-
@api.resource(:repositories)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
})['results'].each do |repository|
|
68
|
+
@api.resource(:repositories).call(:index, {
|
69
|
+
'page_size' => 999999, 'paged' => true,
|
70
|
+
'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
|
71
|
+
'product_id' => product['id'],
|
72
|
+
'enabled' => true,
|
73
|
+
'library' => true
|
74
|
+
})['results'].each do |repository|
|
77
75
|
@existing_repositories[line[ORGANIZATION] + product['name']] ||= {}
|
78
76
|
@existing_repositories[line[ORGANIZATION] + product['name']][repository['label']] = repository['id']
|
79
77
|
end
|
@@ -89,11 +87,10 @@ module HammerCLICsv
|
|
89
87
|
raise "Red Hat product '#{name}' does not exist in '#{line[ORGANIZATION]}'"
|
90
88
|
end
|
91
89
|
|
92
|
-
product_id = @api.resource(:products)
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
})['id']
|
90
|
+
product_id = @api.resource(:products).call(:create, {
|
91
|
+
'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
|
92
|
+
'name' => name
|
93
|
+
})['id']
|
97
94
|
@existing_products[line[ORGANIZATION]][name] = product_id
|
98
95
|
else
|
99
96
|
# Nothing to update for products
|
@@ -105,13 +102,12 @@ module HammerCLICsv
|
|
105
102
|
repository_name = namify(line[REPOSITORY], number)
|
106
103
|
|
107
104
|
if !@existing_repositories[line[ORGANIZATION] + name][repository_name]
|
108
|
-
@api.resource(:repositories)
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
})['results'].each do |repository|
|
105
|
+
@api.resource(:repositories).call(:index, {
|
106
|
+
'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
|
107
|
+
'library' => true,
|
108
|
+
'all' => false,
|
109
|
+
'product_id' => product_id
|
110
|
+
})['results'].each do |repository|
|
115
111
|
@existing_repositories[line[ORGANIZATION] + name][repository['name']] = repository
|
116
112
|
end
|
117
113
|
end
|
@@ -121,15 +117,14 @@ module HammerCLICsv
|
|
121
117
|
raise "Red Hat product '#{name}' does not have repository '#{repository_name}'" if line[REPOSITORY_TYPE] =~ /Red Hat/
|
122
118
|
|
123
119
|
print "Creating repository '#{repository_name}' in product '#{name}'..." if option_verbose?
|
124
|
-
repository = @api.resource(:repositories)
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
})
|
120
|
+
repository = @api.resource(:repositories).call(:create, {
|
121
|
+
'organization_id' => foreman_organization(:name => line[ORGANIZATION]),
|
122
|
+
'name' => repository_name,
|
123
|
+
'label' => labelize(repository_name),
|
124
|
+
'product_id' => product_id,
|
125
|
+
'url' => line[REPOSITORY_URL],
|
126
|
+
'content_type' => content_type(line[REPOSITORY_TYPE])
|
127
|
+
})
|
133
128
|
@existing_repositories[line[ORGANIZATION] + name][line[LABEL]] = repository
|
134
129
|
puts 'done' if option_verbose?
|
135
130
|
end
|
@@ -138,11 +133,7 @@ module HammerCLICsv
|
|
138
133
|
if repository['sync_state'] == 'finished'
|
139
134
|
puts 'already done' if option_verbose?
|
140
135
|
else
|
141
|
-
|
142
|
-
print 'skipping Red Hat repo sync... so slow!... '
|
143
|
-
else
|
144
|
-
sync_repository(line, repository)
|
145
|
-
end
|
136
|
+
sync_repository(line, repository)
|
146
137
|
print "done\n" if option_verbose?
|
147
138
|
end
|
148
139
|
end
|
@@ -23,10 +23,9 @@ module HammerCLICsv
|
|
23
23
|
def export
|
24
24
|
CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => true}) do |csv|
|
25
25
|
csv << [NAME, COUNT, ORGANIZATIONS, LOCATIONS, KIND, TEMPLATE]
|
26
|
-
@api.resource(:config_templates)
|
27
|
-
|
28
|
-
|
29
|
-
})['results'].each do |template_id|
|
26
|
+
@api.resource(:config_templates).call(:index, {
|
27
|
+
:per_page => 999999
|
28
|
+
})['results'].each do |template_id|
|
30
29
|
template = @api.resource(:config_templates).call(:show, {:id => template_id['id']})
|
31
30
|
name = template['name']
|
32
31
|
count = 1
|
@@ -42,10 +41,9 @@ module HammerCLICsv
|
|
42
41
|
|
43
42
|
def import
|
44
43
|
@existing = {}
|
45
|
-
@api.resource(:config_templates)
|
46
|
-
|
47
|
-
|
48
|
-
})['results'].each do |template|
|
44
|
+
@api.resource(:config_templates).call(:index, {
|
45
|
+
:per_page => 999999
|
46
|
+
})['results'].each do |template|
|
49
47
|
@existing[template['name']] = template['id'] if template
|
50
48
|
end
|
51
49
|
|
@@ -66,27 +64,25 @@ module HammerCLICsv
|
|
66
64
|
name = namify(line[NAME], number)
|
67
65
|
if !@existing.include? name
|
68
66
|
print "Creating provisioning template '#{name}'..." if option_verbose?
|
69
|
-
template_id = @api.resource(:config_templates)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
})['id']
|
67
|
+
template_id = @api.resource(:config_templates).call(:create, {
|
68
|
+
'name' => name,
|
69
|
+
'snippet' => line[KIND] == 'snippet',
|
70
|
+
'template_kind_id' => line[KIND] == 'snippet' ? nil : foreman_template_kind(:name => line[KIND]),
|
71
|
+
'organization_ids' => organizations,
|
72
|
+
'location_ids' => locations,
|
73
|
+
'template' => line[TEMPLATE]
|
74
|
+
})['id']
|
78
75
|
else
|
79
76
|
print "Updating provisioning template '#{name}'..." if option_verbose?
|
80
|
-
template_id = @api.resource(:config_templates)
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
})['id']
|
77
|
+
template_id = @api.resource(:config_templates).call(:update, {
|
78
|
+
'id' => @existing[name],
|
79
|
+
'name' => name,
|
80
|
+
'snippet' => line[KIND] == 'snippet',
|
81
|
+
'template_kind_id' => line[KIND] == 'snippet' ? nil : foreman_template_kind(:name => line[KIND]),
|
82
|
+
'organization_ids' => organizations,
|
83
|
+
'location_ids' => locations,
|
84
|
+
'template' => line[TEMPLATE]
|
85
|
+
})['id']
|
90
86
|
end
|
91
87
|
@existing[name] = template_id
|
92
88
|
|
@@ -94,43 +90,39 @@ module HammerCLICsv
|
|
94
90
|
template_organizations ||= {}
|
95
91
|
organizations.each do |organization_id|
|
96
92
|
if template_organizations[organization_id].nil?
|
97
|
-
template_organizations[organization_id] = @api.resource(:organizations)
|
98
|
-
|
99
|
-
|
100
|
-
})['config_templates'].collect do |template|
|
93
|
+
template_organizations[organization_id] = @api.resource(:organizations).call(:show, {
|
94
|
+
'id' => organization_id
|
95
|
+
})['config_templates'].collect do |template|
|
101
96
|
template['id']
|
102
97
|
end
|
103
98
|
end
|
104
99
|
if !template_organizations[organization_id].include? template_id
|
105
100
|
template_organizations[organization_id] += [template_id]
|
106
|
-
@api.resource(:organizations)
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
})
|
101
|
+
@api.resource(:organizations).call(:update, {
|
102
|
+
'id' => organization_id,
|
103
|
+
'organization' => {
|
104
|
+
'config_template_ids' => template_organizations[organization_id]
|
105
|
+
}
|
106
|
+
})
|
113
107
|
end
|
114
108
|
end
|
115
109
|
template_locations ||= {}
|
116
110
|
locations.each do |location_id|
|
117
111
|
if template_locations[location_id].nil?
|
118
|
-
template_locations[location_id] = @api.resource(:locations)
|
119
|
-
|
120
|
-
|
121
|
-
})['config_templates'].collect do |template|
|
112
|
+
template_locations[location_id] = @api.resource(:locations).call(:show, {
|
113
|
+
'id' => location_id
|
114
|
+
})['config_templates'].collect do |template|
|
122
115
|
template['id']
|
123
116
|
end
|
124
117
|
end
|
125
118
|
if !template_locations[location_id].include? template_id
|
126
119
|
template_locations[location_id] += [template_id]
|
127
|
-
@api.resource(:locations)
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
})
|
120
|
+
@api.resource(:locations).call(:update, {
|
121
|
+
'id' => location_id,
|
122
|
+
'location' => {
|
123
|
+
'config_template_ids' => template_locations[location_id]
|
124
|
+
}
|
125
|
+
})
|
134
126
|
end
|
135
127
|
end
|
136
128
|
|
@@ -56,20 +56,17 @@ module HammerCLICsv
|
|
56
56
|
CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
|
57
57
|
csv << [NAME, COUNT, ORGANIZATION, ENVIRONMENT, CONTENTVIEW, SYSTEMGROUPS, VIRTUAL, HOST,
|
58
58
|
OPERATINGSYSTEM, ARCHITECTURE, SOCKETS, RAM, CORES, SLA, PRODUCTS, SUBSCRIPTIONS]
|
59
|
-
@api.resource(:organizations)
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
'id' => system['uuid'],
|
71
|
-
'fields' => 'full'
|
72
|
-
})
|
59
|
+
@api.resource(:organizations).call(:index, {
|
60
|
+
:per_page => 999999
|
61
|
+
})['results'].each do |organization|
|
62
|
+
@api.resource(:systems).call(:index, {
|
63
|
+
'per_page' => 999999,
|
64
|
+
'organization_id' => organization['id']
|
65
|
+
})['results'].each do |system|
|
66
|
+
system = @api.resource(:systems).call(:show, {
|
67
|
+
'id' => system['uuid'],
|
68
|
+
'fields' => 'full'
|
69
|
+
})
|
73
70
|
|
74
71
|
name = system['name']
|
75
72
|
count = 1
|
@@ -98,10 +95,9 @@ module HammerCLICsv
|
|
98
95
|
end
|
99
96
|
products.delete!("\n")
|
100
97
|
subscriptions = CSV.generate do |column|
|
101
|
-
column << @api.resource(:subscriptions)
|
102
|
-
|
103
|
-
|
104
|
-
})['results'].collect do |subscription|
|
98
|
+
column << @api.resource(:subscriptions).call(:index, {
|
99
|
+
'system_id' => system['uuid']
|
100
|
+
})['results'].collect do |subscription|
|
105
101
|
"#{subscription['product_id']}|#{subscription['product_name']}"
|
106
102
|
end
|
107
103
|
end
|
@@ -123,11 +119,10 @@ module HammerCLICsv
|
|
123
119
|
|
124
120
|
print 'Updating host and guest associations...' if option_verbose?
|
125
121
|
@host_guests.each do |host_id, guest_ids|
|
126
|
-
@api.resource(:systems)
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
})
|
122
|
+
@api.resource(:systems).call(:update, {
|
123
|
+
'id' => host_id,
|
124
|
+
'guest_ids' => guest_ids
|
125
|
+
})
|
131
126
|
end
|
132
127
|
puts 'done' if option_verbose?
|
133
128
|
end
|
@@ -135,11 +130,10 @@ module HammerCLICsv
|
|
135
130
|
def create_systems_from_csv(line)
|
136
131
|
if !@existing[line[ORGANIZATION]]
|
137
132
|
@existing[line[ORGANIZATION]] = {}
|
138
|
-
@api.resource(:systems)
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
})['results'].each do |system|
|
133
|
+
@api.resource(:systems).call(:index, {
|
134
|
+
'organization_id' => line[ORGANIZATION],
|
135
|
+
'per_page' => 999999
|
136
|
+
})['results'].each do |system|
|
143
137
|
@existing[line[ORGANIZATION]][system['name']] = system['uuid'] if system
|
144
138
|
end
|
145
139
|
end
|
@@ -154,29 +148,27 @@ module HammerCLICsv
|
|
154
148
|
|
155
149
|
if !@existing[line[ORGANIZATION]].include? name
|
156
150
|
print "Creating system '#{name}'..." if option_verbose?
|
157
|
-
system_id = @api.resource(:systems)
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
})['uuid']
|
151
|
+
system_id = @api.resource(:systems).call(:create, {
|
152
|
+
'name' => name,
|
153
|
+
'organization_id' => line[ORGANIZATION],
|
154
|
+
'environment_id' => lifecycle_environment(line[ORGANIZATION], :name => line[ENVIRONMENT]),
|
155
|
+
'content_view_id' => lifecycle_contentview(line[ORGANIZATION], :name => line[CONTENTVIEW]),
|
156
|
+
'facts' => facts(line),
|
157
|
+
'installed_products' => products(line),
|
158
|
+
'type' => 'system'
|
159
|
+
})['uuid']
|
167
160
|
@existing[line[ORGANIZATION]][name] = system_id
|
168
161
|
else
|
169
162
|
print "Updating system '#{name}'..." if option_verbose?
|
170
163
|
puts line
|
171
|
-
system_id = @api.resource(:systems)
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
})['uuid']
|
164
|
+
system_id = @api.resource(:systems).call(:update, {
|
165
|
+
'id' => @existing[line[ORGANIZATION]][name],
|
166
|
+
'name' => name,
|
167
|
+
'environment_id' => katello_environment(line[ORGANIZATION], :name => line[ENVIRONMENT]),
|
168
|
+
'content_view_id' => katello_contentview(line[ORGANIZATION], :name => line[CONTENTVIEW]),
|
169
|
+
'facts' => facts(line),
|
170
|
+
'installed_products' => products(line)
|
171
|
+
})['uuid']
|
180
172
|
end
|
181
173
|
|
182
174
|
if line[VIRTUAL] == 'Yes' && line[HOST]
|
@@ -212,11 +204,10 @@ module HammerCLICsv
|
|
212
204
|
|
213
205
|
def set_host_collections(system_id, line)
|
214
206
|
CSV.parse_line(line[SYSTEMGROUPS]).each do |hostcollection_name|
|
215
|
-
@api.resource(:hostcollections)
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
})
|
207
|
+
@api.resource(:hostcollections).call(:add_systems, {
|
208
|
+
'id' => katello_hostcollection(line[ORGANIZATION], :name => hostcollection_name),
|
209
|
+
'system_ids' => [system_id]
|
210
|
+
})
|
220
211
|
end
|
221
212
|
end
|
222
213
|
|
@@ -27,10 +27,9 @@ module HammerCLICsv
|
|
27
27
|
def export
|
28
28
|
CSV.open(option_csv_file || '/dev/stdout', 'wb', {:force_quotes => false}) do |csv|
|
29
29
|
csv << [NAME, COUNT]
|
30
|
-
@api.resource(:reports)
|
31
|
-
|
32
|
-
|
33
|
-
})['results'].each do |report|
|
30
|
+
@api.resource(:reports).call(:index, {
|
31
|
+
'per_page' => 999999
|
32
|
+
})['results'].each do |report|
|
34
33
|
csv << [report['host_name'], 1, report['metrics'].to_json]
|
35
34
|
end
|
36
35
|
end
|
@@ -40,10 +39,9 @@ module HammerCLICsv
|
|
40
39
|
|
41
40
|
def import
|
42
41
|
@existing_reports = {}
|
43
|
-
@api.resource(:reports)
|
44
|
-
|
45
|
-
|
46
|
-
})['results'].each do |report|
|
42
|
+
@api.resource(:reports).call(:index, {
|
43
|
+
'per_page' => 999999
|
44
|
+
})['results'].each do |report|
|
47
45
|
@existing_reports[report['name']] = report['id']
|
48
46
|
end
|
49
47
|
|
@@ -59,28 +57,26 @@ module HammerCLICsv
|
|
59
57
|
if !@existing_reports[name]
|
60
58
|
print "Creating report '#{name}'..." if option_verbose?
|
61
59
|
reported_at = line[TIME] || Time.now
|
62
|
-
report = @api.resource(:reports)
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
})
|
60
|
+
report = @api.resource(:reports).call(:create, {
|
61
|
+
'host' => name,
|
62
|
+
'reported_at' => reported_at,
|
63
|
+
'status' => {
|
64
|
+
'applied' => line[APPLIED],
|
65
|
+
'restarted' => line[RESTARTED],
|
66
|
+
'failed' => line[FAILED],
|
67
|
+
'failed_restarts' => line[FAILED_RESTARTS],
|
68
|
+
'skipped' => line[SKIPPED],
|
69
|
+
'pending' => line[PENDING]
|
70
|
+
},
|
71
|
+
'metrics' => JSON.parse(line[METRICS]),
|
72
|
+
'logs' => []
|
73
|
+
})
|
77
74
|
@existing_reports[name] = report['id']
|
78
75
|
else
|
79
76
|
print "Updating report '#{name}'..." if option_verbose?
|
80
|
-
@api.resource(:reports)
|
81
|
-
|
82
|
-
|
83
|
-
})
|
77
|
+
@api.resource(:reports).call(:update, {
|
78
|
+
'id' => @existing_reports[name]
|
79
|
+
})
|
84
80
|
end
|
85
81
|
|
86
82
|
puts 'done' if option_verbose?
|