foreman_teamdynamix 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/helpers/concerns/foreman_teamdynamix/hosts_helper_extensions.rb +2 -2
- data/app/models/concerns/foreman_teamdynamix/host_extensions.rb +4 -4
- data/app/services/teamdynamix_api.rb +2 -2
- data/db/migrate/20171228033228_add_teamdynamix_asset_id_to_hosts.foreman_teamdynamix.rb +2 -2
- data/lib/foreman_teamdynamix/version.rb +1 -1
- data/lib/tasks/teamdynamix.rake +3 -3
- data/test/models/host_extensions_test.rb +3 -3
- data/test/services/teamdynamix_api_test.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15fdcc09436a8ad3ca8f0f0f3ebcfa6772d39e18
|
4
|
+
data.tar.gz: 2f9cfc30bf6e5bb244f8073dfe89c6249eeb146b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2c46411f760a877fe86ff0f298a16d24c282d15d1a57cc3f970abe71edf863d9be5b92e9445cb0d731513d96cb857d09da74ee56bbd856a97d07a9cff51f666
|
7
|
+
data.tar.gz: ce827278475838d58e25d4f591a9dfc9319dce24c101fd910d91c85997b3dab6d8a0e60ad5c8fb81fad9cd43084b46b7aae47170a7f940ffb670d7a800018d41
|
data/README.md
CHANGED
@@ -83,7 +83,7 @@ Add the teamdynamix config to <foreman_repo>/config/settings.yaml
|
|
83
83
|
rake teamdynamix:sync:hosts
|
84
84
|
```
|
85
85
|
Scans the hosts and sync them with TeamDynamix.
|
86
|
-
* If host has
|
86
|
+
* If host has teamdynamix_asset_uid, update the corresponding TeamDynamix asset.
|
87
87
|
* If host name matches the asset SerialNumber, update the host and the corresponding TeamDynamix asset.
|
88
88
|
* If host has no matching asset, create an asset in TeamDynamix with configured fields.
|
89
89
|
|
@@ -11,9 +11,9 @@ module ForemanTeamdynamix
|
|
11
11
|
|
12
12
|
def teamdynamix_fields
|
13
13
|
td_pane_fields = SETTINGS[:teamdynamix][:fields] || DEFAULT_TD_PANE_FIELDS
|
14
|
-
return [[_('Asset'), 'None Associated']] unless @host.
|
14
|
+
return [[_('Asset'), 'None Associated']] unless @host.teamdynamix_asset_uid
|
15
15
|
|
16
|
-
get_teamdynamix_asset(@host.
|
16
|
+
get_teamdynamix_asset(@host.teamdynamix_asset_uid)
|
17
17
|
|
18
18
|
# always display a link to the asset
|
19
19
|
fields = [asset_uri]
|
@@ -9,7 +9,7 @@ module ForemanTeamdynamix
|
|
9
9
|
included do
|
10
10
|
before_create :create_teamdynamix_asset
|
11
11
|
before_destroy :retire_teamdynamix_asset
|
12
|
-
validates :
|
12
|
+
validates :teamdynamix_asset_uid, uniqueness: { :allow_blank => true }
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
@@ -20,11 +20,11 @@ module ForemanTeamdynamix
|
|
20
20
|
|
21
21
|
if assets.empty?
|
22
22
|
asset = td_api.create_asset(self)
|
23
|
-
self.
|
23
|
+
self.teamdynamix_asset_uid = asset['ID']
|
24
24
|
elsif assets.length > 1
|
25
25
|
raise 'Found more than 1 existing asset'
|
26
26
|
else
|
27
|
-
self.
|
27
|
+
self.teamdynamix_asset_uid = assets.first['ID']
|
28
28
|
td_api.update_asset(self)
|
29
29
|
end
|
30
30
|
rescue StandardError => e
|
@@ -33,7 +33,7 @@ module ForemanTeamdynamix
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def retire_teamdynamix_asset
|
36
|
-
td_api.retire_asset(
|
36
|
+
td_api.retire_asset(teamdynamix_asset_uid) if teamdynamix_asset_uid
|
37
37
|
rescue StandardError => e
|
38
38
|
errors.add(:base, _("Could not retire the asset for the host in TeamDynamix: #{e.message}"))
|
39
39
|
false
|
@@ -36,7 +36,7 @@ class TeamdynamixApi
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def update_asset(host)
|
39
|
-
uri = URI.parse(API_URL + "/#{APP_ID}/assets/#{host.
|
39
|
+
uri = URI.parse(API_URL + "/#{APP_ID}/assets/#{host.teamdynamix_asset_uid}")
|
40
40
|
rest(:post, uri, update_asset_payload(host))
|
41
41
|
end
|
42
42
|
|
@@ -138,7 +138,7 @@ class TeamdynamixApi
|
|
138
138
|
end
|
139
139
|
|
140
140
|
def update_asset_payload(host)
|
141
|
-
payload = { ID: host.
|
141
|
+
payload = { ID: host.teamdynamix_asset_uid }
|
142
142
|
payload.merge(create_asset_payload(host))
|
143
143
|
end
|
144
144
|
|
data/lib/tasks/teamdynamix.rake
CHANGED
@@ -21,20 +21,20 @@ namespace :teamdynamix do
|
|
21
21
|
|
22
22
|
Host.all.each do |h|
|
23
23
|
# if asset exists, update it
|
24
|
-
if td_api.asset_exist?(h.
|
24
|
+
if td_api.asset_exist?(h.teamdynamix_asset_uid)
|
25
25
|
td_api.update_asset(h)
|
26
26
|
update_from_asset_id += 1
|
27
27
|
else
|
28
28
|
assets = td_api.search_asset(SerialLike: h.name)
|
29
29
|
if assets.empty?
|
30
30
|
asset = td_api.create_asset(h)
|
31
|
-
h.
|
31
|
+
h.teamdynamix_asset_uid = asset['ID']
|
32
32
|
errors.push("Could not save host: #{h.name} (#{h.id})") unless h.save
|
33
33
|
creates += 1
|
34
34
|
elsif assets.length > 1
|
35
35
|
errors.push("Could not sync: Found more than 1 asset for #{h.name} (#{h.id})")
|
36
36
|
else
|
37
|
-
h.
|
37
|
+
h.teamdynamix_asset_uid = assets.first['ID']
|
38
38
|
td_api.update_asset(h)
|
39
39
|
errors.push("Could not save host: #{h.name} (#{h.id})") unless h.save
|
40
40
|
updates_from_serial_matching += 1
|
@@ -16,8 +16,8 @@ class HostExtensionsTests < ActiveSupport::TestCase
|
|
16
16
|
assert_send([td_api, :create_asset, host])
|
17
17
|
end
|
18
18
|
|
19
|
-
it 'sets host#
|
20
|
-
assert_not_nil(host.
|
19
|
+
it 'sets host#teamdynamix_asset_uid' do
|
20
|
+
assert_not_nil(host.teamdynamix_asset_uid)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -31,7 +31,7 @@ class HostExtensionsTests < ActiveSupport::TestCase
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'calls Teamdynamix API to retire an asset' do
|
34
|
-
assert_send([td_api, :retire_asset, host.
|
34
|
+
assert_send([td_api, :retire_asset, host.teamdynamix_asset_uid])
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -36,9 +36,9 @@ class TeamdynamixApiTest < ActiveSupport::TestCase
|
|
36
36
|
|
37
37
|
describe '#update_asset' do
|
38
38
|
let(:update_path) { get_asset_path }
|
39
|
-
let(:update_payload) { { ID: host.
|
39
|
+
let(:update_payload) { { ID: host.teamdynamix_asset_uid }.merge!(create_payload) }
|
40
40
|
before do
|
41
|
-
host.
|
41
|
+
host.teamdynamix_asset_uid = sample_asset_id
|
42
42
|
SETTINGS[:teamdynamix][:api][:create] = { StatusID: create_status_id,
|
43
43
|
Attributes: custom_attributes }
|
44
44
|
end
|