2010-01-30 06:21:35 +00:00
|
|
|
module Hobo
|
|
|
|
class VM
|
|
|
|
class <<self
|
|
|
|
# Bring up the virtual machine. Imports the base image and
|
|
|
|
# provisions it.
|
|
|
|
def up
|
2010-01-30 08:06:56 +00:00
|
|
|
vm = import
|
|
|
|
persist_uuid(vm)
|
|
|
|
setup_mac_address(vm)
|
|
|
|
forward_ssh(vm)
|
|
|
|
setup_shared_folder(vm)
|
|
|
|
end
|
2010-01-31 07:00:56 +00:00
|
|
|
|
2010-01-30 08:06:56 +00:00
|
|
|
def import
|
2010-01-30 06:21:35 +00:00
|
|
|
HOBO_LOGGER.info "Importing base VM (#{Hobo.config[:vm][:base]})..."
|
2010-01-30 08:06:56 +00:00
|
|
|
VirtualBox::VM.import(File.expand_path(Hobo.config[:vm][:base]))
|
|
|
|
end
|
2010-01-31 07:00:56 +00:00
|
|
|
|
2010-01-30 08:06:56 +00:00
|
|
|
def persist_uuid(vm)
|
2010-01-30 06:21:35 +00:00
|
|
|
HOBO_LOGGER.info "Persisting the VM UUID (#{vm.uuid})..."
|
2010-01-31 07:00:56 +00:00
|
|
|
Env.persist_uuid(vm.uuid)
|
2010-01-30 06:21:35 +00:00
|
|
|
end
|
2010-01-31 07:00:56 +00:00
|
|
|
|
2010-01-30 08:06:56 +00:00
|
|
|
def setup_mac_address(vm)
|
|
|
|
HOBO_LOGGER.info "Matching MAC addresses..."
|
|
|
|
vm.nics.first.macaddress = Hobo.config[:vm][:base_mac]
|
|
|
|
vm.save(true)
|
|
|
|
end
|
2010-01-31 07:00:56 +00:00
|
|
|
|
2010-01-30 08:06:56 +00:00
|
|
|
def forward_ssh(vm)
|
|
|
|
HOBO_LOGGER.info "Forwarding SSH ports..."
|
|
|
|
port = VirtualBox::ForwardedPort.new
|
|
|
|
port.name = "ssh"
|
|
|
|
port.hostport = Hobo.config[:ssh][:port]
|
|
|
|
port.guestport = 22
|
|
|
|
vm.forwarded_ports << port
|
|
|
|
vm.save(true)
|
|
|
|
end
|
2010-01-31 07:00:56 +00:00
|
|
|
|
2010-01-30 08:06:56 +00:00
|
|
|
# TODO: We need to get the host path.
|
|
|
|
def setup_shared_folder(vm)
|
|
|
|
HOBO_LOGGER.info "Creating shared folders..."
|
|
|
|
folder = VirtualBox::SharedFolder.new
|
|
|
|
folder.name = "project-path"
|
|
|
|
folder.hostpath = ""
|
|
|
|
vm.shared_folders << folder
|
|
|
|
#vm.save(true)
|
|
|
|
end
|
2010-01-30 06:21:35 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|