Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: On Windows use powershell and WMI to get the machine id #132

Merged
merged 2 commits into from
Apr 15, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions lib/lua/machineidentity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ limitations under the License.

local Error = require('core').Error
local Object = require('core').Object
local async = require('async')
local childprocess = require('childprocess')
local os = require('os')
local fs = require('fs')
Expand All @@ -26,25 +25,30 @@ local fmt = require('string').format
local MachineIdentity = Object:extend()

local function xenAdapter(callback)
local exePath
local exeArgs
local exePath, exeArgs

if os.type() == 'win32' then
exePath = 'c:\\Program Files\\Citrix\\XenTools\\xenstore_client.exe'
exeArgs = { 'read', 'name' }
if fs.existsSync(exePath) then
exeArgs = { 'read', 'name' }
else
exePath = 'powershell'
exeArgs = { '-Command', '& {$sid = ((Get-WmiObject -Class CitrixXenStoreBase -Namespace root\\wmi).AddSession("Temp").SessionId) ; $s = (Get-WmiObject -Namespace root\\wmi -Query "select * from CitrixXenStoreSession where SessionId=$sid") ; $v = $s.GetValue("name").value ; $s.EndSession() ; $v}' }
end
else
exePath = 'xenstore-read'
exeArgs = { 'name' }
end

local buffer = ''
local buffer = {}
local child = childprocess.spawn(exePath, exeArgs)

child.stdout:on('data', function(chunk)
buffer = buffer .. chunk
table.insert(buffer, chunk)
end)

child:on('exit', function(code)
buffer = table.concat(buffer)
if code == 0 and buffer:len() > 10 then
callback(nil, utils.trim(buffer:sub(10)))
else
Expand Down