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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5aa4a042eea23067c0031d158c3d6dd365cc8ed8
4
- data.tar.gz: a6f95a35f5b7bd3649ca709ba6e916d3b7f68233
3
+ metadata.gz: 15fdcc09436a8ad3ca8f0f0f3ebcfa6772d39e18
4
+ data.tar.gz: 2f9cfc30bf6e5bb244f8073dfe89c6249eeb146b
5
5
  SHA512:
6
- metadata.gz: 7f2135377a4998f4d0fa5bc2701d9222745705115129b6ffdea3315c8be2a46037818c9c0380958ca708837ef276e694137f832657730d753211b8ac5d0925b8
7
- data.tar.gz: 33a553f5ad86b40db58a0a2eb78dc4b79283d90eaa950ed11a3c75dbaf14b1a633b11eec85b59a7c3dd9c59c0c33f1d38f9bf1c4ceb114a29d5c93e301b56ca1
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 teamdynamix_asset_id, update the corresponding TeamDynamix asset.
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.teamdynamix_asset_id
14
+ return [[_('Asset'), 'None Associated']] unless @host.teamdynamix_asset_uid
15
15
 
16
- get_teamdynamix_asset(@host.teamdynamix_asset_id)
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 :teamdynamix_asset_id, uniqueness: { :allow_blank => true }
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.teamdynamix_asset_id = asset['ID']
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.teamdynamix_asset_id = assets.first['ID']
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(teamdynamix_asset_id) if teamdynamix_asset_id
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.teamdynamix_asset_id}")
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.teamdynamix_asset_id }
141
+ payload = { ID: host.teamdynamix_asset_uid }
142
142
  payload.merge(create_asset_payload(host))
143
143
  end
144
144
 
@@ -1,5 +1,5 @@
1
- class AddTeamdynamixAssetIdToHosts < ActiveRecord::Migration
1
+ class AddTeamdynamixAssetUidToHosts < ActiveRecord::Migration
2
2
  def change
3
- add_column :hosts, :teamdynamix_asset_id, :string
3
+ add_column :hosts, :teamdynamix_asset_uid, :string
4
4
  end
5
5
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanTeamdynamix
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
@@ -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.teamdynamix_asset_id)
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.teamdynamix_asset_id = asset['ID']
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.teamdynamix_asset_id = assets.first['ID']
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#teamdynamix_asset_id' do
20
- assert_not_nil(host.teamdynamix_asset_id)
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.teamdynamix_asset_id])
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.teamdynamix_asset_id }.merge!(create_payload) }
39
+ let(:update_payload) { { ID: host.teamdynamix_asset_uid }.merge!(create_payload) }
40
40
  before do
41
- host.teamdynamix_asset_id = sample_asset_id
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_teamdynamix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nipendar Tyagi