Service Model error when running code from Mastering CloudForms book


#1

I’m trying to implement the below method from Mastering CloudForms Automation to list all services as items in a drop down list:
https://github.com/pemcg/oreilly-mastering-cloudforms-automation/blob/master/chapter37/scripts/list_services.rb

Any time I go to the dialog the list drop down says <Script error> .
Looking at the error in automation.log I see:

[----] I, [2017-08-15T15:07:07.522814 #3030:ec76b0]  INFO -- : <AEMethod [/Operations/Methods/list_services]> Starting
[----] I, [2017-08-15T15:07:08.283834 #3030:69a960]  INFO -- : <AEMethod list_services> rbac filters: []
[----] E, [2017-08-15T15:07:08.290705 #3030:10f4398] ERROR -- : <AEMethod list_services> [Service Model not found (MiqAeException::ServiceNotFound)]
(druby://127.0.0.1:41659) /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_method_service/miq_ae_service_model_base.rb:21:in `rescue in method_missing'
(druby://127.0.0.1:41659) /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_method_service/miq_ae_service_model_base.rb:18:in `method_missing'
(druby://127.0.0.1:41659) /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/drb/drb.rb:1624:in `perform_without_block'
(druby://127.0.0.1:41659) /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/drb/drb.rb:1584:in `perform'
(druby://127.0.0.1:41659) /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/drb/drb.rb:1657:in `block (2 levels) in main_loop'
(druby://127.0.0.1:41659) /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/drb/drb.rb:1653:in `loop'
(druby://127.0.0.1:41659) /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/drb/drb.rb:1653:in `block in main_loop'
/Operations/Methods/list_services:37:in `<main>'
[----] I, [2017-08-15T15:07:08.309980 #3030:ec76b0]  INFO -- : <AEMethod [/Operations/Methods/list_services]> Ending

It seems pretty clear that there’s some trouble executing line 37: $evm.vmdb(:service).find(:all).each do |service|

Does anyone have any advise on where to start troubleshooting?

Version fine-2.20170724083520_6137fff


#2

Hey @switchboard.op

The find method in Rails deprecated some functionality (see http://allanweb.ca/blog/2013/11/10/dealing-with-rails-4-deprecations/ for example)

I would suggest using the following syntax:

$evm.vmdb(:service).all.each do |service|

cc @pemcg


#3

Thanks @gmccullough

Such any easy fix but it probably would have taken me ages to figure out it was a deprecation.

I’ll be reading through that article, thanks again.


#4

Unfortunately several things have changed since the publication of the O’Reilly book. There’s an updated online version that covers CloudForms 4.2 and ManageIQ Euwe though, the chapter in question is here: https://pemcg.gitbooks.io/mastering-automation-in-cloudforms-4-2-and-manage/content/service_hierarchies/chapter.html

It shows the corrected code that @gmccullough suggested.

hope this helps,
pemcg