Class: Kitchen::Driver::Vcenter

Inherits:
Base
  • Object
show all
Defined in:
lib/kitchen/driver/vcenter.rb

Overview

Vcenter

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connection_optionsObject

Returns the value of attribute connection_options.



38
39
40
# File 'lib/kitchen/driver/vcenter.rb', line 38

def connection_options
  @connection_options
end

#ipaddressObject

Returns the value of attribute ipaddress.



38
39
40
# File 'lib/kitchen/driver/vcenter.rb', line 38

def ipaddress
  @ipaddress
end

#session_idObject

Returns the value of attribute session_id.



38
39
40
# File 'lib/kitchen/driver/vcenter.rb', line 38

def session_id
  @session_id
end

#session_svcObject

Returns the value of attribute session_svc.



38
39
40
# File 'lib/kitchen/driver/vcenter.rb', line 38

def session_svc
  @session_svc
end

#vapi_configObject

Returns the value of attribute vapi_config.



38
39
40
# File 'lib/kitchen/driver/vcenter.rb', line 38

def vapi_config
  @vapi_config
end

Instance Method Details

#create(state) ⇒ Object



52
53
54
55
56
57
58
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
# File 'lib/kitchen/driver/vcenter.rb', line 52

def create(state)
  # 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

  # raise "Please set the resource pool name using `resource_pool` parameter in the 'drive_config' section of your .kitchen.yml file" if config[:resource_pool].nil?

  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
  config[:folder] = {
    name: config[:folder],
    id: get_folder(config[:folder]),
  } unless config[:folder].nil?

  # Create a hash of options that the clone requires
  options = {
    name: config[:vm_name],
    targethost: config[:targethost],
    poweron: config[:poweron],
    template: config[:template],
    datacenter: config[:datacenter],
    folder: config[:folder],
    resource_pool: config[:resource_pool],
  }

  # Create an object from which the clone operation can be called
  clone_obj = Support::CloneVm.new(connection_options, options)
  state[:hostname] = clone_obj.clone()
  state[:vm_name] = config[:vm_name]
end

#destroy(state) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/kitchen/driver/vcenter.rb', line 95

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