Module: ForemanBootdisk::ComputeResources::Vmware

Defined in:
app/models/concerns/foreman_bootdisk/compute_resources/vmware.rb

Instance Method Summary collapse

Instance Method Details

#bootdisk_datastore(vm_uuid) ⇒ Object



20
21
22
# File 'app/models/concerns/foreman_bootdisk/compute_resources/vmware.rb', line 20

def bootdisk_datastore(vm_uuid)
  find_vm_by_uuid(vm_uuid).volumes.first.datastore
end

#capabilitiesObject



6
7
8
# File 'app/models/concerns/foreman_bootdisk/compute_resources/vmware.rb', line 6

def capabilities
  super + [:bootdisk]
end

#controller_config(vm_uuid) ⇒ Object



67
68
69
70
71
# File 'app/models/concerns/foreman_bootdisk/compute_resources/vmware.rb', line 67

def controller_config(vm_uuid)
  options = OpenStruct.new(server_id: vm_uuid, attributes: {type: RbVmomi::VIM.VirtualAHCIController.class})
  client.add_vm_controller(options)
  client.get_vm_first_sata_controller(vm_uuid)
end

#iso_attach(iso, vm_uuid) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/concerns/foreman_bootdisk/compute_resources/vmware.rb', line 44

def iso_attach(iso, vm_uuid)
  controller = controller_config(vm_uuid)
  options = {
    'instance_uuid' => vm_uuid,
    'iso' => "foreman_isos/#{iso}",
    'datastore' => bootdisk_datastore(vm_uuid),
    'start_connected' => true,
    'connected' => true,
    'allow_guest_control' => true,
    'controller_key' => controller[:key]
  }
  client.vm_reconfig_cdrom options
end

#iso_delete(iso, vm_uuid) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'app/models/concerns/foreman_bootdisk/compute_resources/vmware.rb', line 34

def iso_delete(iso, vm_uuid)
  options = {
    'local_path' => iso,
    'datacenter' => dc.name,
    'datastore' => bootdisk_datastore(vm_uuid),
    'upload_directory' => 'foreman_isos'
  }
  client.destroy_iso options
end

#iso_detach(vm_uuid) ⇒ Object



58
59
60
61
62
63
64
65
# File 'app/models/concerns/foreman_bootdisk/compute_resources/vmware.rb', line 58

def iso_detach(vm_uuid)
  options = {
    'instance_uuid' => vm_uuid,
    'start_connected' => false,
    'connected' => false,
  }
  client.vm_reconfig_cdrom options
end

#iso_upload(iso, vm_uuid) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'app/models/concerns/foreman_bootdisk/compute_resources/vmware.rb', line 24

def iso_upload(iso, vm_uuid)
  options = {
    'local_path' => iso,
    'datacenter' => dc.name,
    'datastore' => bootdisk_datastore(vm_uuid),
    'upload_directory' => 'foreman_isos' # fog creates the directory if it does not exist
  }
  client.upload_iso options
end

#parse_args(args = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'app/models/concerns/foreman_bootdisk/compute_resources/vmware.rb', line 10

def parse_args(args = {})
  args = super(args)
  if args[:provision_method] == 'bootdisk'
    args[:cdroms] = [new_cdrom]
    args[:boot_order] = %w[cdrom disk]
    args[:boot_retry] = 10 * 1000 # boot_retry is in ms. Shortest is 10s
  end
  args
end