Merge pull request #3757 from ireznice/ir_processes

[vsphere] support for listing processes in guest OS
This commit is contained in:
Paulo Henrique Lopes Ribeiro 2015-11-13 11:31:44 -02:00
commit 308e7100b1
5 changed files with 67 additions and 0 deletions

View File

@ -41,6 +41,7 @@ module Fog
model :customfield
collection :customfields
model :scsicontroller
model :process
request_path 'fog/vsphere/requests/compute'
request :current_time
@ -92,6 +93,7 @@ module Fog
request :list_vm_snapshots
request :list_child_snapshots
request :revert_to_snapshot
request :list_processes
module Shared
attr_reader :vsphere_is_vcenter

View File

@ -0,0 +1,18 @@
require 'fog/compute/models/server'
module Fog
module Compute
class Vsphere
class Process < Fog::Model
attribute :cmd_line
attribute :end_time
attribute :exit_code
attribute :name
attribute :owner
attribute :pid
attribute :start_time
end
end
end
end

View File

@ -237,6 +237,11 @@ module Fog
end
end
def guest_processes(opts = {})
fail 'VM tools must be running' unless tools_running?
service.list_processes(self.id, opts)
end
def customvalues
attributes[:customvalues] ||= id.nil? ? [] : service.customvalues( :vm => self )
end

View File

@ -0,0 +1,41 @@
module Fog
module Compute
class Vsphere
class Real
def list_processes(vm_id, opts)
vm = get_vm_ref(vm_id)
auth = RbVmomi::VIM::NamePasswordAuthentication(
username: opts[:user],
password: opts[:password],
interactiveSession: false
)
p_manager = @connection.serviceContent.guestOperationsManager.processManager
processes = p_manager.ListProcessesInGuest(vm: vm, auth: auth)
processes.map do |pi|
Process.new(
cmd_line: pi.cmdLine,
end_time: pi.endTime,
exit_code: pi.exitCode,
name: pi.name,
owner: pi.owner,
pid: pi.pid,
start_time: pi.startTime
)
end
end
end
class Mock
def list_processes(vm_id, opts = {})
[
Process.new(name: 'winlogon'),
Process.new(name: 'init')
]
end
end
end
end
end

View File

@ -9,6 +9,7 @@ Shindo.tests('Fog::Compute[:vsphere] | server model', ['vsphere']) do
test(action) { server.respond_to? action }
test("#{action} returns successfully") { server.send(action.to_sym) ? true : false }
end
test('guest_processes') { server.respond_to? 'guest_processes' }
test('take_snapshot') do
test('responds') { server.respond_to? 'take_snapshot'}
test('returns successfully') { server.take_snapshot('name' => 'foobar').kind_of? Hash }