foreman_templates 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/concerns/foreman_templates/provisioning_template_import.rb +10 -12
- data/app/models/concerns/foreman_templates/ptable_import.rb +15 -15
- data/app/models/concerns/foreman_templates/template_import.rb +21 -0
- data/lib/foreman_templates/version.rb +1 -1
- data/lib/tasks/foreman_templates_tasks.rake +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82ee874e71d9e9079295163e6047be8d000ec0da
|
4
|
+
data.tar.gz: dced21a45bdb893b228b1ac6656eecfaa38bee92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4177cb40d2c6dfa46b6ce5435320b7b84d4d870846a59c82b48824a46d16466b92b16c38a7304cbf7ed48efc74fc421425bbaf99211e8751f2f737fdcb4c93f2
|
7
|
+
data.tar.gz: 6e06c16092fe06fd6913575e3dbf618658a4ea1c1723187ac57ce680a785b4407ce181235b4bdd15e3e322b848e28f753c196baf8f05a4d18702cd8ab86d7397
|
@@ -17,7 +17,9 @@ module ForemanTemplates::ProvisioningTemplateImport
|
|
17
17
|
:snippet => false,
|
18
18
|
:template_kind_id => kind.id
|
19
19
|
}
|
20
|
-
oses
|
20
|
+
oses = map_metadata(metadata, 'oses')
|
21
|
+
locations = map_metadata(metadata, 'locations')
|
22
|
+
organizations = map_metadata(metadata, 'organizations')
|
21
23
|
|
22
24
|
# Printout helpers
|
23
25
|
c_or_u = template.new_record? ? 'Created' : 'Updated'
|
@@ -25,6 +27,8 @@ module ForemanTemplates::ProvisioningTemplateImport
|
|
25
27
|
|
26
28
|
if (metadata['associate'] == 'new' && template.new_record?) || (metadata['associate'] == 'always')
|
27
29
|
data[:operatingsystem_ids] = oses.map(&:id)
|
30
|
+
data[:location_ids] = locations.map(&:id)
|
31
|
+
data[:organization_ids] = organizations.map(&:id)
|
28
32
|
end
|
29
33
|
|
30
34
|
if data[:template] != template.template
|
@@ -36,11 +40,15 @@ module ForemanTemplates::ProvisioningTemplateImport
|
|
36
40
|
status = template.update_attributes(data)
|
37
41
|
result = " #{c_or_u} Template #{id_string}:#{name}"
|
38
42
|
result += "\n Operatingsystem Associations:\n - #{oses.map(&:fullname).join("\n - ")}" unless oses.empty?
|
39
|
-
|
43
|
+
result += "\n Organizations Associations:\n - #{organizations.map(&:name).join("\n - ")}" unless organizations.empty?
|
44
|
+
result += "\n Location Associations:\n - #{locations.map(&:name).join("\n - ")}" unless locations.empty?
|
45
|
+
elsif data[:operatingsystem_ids] || data[:location_ids] || data[:organization_ids]
|
40
46
|
diff = nil
|
41
47
|
status = template.update_attributes(data)
|
42
48
|
result = " #{c_or_u} Template Associations #{id_string}:#{name}"
|
43
49
|
result += "\n Operatingsystem Associations:\n - #{oses.map(&:fullname).join("\n - ")}" unless oses.empty?
|
50
|
+
result += "\n Organizations Associations:\n - #{organizations.map(&:name).join("\n - ")}" unless organizations.empty?
|
51
|
+
result += "\n Location Associations:\n - #{locations.map(&:name).join("\n - ")}" unless locations.empty?
|
44
52
|
else
|
45
53
|
diff = nil
|
46
54
|
status = true
|
@@ -48,15 +56,5 @@ module ForemanTemplates::ProvisioningTemplateImport
|
|
48
56
|
end
|
49
57
|
{ :diff => diff, :status => status, :result => result }
|
50
58
|
end
|
51
|
-
|
52
|
-
def map_oses(metadata)
|
53
|
-
if metadata['oses']
|
54
|
-
metadata['oses'].map do |os|
|
55
|
-
Operatingsystem.all.map { |db| db.to_label =~ /^#{os}/ ? db : nil }
|
56
|
-
end.flatten.compact
|
57
|
-
else
|
58
|
-
[]
|
59
|
-
end
|
60
|
-
end
|
61
59
|
end
|
62
60
|
end
|
@@ -8,15 +8,21 @@ module ForemanTemplates::PtableImport
|
|
8
8
|
|
9
9
|
# Data
|
10
10
|
ptable = Ptable.where(:name => name).first_or_initialize
|
11
|
-
data = {
|
12
|
-
|
11
|
+
data = {
|
12
|
+
:layout => text
|
13
|
+
}
|
14
|
+
oses = map_metadata(metadata, 'oses')
|
15
|
+
locations = map_metadata(metadata, 'locations')
|
16
|
+
organizations = map_metadata(metadata, 'organizations')
|
13
17
|
|
14
18
|
# Printout helpers
|
15
19
|
c_or_u = ptable.new_record? ? 'Created' : 'Updated'
|
16
20
|
id_string = ('id' + ptable.id) rescue ''
|
17
21
|
|
18
22
|
if (metadata['associate'] == 'new' && ptable.new_record?) || (metadata['associate'] == 'always')
|
19
|
-
data[:os_family]
|
23
|
+
data[:os_family] = oses.map(&:family).uniq.first
|
24
|
+
data[:location_ids] = locations.map(&:id)
|
25
|
+
data[:organization_ids] = organizations.map(&:id)
|
20
26
|
end
|
21
27
|
|
22
28
|
if data[:layout] != ptable.layout
|
@@ -27,11 +33,16 @@ module ForemanTemplates::PtableImport
|
|
27
33
|
).to_s(:color)
|
28
34
|
status = ptable.update_attributes(data)
|
29
35
|
result = " #{c_or_u} Ptable #{id_string}:#{name}"
|
30
|
-
|
36
|
+
result += "\n Operatingsystem Family:\n - #{oses.map(&:family).uniq.first}" unless oses.empty?
|
37
|
+
result += "\n Organizations Associations:\n - #{organizations.map(&:name).join("\n - ")}" unless organizations.empty?
|
38
|
+
result += "\n Location Associations:\n - #{locations.map(&:name).join("\n - ")}" unless locations.empty?
|
39
|
+
elsif data[:os_family] || data[:location_ids] || data[:organization_ids]
|
31
40
|
diff = nil
|
32
41
|
status = ptable.update_attributes(data)
|
33
42
|
result = " #{c_or_u} Ptable Associations #{id_string}:#{name}"
|
34
43
|
result += "\n Operatingsystem Family:\n - #{oses.map(&:family).uniq.first}" unless oses.empty?
|
44
|
+
result += "\n Organizations Associations:\n - #{organizations.map(&:name).join("\n - ")}" unless organizations.empty?
|
45
|
+
result += "\n Location Associations:\n - #{locations.map(&:name).join("\n - ")}" unless locations.empty?
|
35
46
|
else
|
36
47
|
diff = nil
|
37
48
|
status = true
|
@@ -39,16 +50,5 @@ module ForemanTemplates::PtableImport
|
|
39
50
|
end
|
40
51
|
{ :diff => diff, :status => status, :result => result }
|
41
52
|
end
|
42
|
-
|
43
|
-
# TODO: DRY this, it's copied from ProvisioningTemplateImport
|
44
|
-
def map_oses(metadata)
|
45
|
-
if metadata['oses']
|
46
|
-
metadata['oses'].map do |os|
|
47
|
-
Operatingsystem.all.map { |db| db.to_label =~ /^#{os}/ ? db : nil }
|
48
|
-
end.flatten.compact
|
49
|
-
else
|
50
|
-
[]
|
51
|
-
end
|
52
|
-
end
|
53
53
|
end
|
54
54
|
end
|
@@ -29,5 +29,26 @@ module ForemanTemplates::TemplateImport
|
|
29
29
|
end
|
30
30
|
{ :diff => diff, :status => status, :result => result }
|
31
31
|
end
|
32
|
+
|
33
|
+
def map_metadata(metadata, param)
|
34
|
+
if metadata[param]
|
35
|
+
case param
|
36
|
+
when 'oses'
|
37
|
+
metadata[param].map do |os|
|
38
|
+
Operatingsystem.all.map { |db| db.to_label =~ /^#{os}/ ? db : nil }
|
39
|
+
end.flatten.compact
|
40
|
+
when 'locations'
|
41
|
+
metadata[param].map do |loc|
|
42
|
+
Location.all.map { |db| db.name =~ /^#{loc}/ ? db : nil }
|
43
|
+
end.flatten.compact
|
44
|
+
when 'organizations'
|
45
|
+
metadata[param].map do |org|
|
46
|
+
Organization.all.map { |db| db.name =~ /^#{org}/ ? db : nil }
|
47
|
+
end.flatten.compact
|
48
|
+
end
|
49
|
+
else
|
50
|
+
[]
|
51
|
+
end
|
52
|
+
end
|
32
53
|
end
|
33
54
|
end
|
@@ -9,7 +9,7 @@ namespace :templates do
|
|
9
9
|
#* prefix => The string all imported templates should begin with [Community ]
|
10
10
|
#* dirname => The directory within the git tree containing the templates [/]
|
11
11
|
#* filter => Import names matching this regex (case-insensitive; snippets are not filtered)
|
12
|
-
#* associate => Associate to OS, always, new or never [new]
|
12
|
+
#* associate => Associate to OS's, Locations & Organizations. Options are: always, new or never [new]
|
13
13
|
|
14
14
|
results = ForemanTemplates::TemplateImporter.new({
|
15
15
|
verbose: ENV['verbose'],
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_templates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Sutcliffe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: diffy
|