Class: Machinery::DeployTask

Inherits:
Object
  • Object
show all
Defined in:
lib/deploy_task.rb

Overview

Copyright © 2013-2016 SUSE LLC

This program is free software; you can redistribute it and/or modify it under the terms of version 3 of the GNU General Public License as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, contact SUSE LLC.

To contact SUSE about this file by physical or electronic mail, you may find current contact information at www.suse.com

Instance Method Summary collapse

Instance Method Details

#deploy(description, cloud_config, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/deploy_task.rb', line 19

def deploy(description, cloud_config, options = {})
  Machinery::LocalSystem.validate_architecture("x86_64")
  Machinery::LocalSystem.validate_existence_of_packages(
    ["python-glanceclient", "kiwi", "kiwi-desc-vmxboot"]
  )
  description.validate_build_compatibility

  unless File.exist?(cloud_config)
    raise(Machinery::Errors::DeployFailed,
      "The cloud config file '#{cloud_config}' could not be found."
    )
  end

  if options[:image_dir]
    unless Dir.exist?(options[:image_dir])
      raise(Machinery::Errors::DeployFailed,
        "The image directory does not exist."
      )
    end
    image_dir = options[:image_dir]
  else
    image_dir = Dir.mktmpdir("#{description.name}-image", "/tmp")
    is_temporary = true
    task = Machinery::BuildTask.new
    task.build(description, image_dir)
  end

   = (image_dir)
  image_file = File.join(image_dir, [:image_file])

  if [:description] != description.name
    raise(Machinery::Errors::MissingRequirement,
      "The image file '#{image_file}' was not build from the provided system description."
    )
  end

  unless File.exist?(image_file)
    raise(Machinery::Errors::DeployFailed,
      "The image file '#{image_file}' does not exist."
    )
  end

  command = "/usr/bin/glance"
  command << " --insecure" if options[:insecure]
  command << " image-create"
  command << " --name=#{options[:image_name] || description.name}"
  command << " --disk-format=qcow2 --container-format=bare"
  command << " --file=#{Shellwords.escape(image_file)}"

  system "sh -c '. #{Shellwords.escape(cloud_config)} && #{command}'"

  if is_temporary && image_dir.start_with?("/tmp/")
    FileUtils.rm_rf(image_dir)
  end
end