Class: Vmit::Plugins::Bootstrap

Inherits:
Clamp::Command
  • Object
show all
Defined in:
lib/vmit/plugins/bootstrap.rb

Overview

Bootstrap allows to initialize a virtual machine from (currently) a (SUSE) repository.

It will perform an autoinstallation based on the repository.

Instance Method Summary collapse

Instance Method Details

#executeObject



51
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
# File 'lib/vmit/plugins/bootstrap.rb', line 51

def execute
  Vmit.logger.info 'Starting bootstrap'
  curr_dir = File.expand_path(Dir.pwd)
  vm = Vmit::VirtualMachine.new(curr_dir)

  Vmit.logger.info '  Deleting old images'
  FileUtils.rm_f(Dir.glob('*.qcow2'))
  opts = {}
  opts[:disk_size] = disk_size if disk_size
  vm.disk_image_init!(opts)
  vm.save_config!

  uri = URI.parse(location)
  bootstrap = [Vmit::Bootstrap::FromImage,
            Vmit::Bootstrap::FromMedia].find do |method|
    method.accept?(uri)
  end

  if bootstrap
    bootstrap.new(vm, uri).execute
  else
    raise "Can't bootstrap from #{location}"
  end

  Vmit.logger.info 'Creating snapshot of fresh system.'
  vm.disk_snapshot!
  Vmit.logger.info 'Bootstraping done. Call vmit run to start your system.'
end