[SOLVED] Event Stream data is of class DRb::DRbUnknown


#1

Hi,

I am trying to catch the data of an Event Stream. The event comes from VMware provider and its type is “DVPortgroupCreatedEvent”. For that I get $evm.root['event_stream']. However, the full_data attribute of the Event Stream is of class DRb::DRbUnknown and I cannot read information from it.

I have investigated using rails console with the .irbrc file provided in @pemcg book: https://github.com/pemcg/mastering-automation-in-cloudforms-and-manageiq/blob/master/chapter6.asciidoc. For that I call:

irb(main):001:0> require 'json'
=> false
irb(main):002:0> es = $evm.vmdb(:event_stream).find_by_id('51000000008831')
=> #<MiqAeServiceEmsEvent:0x5f3a958 @object=#<EmsEvent id: 51000000008831, event_type: "DVPortgroupCreatedEvent", message: "dvPort group vxw-dvs-41-virtualwire-17-sid-5008-LS...", timestamp: "2016-11-20 20:58:19", host_name: nil, host_id: nil, vm_name: nil, vm_location: nil, vm_or_template_id: nil, ...>
irb(main):005:0> puts JSON.pretty_generate(es.full_data)
{
  "key": "209647",
  "chainId": "209646",
  "createdTime": "2016-11-20T20:58:19.219063Z",
  "userName": "VSPHERE.LOCAL\\Administrator",
  "datacenter": {
    "name": "Nested-DC",
    "datacenter": "datacenter-2"
  },
  "net": {
    "name": "vxw-dvs-41-virtualwire-17-sid-5008-LS-test-fdupont9",
    "network": "dvportgroup-144"
  },
  "dvs": {
    "name": "vDSwitch-NSX",
    "dvs": "dvs-41"
  },
  "fullFormattedMessage": "dvPort group vxw-dvs-41-virtualwire-17-sid-5008-LS-test-fdupont9 in Nested-DC was added to switch vDSwitch-NSX.",
  "changeTag": "",
  "eventType": "DVPortgroupCreatedEvent"
}
=> nil
irb(main):003:0>

I have then tried to get the information with $evm.vmdb(:event_stream).find_by_id($evm.root['event_id']), but I still have a DRb:DRBUnknown object when trying to access the full_data attribute.

Any hint why I don’t have the same behavior and why I get a DRb::DRbUnknown object ?


#2

To be more precise, here is the inspect of the DRb:DRnbUnknown object:

#<DRb::DRbUnknown:0x00000001a603a0 @name="VimHash", @buf="\x04\bIC:\fVimHash{\x0FI\"\bkey\x06:\x06ETIC:\x0EVimString\"\v209760\b;\x06T:\r@xsiType:\x12SOAP::SOAPInt:\r@vimType0I\"\fchainId\x06;\x06TIC;\a\"\v209759\b;\x06T;\b;\t;\n0I\"\x10createdTime\x06;\x06TIC;\a\" 2016-11-20T21:42:18.003063Z\b;\x06T;\b:\x17SOAP::SOAPDateTime;\n0I\"\ruserName\x06;\x06TIC;\a\" VSPHERE.LOCAL\\Administrator\b;\x06T;\b:\x15SOAP::SOAPString;\n0I\"\x0Fdatacenter\x06;\x06TIC;\x00{\aI\"\tname\x06;\x06TIC;\a\"\x0ENested-DC\b;\x06T;\b;\f;\n0I\"\x0Fdatacenter\x06;\x06TIC;\a\"\x11datacenter-2\b;\x06T;\b:\eManagedObjectReference;\n:\x0FDatacenter\a;\b:\x1CDatacenterEventArgument;\n0I\"\bnet\x06;\x06TIC;\x00{\aI\"\tname\x06;\x06TIC;\a\"8vxw-dvs-41-virtualwire-20-sid-5003-LS-test-fdupont4\b;\x06T;\b;\f;\n0I\"\fnetwork\x06;\x06TIC;\a\"\x14dvportgroup-147\b;\x06T;\b;\r;\n: DistributedVirtualPortgroup\a;\b:\x19NetworkEventArgument;\n0I\"\bdvs\x06;\x06TIC;\x00{\aI\"\tname\x06;\x06TIC;\a\"\x11vDSwitch-NSX\b;\x06T;\b;\f;\n0I\"\bdvs\x06;\x06TIC;\a\"\vdvs-41\b;\x06T;\b;\r;\n:#VmwareDistributedVirtualSwitch\a;\b:\x15DvsEventArgument;\n0I\"\x19fullFormattedMessage\x06;\x06TIC;\a\"tdvPort group vxw-dvs-41-virtualwire-20-sid-5003-LS-test-fdupont4 in Nested-DC was added to switch vDSwitch-NSX.\b;\x06T;\b;\f;\n0I\"\x0EchangeTag\x06;\x06TIC;\a\"\x00\b;\x06T;\b;\f;\n0I\"\x0EeventType\x06;\x06TI\"\x1CDVPortgroupCreatedEvent\x06;\x06T\a;\b:\x1CDVPortgroupCreatedEvent;\n0">

#3

Hi Fabien

Which version of CF/MIQ is this?

on 4.1/Darga using the script:

require 'json'
es = $evm.vmdb(:event_stream).find_by_id('23657')
$evm.log(:info, "Event stream full data = #{JSON.pretty_generate(es.full_data)}")

prints:

Event stream full data = {
  "id": "44440",
  "href": "/api/events/44440",
  "cluster": {
    "id": "00000001-0001-0001-0001-000000000249",
    "href": "/api/clusters/00000001-0001-0001-0001-000000000249"
  },
  "host": {
    "id": "88604de8-8966-43e0-badf-05fecf1d7bc3",
    "href": "/api/hosts/88604de8-8966-43e0-badf-05fecf1d7bc3"
  },
  "description": "Available memory of host rhevh01.bit63.net [1018 MB] is under defined threshold [1024 MB].",
  "severity": "warning",
  "code": 531,
  "time": "2016-11-21 07:44:04 UTC",
  "name": "HOST_LOW_MEM"
}

In general you’ll get DRb::DRbUnknown errors when running from automate if the client side of the dRuby connection can’t resolve the object type (this is why you’ll never see DRb::DRbUnknown errors when running from the Rails console - there’s no dRuby involved).

In your example it looks like it can’t resolve VimHash and VimString, so you can always try to define them yourself in your automate method as simple extensions of the ‘regular’ class, i.e.

class VimString < String
end

Cheers
pemcg


#4

Thanks Peter. You showed me the way. Indeed, the problem is that my code cannot resolve object type VimHash. And this class exists in ManageIQ world: /var/www/miq/vmdb/gems/pending/VMwareWebService/VimTypes.rb. So, the problem comes from the fact that it is not part of the default $LOAD_PATH.

And I found the solution in your book: https://github.com/pemcg/manageiq-automation-howto-guide/blob/master/chapter15/scripts/add_disk_cfme_54.rb. I have to extend the $LOAD_PATH so that I can import VimTypes:

$LOAD_PATH.unshift('/var/www/miq/vmdb/gems/pending')
require 'VMwareWebService/VimTypes'