Permalink
Browse files

Node options should always be passed through the command line

- Remove defaults.json, and associated setup in rake task
- Add support for setting vmdk in tests via NALLOC_VMDK_PATH
- Remove :ssh_key option, use either 'id_rsa' or NALLOC_SSH_KEY
-
  • Loading branch information...
1 parent 8826347 commit 35f3c234ce9a59a6a2786392861273c81bfd5891 @mpage mpage committed Jan 25, 2012
Showing with 20 additions and 60 deletions.
  1. +0 −20 Rakefile
  2. +4 −0 features/step_definitions/allocate.rb
  3. +16 −40 lib/nalloc/driver/fusion.rb
View
20 Rakefile
@@ -71,26 +71,6 @@ namespace 'fusion' do
sh "sudo #{ADD_ADAPTERS_PATH} #{to_add.flatten.join(' ')}"
Nalloc::Driver::Fusion.save_adapters(adapters)
- puts "Setting defaults"
- defaults = {}
- ["vmdk_path", "vmx_template_path"].each do |path_opt|
- ans = ask("Would you like to set a default for #{path_opt} (yes/no)?")
- if ans == "yes"
- name = path_opt.gsub("_path", '')
- loop do
- path = ask("Please enter the path for the #{name}: ")
- real_path = File.expand_path(path)
- if File.exist?(real_path)
- defaults[path_opt] = real_path
- break
- else
- puts "Sorry, #{real_path} doesn't appear to exist..."
- end
- end
- end
- end
- Nalloc::Driver::Fusion.write_defaults(defaults)
-
puts "Setup complete. You'll need to restart fusion before the network"\
+ " adapter will be usable."
rescue => e
View
4 features/step_definitions/allocate.rb
@@ -13,6 +13,10 @@
if root_pass = ENV['NALLOC_ROOT_PASS']
@node_specs[name][:root_pass] = root_pass
end
+
+ if vmdk_path = ENV['NALLOC_VMDK_PATH']
+ @node_specs[name][:vmdk_path] = vmdk_path
+ end
end
end
View
56 lib/nalloc/driver/fusion.rb
@@ -15,10 +15,12 @@ class Nalloc::Driver::Fusion < Nalloc::Driver
VM_STORE_PATH = File.join(CONFIG_DIR, "vms")
TEMPLATE_DIR = Nalloc.path("templates/fusion")
- VMX_TEMPLATE_PATH = File.join(TEMPLATE_DIR, "zygote.vmx.erb")
+ 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_SSH_KEY = "id_rsa"
+
class << self
def save_adapters(adapters)
File.open(ADAPTER_POOL_PATH, 'w+') do |f|
@@ -29,32 +31,6 @@ def save_adapters(adapters)
def load_adapters
adapters = JSON.parse(File.read(ADAPTER_POOL_PATH))
end
-
- def write_defaults(defaults)
- File.open(DEFAULTS_PATH, 'w+') do |f|
- f.write(defaults.to_json)
- end
-
- nil
- end
-
- # Returns default options used during node allocation
- #
- # @return [Hash] 'vmdk_path' => Path to base vmdk
- # 'vmx_template_path' => Path to vmx erb template
- def defaults
- unless @defaults
- raw_defaults = File.read(DEFAULTS_PATH)
- @defaults = JSON.parse(raw_defaults)
- @defaults.freeze
- end
-
- @defaults
- end
-
- def default_on(specs, prop)
- specs[prop] || self.defaults[prop.to_s]
- end
end
def name
@@ -128,23 +104,16 @@ 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 = self.class.default_on(specs, :vmdk_path)
- raise "No vmdk_path specified for node #{name}" unless vmdk_path
-
- root_pass = self.class.default_on(specs, :root_pass)
- raise "No root_pass specified for node #{name}" unless root_pass
-
- user = specs[:username]
- raise "No user given for node #{name}" unless specs[:username]
-
- ssh_key_name = specs[:ssh_key_name]
- raise "No ssh_key_name given for node #{name}" unless specs[:ssh_key_name]
+ 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)
+ ssh_key_name = ENV['NALLOC_SSH_KEY'] || DEFAULT_SSH_KEY
private_key_path = Nalloc::Node.find_ssh_key(ssh_key_name)
public_key_path = Nalloc::Node.find_ssh_key("#{ssh_key_name}.pub")
- vmx_template_path = self.class.default_on(specs, :vmx_template_path)
- vmx_template_path ||= VMX_TEMPLATE_PATH
+ vmx_template_path = specs[:vmx_template_path] || DEFAULT_VMX_TEMPLATE_PATH
vmx_path = create_vm(vmx_template_path, cluster_dir,
:name => name,
@@ -386,4 +355,11 @@ def find_active_nodes
vms
end
+
+ def get_required_spec_option(node_name, specs, key)
+ unless val = specs[key]
+ raise "No #{key} specified for node #{node_name}"
+ end
+ val
+ end
end

0 comments on commit 35f3c23

Please sign in to comment.