Class: VmwareClass
- Inherits:
-
Object
- Object
- VmwareClass
- Defined in:
- lib/miq_utilities/vmware.rb
Overview
Wrapper class to interact with vmware
Instance Method Summary collapse
- #find_vm(datacenter, vmname) ⇒ Object
- #get_vsphere_connection(user, password) ⇒ Object
-
#initialize(host_name) ⇒ VmwareClass
constructor
A new instance of VmwareClass.
- #retrieve_data_center ⇒ Object
- #upg_tools(vmobj) ⇒ Object
Constructor Details
#initialize(host_name) ⇒ VmwareClass
Returns a new instance of VmwareClass.
18 19 20 |
# File 'lib/miq_utilities/vmware.rb', line 18 def initialize(host_name) @host_name = host_name end |
Instance Method Details
#find_vm(datacenter, vmname) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/miq_utilities/vmware.rb', line 32 def find_vm(datacenter, vmname) vm = {} datacenter.datastoreFolder.childEntity.collect do |datastore| vm[:instance] = datastore.vm.find { |x| x.name == vmname } if vm[:instance] vm[:datastore] = datastore.name break end end vm end |
#get_vsphere_connection(user, password) ⇒ Object
22 23 24 25 |
# File 'lib/miq_utilities/vmware.rb', line 22 def get_vsphere_connection(user, password) @connection = RbVmomi::VIM.connect(host: @host_name, user: user, password: password, insecure: true) @connection end |
#retrieve_data_center ⇒ Object
27 28 29 30 |
# File 'lib/miq_utilities/vmware.rb', line 27 def retrieve_data_center @connection.serviceInstance.find_datacenter || raise('Datacenter not found!') unless @connection.nil? raise("No connection established!\nUse the \"get_vsphere_connection\" method to connect.") if @connection.nil? end |
#upg_tools(vmobj) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/miq_utilities/vmware.rb', line 44 def upg_tools(vmobj) instopts = if vmobj[:instance][:guest][:guestFamily] == 'windowsGuest' '/s /v "/qn REBOOT=ReallySuppress"' end vmobj[:instance].UpgradeTools_Task(installerOptions: instopts).wait_for_completion end |