Module: ForemanTeamdynamix::HostExtensions
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/foreman_teamdynamix/host_extensions.rb
Instance Method Summary collapse
- #create_or_update_teamdynamix_asset(save = false) ⇒ Object
- #td_api ⇒ Object
- #teamdynamix_asset(search = false) ⇒ Object
- #teamdynamix_asset_status ⇒ Object
Instance Method Details
#create_or_update_teamdynamix_asset(save = false) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/concerns/foreman_teamdynamix/host_extensions.rb', line 36 def create_or_update_teamdynamix_asset(save = false) if teamdynamix_asset(true) td_api.update_asset(self) @teamdynamix_asset_status ||= :updated_id self.save(validate: false) if save elsif errors.empty? @teamdynamix_asset = td_api.create_asset(self) self.teamdynamix_asset_uid = teamdynamix_asset['ID'] @teamdynamix_asset_status = :created self.save(validate: false) if save else false end rescue StandardError => e errors.add(:base, _("Could not create or update the asset for the host in TeamDynamix: #{e.}")) false end |
#td_api ⇒ Object
11 12 13 |
# File 'app/models/concerns/foreman_teamdynamix/host_extensions.rb', line 11 def td_api @td_api ||= TeamdynamixApi.instance end |
#teamdynamix_asset(search = false) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/models/concerns/foreman_teamdynamix/host_extensions.rb', line 19 def teamdynamix_asset(search = false) @teamdynamix_asset ||= td_api.get_asset(teamdynamix_asset_uid) if search && !@teamdynamix_asset && facts['serialnumber'].present? assets = td_api.search_asset(SerialLike: facts['serialnumber']) if assets.length == 1 @teamdynamix_asset = td_api.get_asset(assets.first['ID']) self.teamdynamix_asset_uid = teamdynamix_asset['ID'] @teamdynamix_asset_status = :updated_search elsif assets.length > 1 errors.add(:base, _("Search for asset in TeamDynamix failed: Found #{assets.length} matching assets")) end end @teamdynamix_asset end |
#teamdynamix_asset_status ⇒ Object
15 16 17 |
# File 'app/models/concerns/foreman_teamdynamix/host_extensions.rb', line 15 def teamdynamix_asset_status @teamdynamix_asset_status end |