Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.74 KB | None | 0 0
  1. require 'xmlrpc/client'
  2. Facter.add(:odoo_ref) do
  3.   confine :virtual => 'physical'
  4.   setcode do
  5.     mac = Facter.value(:discovery_bootif)
  6.     sn = Facter.value(:serialnumber)
  7.     url = 'http://odoo-server:8069'
  8.     db = 'production'
  9.     username = 'username'
  10.     password = 'password'
  11.     common = XMLRPC::Client.new2("#{url}/xmlrpc/2/common")
  12.     uid = common.call('authenticate', db, username, password, {})
  13.     models = XMLRPC::Client.new2("#{url}/xmlrpc/2/object").proxy
  14.     records = models.execute_kw(db, uid, password,
  15.       'stock.production.lot', 'search_read',
  16.       [['|', ['serialnumber', '=', mac], ['serialnumber', '=', sn]]],
  17.       {:fields => ['ref']})
  18.     if records.length == 1
  19.       records.first['ref']
  20.     end
  21.   end
  22. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement