Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sane defaults for VMWare Fusion driver #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions lib/nalloc/driver/fusion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ class Nalloc::Driver::Fusion < Nalloc::Driver
VM_STORE_PATH = File.join(CONFIG_DIR, "vms")

TEMPLATE_DIR = Nalloc.path("templates/fusion")
DEFAULT_VMX_TEMPLATE_PATH = File.join(TEMPLATE_DIR, "zygote.vmx.erb")
IFACES_TEMPLATE_PATH = File.join(TEMPLATE_DIR, "interfaces.erb")
RESOLV_CONF_TEMPLATE_PATH = File.join(TEMPLATE_DIR, "resolv.conf.erb")

DEFAULT_VMX_TEMPLATE_PATH = File.join(TEMPLATE_DIR, "zygote.vmx.erb")
DEFAULT_VMDK_TEMPLATE_PATH =
"~/Documents/Virtual Machines.localized/nalloc.vmwarevm/nalloc.vmdk"
DEFAULT_SSH_KEY = "id_rsa"
DEFAULT_ROOT_PASS = 'nalloc'
DEFAULT_USERNAME = 'nalloc'

class << self
def save_adapters(adapters)
Expand Down Expand Up @@ -121,10 +124,10 @@ def start_allocating_nodes(cluster_id, specs)
#
# @return block Finishes allocating node, blocks until completion.
def start_allocating_node(cluster_id, name, specs, cluster_dir, props)
vmdk_path =
File.expand_path(get_required_spec_option(name, specs, :vmdk_path))
root_pass = get_required_spec_option(name, specs, :root_pass)
user = get_required_spec_option(name, specs, :username)
vmdk_path = specs[:vmdk_path] || DEFAULT_VMDK_TEMPLATE_PATH
vmdk_path = File.expand_path(vmdk_path)
root_pass = specs[:root_pass] || DEFAULT_ROOT_PASS
user = specs[:username] || DEFAULT_USERNAME

ssh_key_name = ENV['NALLOC_SSH_KEY'] || DEFAULT_SSH_KEY
private_key_path = Nalloc::Node.find_ssh_key(ssh_key_name)
Expand All @@ -134,8 +137,10 @@ def start_allocating_node(cluster_id, name, specs, cluster_dir, props)

vmx_path = create_vm(vmx_template_path, cluster_dir, name, vmdk_path,
"vmnet#{props[:adapter]}",
:memsize_MB => specs[:memsize_MB],
:guest_os => specs[:guest_os])
:memsize_MB => specs[:memsize_MB] || '512',
:guest_os => specs[:guest_os] || 'ubuntu')

system_identity = compute_system_identity(vmdk_path)

vmrun("start", vmx_path, "nogui")

Expand Down Expand Up @@ -165,8 +170,10 @@ def start_allocating_node(cluster_id, name, specs, cluster_dir, props)
# Bring up networking
gr.call("/etc/init.d/networking", "restart")

{ "identity" => vmx_path,
{
"identity" => vmx_path,
"public_ip_address" => props[:ipaddr],
"system_identity" => system_identity,
"ssh" => {
"user" => user,
"private_key_name" => ssh_key_name,
Expand Down Expand Up @@ -394,4 +401,11 @@ def cluster_id_from_vmx_path(vmx_path)
parts = vmx_path.split(File::SEPARATOR)
parts[-3]
end

def compute_system_identity(vmdk_path)
digest = `openssl dgst -sha256 < #{vmdk_path.inspect}`.chomp
raise "Couldn't compute system_identity for #{vmdk_path}" unless $?.success?

digest
end
end
4 changes: 2 additions & 2 deletions templates/fusion/zygote.vmx.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ virtualHW.version = "8"
vcpu.hotadd = "TRUE"
scsi0.present = "TRUE"
scsi0.virtualDev = "lsilogic"
memsize = "<%= props[:memsize_MB] || 512 %>"
memsize = "<%= props[:memsize_MB] %>"
mem.hotadd = "TRUE"
scsi0:0.present = "TRUE"
scsi0:0.fileName = "<%= props[:vmdk_path] %>"
Expand Down Expand Up @@ -36,7 +36,7 @@ vmci0.present = "TRUE"
hpet0.present = "TRUE"
tools.syncTime = "TRUE"
displayName = "<%= props[:name] %>"
guestOS = "<%= props[:guest_os] || 'ubuntu-64' %>"
guestOS = "<%= props[:guest_os] %>"
nvram = "<%= props[:name] %>.nvram"
virtualHW.productCompatibility = "hosted"
proxyApps.publishToHost = "FALSE"
Expand Down