mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[vsphere] support for listing processes in guest OS
This commit is contained in:
parent
67fff27936
commit
14a4e94bbc
5 changed files with 67 additions and 0 deletions
|
@ -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
|
||||
|
|
18
lib/fog/vsphere/models/compute/process.rb
Normal file
18
lib/fog/vsphere/models/compute/process.rb
Normal 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
|
||||
|
|
@ -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
|
||||
|
|
41
lib/fog/vsphere/requests/compute/list_processes.rb
Normal file
41
lib/fog/vsphere/requests/compute/list_processes.rb
Normal 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
|
||||
|
|
@ -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 }
|
||||
|
|
Loading…
Add table
Reference in a new issue