Class: OpsManager::Appliance::Vsphere

Inherits:
Base
  • Object
show all
Includes:
Logging
Defined in:
lib/ops_manager/appliance/vsphere.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger, logger, logger=

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from OpsManager::Appliance::Base

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/ops_manager/appliance/vsphere.rb', line 11

def config
  @config
end

Instance Method Details

#cmdObject



25
26
27
28
# File 'lib/ops_manager/appliance/vsphere.rb', line 25

def cmd
  vcenter_target= "vi://#{vcenter_username}:#{vcenter_password}@#{config[:opts][:vcenter][:host]}/#{config[:opts][:vcenter][:datacenter]}/host/#{config[:opts][:vcenter][:cluster]}"
  "echo yes | ovftool --acceptAllEulas --noSSLVerify --powerOn --X:waitForIp --net:\"Network 1=#{config[:opts][:portgroup]}\" --name=#{vm_name} -ds=#{config[:opts][:datastore]} --prop:ip0=#{config[:ip]} --prop:netmask0=#{config[:opts][:netmask]}  --prop:gateway=#{config[:opts][:gateway]} --prop:DNS=#{config[:opts][:dns]} --prop:ntp_servers=#{config[:opts][:ntp_servers].join(',')} --prop:admin_password=#{config[:password]} #{config[:opts][:ova_path]} #{vcenter_target}"
end

#deploy_vmObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ops_manager/appliance/vsphere.rb', line 13

def deploy_vm
  print '====> Deploying ova ...'.green
  logger.info "Running: #{cmd}"
  logger.info `#{cmd}`
  if ! $?.success?
    puts 'FAILED. Your old ops manager is offline, and a new one was not provisioned.'.red
    puts 'You may want to re-run with DEBUG=true set to figure out what failed...'
    raise "Failure in ovftool"
  end
  puts 'done'.green
end

#stop_current_vm(name) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/ops_manager/appliance/vsphere.rb', line 30

def stop_current_vm(name)
  print "====> Stopping vm #{name} ...".green
  dc = vim.serviceInstance.find_datacenter(config[:opts][:vcenter][:datacenter])
  logger.info "finding vm: #{name}"
  vm = dc.find_vm(name) or fail "VM not found"
  vm.PowerOffVM_Task.wait_for_completion
  puts 'done'.green
end