class VcenterLib::Vcenter
central access point
Public Class Methods
new(options = {})
click to toggle source
# File lib/vcenter_lib/vcenter.rb, line 8 def initialize(options = {}) @username = options[:username] @password = options[:password] @vcenter = options[:vcenter] @insecure = options[:insecure] end
Public Instance Methods
dcs()
click to toggle source
get array of all datacenters
# File lib/vcenter_lib/vcenter.rb, line 16 def dcs vim.rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter) end
find_vm_by_name(vm_name)
click to toggle source
find vm
# File lib/vcenter_lib/vcenter.rb, line 35 def find_vm_by_name(vm_name) logger.debug("search for #{vm_name}") serviceContent.propertyCollector.collectMultiple(vms, 'name').find do |_k, v| v['name'] == vm_name end[0] end
serviceContent()
click to toggle source
rubocop:disable Style/MethodName
# File lib/vcenter_lib/vcenter.rb, line 43 def serviceContent vim.serviceContent end
vim()
click to toggle source
rubocop:enable Style/MethodName
# File lib/vcenter_lib/vcenter.rb, line 48 def vim @vim || @vim = RbVmomi::VIM.connect( host: @vcenter, user: @username, password: @password, insecure: @insecure ) end
vms()
click to toggle source
get all vms in all datacenters
# File lib/vcenter_lib/vcenter.rb, line 21 def vms logger.debug "get all VMs in all datacenters: begin" result = dcs.inject([]) do |r, dc| r + serviceContent.viewManager.CreateContainerView( container: dc.vmFolder, type: ['VirtualMachine'], recursive: true ).view end logger.debug "get all VMs in all datacenters: end" result end