Module: ForemanBootdisk::Orchestration::Compute

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/foreman_bootdisk/orchestration/compute.rb

Instance Method Summary collapse

Instance Method Details

#bootdisk_attach_isoObject



62
63
64
# File 'app/models/concerns/foreman_bootdisk/orchestration/compute.rb', line 62

def bootdisk_attach_iso
  compute_resource.iso_attach(File.basename(bootdisk_isofile), uuid)
end

#bootdisk_detach_isoObject



66
67
68
# File 'app/models/concerns/foreman_bootdisk/orchestration/compute.rb', line 66

def bootdisk_detach_iso
  compute_resource.iso_detach(uuid)
end

#bootdisk_generate_iso_imageObject



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

def bootdisk_generate_iso_image
  if self.build? && self.provisioning_template(kind: :PXELinux) && self.provisioning_template(kind: :PXEGrub2)
    logger.info format('Generating FULL HOST ISO image for %s', name)
    ForemanBootdisk::ISOGenerator.generate_full_host(self, dir: Dir.tmpdir) do |image|
      FileUtils.mv image, bootdisk_isofile
    end
  else
    logger.info format('Generating HOST ISO image for %s', name)
    ForemanBootdisk::ISOGenerator.generate(ipxe: bootdisk_template_render, dir: Dir.tmpdir) do |image|
      FileUtils.mv image, bootdisk_isofile
    end
  end
end

#bootdisk_isodirObject



14
15
16
# File 'app/models/concerns/foreman_bootdisk/orchestration/compute.rb', line 14

def bootdisk_isodir
  @bootdisk_isodir ||= Dir.mktmpdir
end

#bootdisk_isofileObject



18
19
20
# File 'app/models/concerns/foreman_bootdisk/orchestration/compute.rb', line 18

def bootdisk_isofile
  File.join(bootdisk_isodir, "#{name}.iso")
end

#bootdisk_upload_isoObject



58
59
60
# File 'app/models/concerns/foreman_bootdisk/orchestration/compute.rb', line 58

def bootdisk_upload_iso
  compute_resource.iso_upload(bootdisk_isofile, uuid)
end

#delAttachIsoImageObject



94
# File 'app/models/concerns/foreman_bootdisk/orchestration/compute.rb', line 94

def delAttachIsoImage; end

#delDetachIsoImageObject



103
# File 'app/models/concerns/foreman_bootdisk/orchestration/compute.rb', line 103

def delDetachIsoImage; end

#delGenerateIsoImageObject



76
# File 'app/models/concerns/foreman_bootdisk/orchestration/compute.rb', line 76

def delGenerateIsoImage; end

#delIsoImageObject



85
# File 'app/models/concerns/foreman_bootdisk/orchestration/compute.rb', line 85

def delIsoImage; end

#queue_bootdisk_computeObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/concerns/foreman_bootdisk/orchestration/compute.rb', line 22

def queue_bootdisk_compute
  return unless compute? && errors.empty?
  return unless provision_method == 'bootdisk'

  # We want to add our queue jobs only if really necessary:
  #   - in case of starting to create a new host
  #   - in case of a rebuild
  if (old.nil? || !old.build?) && build?
    queue.create(name: _('Generating ISO image for %s') % self, priority: 5,
                 action: [self, :setGenerateIsoImage])
    queue.create(name: _('Upload ISO image to datastore for %s') % self, priority: 6,
                 action: [self, :setIsoImage])
    queue.create(name: _('Attach ISO image to CDROM drive for %s') % self, priority: 1001,
                 action: [self, :setAttachIsoImage])
  # Detach ISO image when host sends 'built' HTTP POST request
  elsif old&.build? && !build?
    queue.create(name: _('Detach ISO image from CDROM drive for %s') % self, priority: 52,
                 action: [self, :setDetachIsoImage])
  end
  true
end

#setAttachIsoImageObject



87
88
89
90
91
92
# File 'app/models/concerns/foreman_bootdisk/orchestration/compute.rb', line 87

def setAttachIsoImage
  logger.info format('Attaching ISO image to CDROM drive for %s', name)
  bootdisk_attach_iso
rescue StandardError => e
  failure format(_('Failed to attach ISO image to CDROM drive of instance %{name}: %{message}'), name: name, message: e.message), e
end

#setDetachIsoImageObject



96
97
98
99
100
101
# File 'app/models/concerns/foreman_bootdisk/orchestration/compute.rb', line 96

def setDetachIsoImage
  logger.info format('Detaching ISO image from CDROM drive for %s', name)
  bootdisk_detach_iso
rescue StandardError => e
  failure format(_('Failed to detach ISO image from CDROM drive of instance %{name}: %{message}'), name: name, message: e.message), e
end

#setGenerateIsoImageObject



70
71
72
73
74
# File 'app/models/concerns/foreman_bootdisk/orchestration/compute.rb', line 70

def setGenerateIsoImage
  bootdisk_generate_iso_image
rescue StandardError => e
  failure format(_('Failed to generate ISO image for instance %{name}: %{message}'), name: name, message: e.message), e
end

#setIsoImageObject



78
79
80
81
82
83
# File 'app/models/concerns/foreman_bootdisk/orchestration/compute.rb', line 78

def setIsoImage
  logger.info "Uploading ISO image #{bootdisk_isofile} for #{name}"
  bootdisk_upload_iso
rescue StandardError => e
  failure format(_('Failed to upload ISO image for instance %{name}: %{message}'), name: name, message: e.message), e
end