Class: Kitchen::Driver::Vcenter
- Inherits:
-
Base
- Object
- Base
- Kitchen::Driver::Vcenter
- Defined in:
- lib/kitchen/driver/vcenter.rb
Overview
Extends the Base class for vCenter
Instance Attribute Summary collapse
-
#connection_options ⇒ Object
Returns the value of attribute connection_options.
-
#ipaddress ⇒ Object
Returns the value of attribute ipaddress.
-
#session_id ⇒ Object
Returns the value of attribute session_id.
-
#session_svc ⇒ Object
Returns the value of attribute session_svc.
-
#vapi_config ⇒ Object
Returns the value of attribute vapi_config.
Instance Method Summary collapse
-
#create(state) ⇒ Object
The main create method.
-
#destroy(state) ⇒ Object
The main destroy method.
Instance Attribute Details
#connection_options ⇒ Object
Returns the value of attribute connection_options.
39 40 41 |
# File 'lib/kitchen/driver/vcenter.rb', line 39 def @connection_options end |
#ipaddress ⇒ Object
Returns the value of attribute ipaddress.
39 40 41 |
# File 'lib/kitchen/driver/vcenter.rb', line 39 def ipaddress @ipaddress end |
#session_id ⇒ Object
Returns the value of attribute session_id.
39 40 41 |
# File 'lib/kitchen/driver/vcenter.rb', line 39 def session_id @session_id end |
#session_svc ⇒ Object
Returns the value of attribute session_svc.
39 40 41 |
# File 'lib/kitchen/driver/vcenter.rb', line 39 def session_svc @session_svc end |
#vapi_config ⇒ Object
Returns the value of attribute vapi_config.
39 40 41 |
# File 'lib/kitchen/driver/vcenter.rb', line 39 def vapi_config @vapi_config end |
Instance Method Details
#create(state) ⇒ Object
The main create method
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/kitchen/driver/vcenter.rb', line 59 def create(state) # Configure the hash for use when connecting for cloning a machine @connection_options = { user: config[:vcenter_username], password: config[:vcenter_password], insecure: config[:vcenter_disable_ssl_verify] ? true : false, host: config[:vcenter_host], } # If the vm_name has not been set then set it now based on the suite, platform and a random number if config[:vm_name].nil? config[:vm_name] = format("%s-%s-%s", instance.suite.name, instance.platform.name, SecureRandom.hex(4)) end connect # Using the clone class, create a machine for TK # Find the identifier for the targethost to pass to rbvmomi config[:targethost] = get_host(config[:targethost]) # Find the resource pool config[:resource_pool] = get_resource_pool(config[:resource_pool]) # Check that the datacenter exists datacenter_exists?(config[:datacenter]) # Same thing needs to happen with the folder name if it has been set unless config[:folder].nil? config[:folder] = { name: config[:folder], id: get_folder(config[:folder]), } end # Allow different clone types config[:clone_type] = :linked if config[:clone_type] == "linked" # Create a hash of options that the clone requires = { name: config[:vm_name], targethost: config[:targethost], poweron: config[:poweron], template: config[:template], datacenter: config[:datacenter], folder: config[:folder], resource_pool: config[:resource_pool], clone_type: config[:clone_type], } # Create an object from which the clone operation can be called clone_obj = Support::CloneVm.new(, ) state[:hostname] = clone_obj.clone state[:vm_name] = config[:vm_name] end |
#destroy(state) ⇒ Object
The main destroy method
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/kitchen/driver/vcenter.rb', line 117 def destroy(state) return if state[:vm_name].nil? connect vm = get_vm(state[:vm_name]) vm_obj = Com::Vmware::Vcenter::VM.new(vapi_config) # shut the machine down if it is running if vm.power_state.value == "POWERED_ON" power = Com::Vmware::Vcenter::Vm::Power.new(vapi_config) power.stop(vm.vm) end # delete the vm vm_obj.delete(vm.vm) end |