Can't .find_by_all_the_things in automation_task


#1

Hi all

I was pretty excited about being able to raise automation requests via $evm.execute instead of having to use the API - this means I can avoid making users enter the passwords for each request, and really is cool.

However, as I’m working though a new automation method using this way of doing things, I’ve run into this little problem…

When, in the automation_task, I try to locate anything in the vmdb, such as doing the old " vm = $evm.vmdb(‘vm’).find_by_guid($evm.root[‘guid’]) " trick - no matter how or what I search, I get nil.

Is this a bug? Or is it by design, and I’m just not smart enough to figure out how to work around it? :slightly_smiling:


#2

@gmccullough can you review this question from Stephen.


#3

@Stephen_McKay

The only reason I would expect that call to fail is if the guid being passed is not found or invalid for some other reason. (For example, does it contain leading or trailing whitespace?)

Can you try something as simple as this to make sure you are getting objects back:

vm = $evm.vmdb('vm').first

If this works you can try some like this that uses the find_by_guid call to validate:

vm_guid = $evm.vmdb('vm').first.guid 
vm = $evm.vmdb('vm').find_by_guid(vm_guid)

Please give these a try and let me know what your results are.


#4

Hi Greg,

Yes indeed. If I run the call from the VM button (so $evm.root[‘vmdb_object_type’] is ‘vm’) searching vmdb is all ok. But if I enter the same code as an automation_task (so $evm.root[‘vmdb_object_type’] is ‘automation_task’) it returns nil.

However, between typing the above and finishing this post I decided to experiment a little further, and found the problem. :slightly_smiling:

The guid variable I was using to do the up was nil. But I was pasing it correctly in $evm.root[‘automation_task’].options[:attrs]. However, I was using a symbol as a key to try to grab it from the attrs hash, wheras I had populated the hash with strings as keys, not symbols. Stupid ruby n00b error.

No bug. Just me. Thans for getting me on track, anyway! And Also, many thanks for the PR exposing storage_files to automate.

:slight_smile: