Class: VcenterLib::Vcenter
- Inherits:
-
Object
- Object
- VcenterLib::Vcenter
- Includes:
- Logging
- Defined in:
- lib/vcenter_lib/vcenter.rb
Overview
central access point
Instance Method Summary collapse
-
#dcs ⇒ Object
get array of all datacenters.
-
#find_vm_by_name(vm_name) ⇒ Object
find vm.
-
#initialize(options = {}) ⇒ Vcenter
constructor
A new instance of Vcenter.
-
#serviceContent ⇒ Object
rubocop:disable Style/MethodName.
-
#vim ⇒ Object
rubocop:enable Style/MethodName.
-
#vms ⇒ Object
get all vms in all datacenters.
Methods included from Logging
Constructor Details
#initialize(options = {}) ⇒ Vcenter
Returns a new instance of Vcenter.
8 9 10 11 12 13 |
# File 'lib/vcenter_lib/vcenter.rb', line 8 def initialize( = {}) @username = [:username] @password = [:password] @vcenter = [:vcenter] @insecure = [:insecure] end |
Instance Method Details
#dcs ⇒ Object
get array of all datacenters
16 17 18 |
# File 'lib/vcenter_lib/vcenter.rb', line 16 def dcs vim.rootFolder.childEntity.grep(RbVmomi::VIM::Datacenter) end |
#find_vm_by_name(vm_name) ⇒ Object
find vm
35 36 37 38 39 40 |
# 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 ⇒ Object
rubocop:disable Style/MethodName
43 44 45 |
# File 'lib/vcenter_lib/vcenter.rb', line 43 def serviceContent vim.serviceContent end |
#vim ⇒ Object
rubocop:enable Style/MethodName
48 49 50 51 52 53 54 55 |
# 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 ⇒ Object
get all vms in all datacenters
21 22 23 24 25 26 27 28 29 30 31 32 |
# 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 |