Service Model error when running code from Mastering CloudForms book

I’m trying to implement the below method from Mastering CloudForms Automation to list all services as items in a drop down list:

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:// /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:// /var/www/miq/vmdb/lib/miq_automation_engine/engine/miq_ae_method_service/miq_ae_service_model_base.rb:18:in `method_missing'
(druby:// /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/drb/drb.rb:1624:in `perform_without_block'
(druby:// /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/drb/drb.rb:1584:in `perform'
(druby:// /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/drb/drb.rb:1657:in `block (2 levels) in main_loop'
(druby:// /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/drb/drb.rb:1653:in `loop'
(druby:// /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

Hey @switchboard.op

The find method in Rails deprecated some functionality (see for example)

I would suggest using the following syntax:

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

cc @pemcg

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.

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:

It shows the corrected code that @gmccullough suggested.

hope this helps,