rubiojr / knife-esx

@maintux's FORK IS NOW OFFICIAL: https://github.com/maintux/knife-esx
https://github.com/maintux/knife-esx
Apache License 2.0
35 stars 10 forks source link

Connection.template_exist?(config[:use_template]) will always evaluate to false #9

Closed harryyeh closed 11 years ago

harryyeh commented 11 years ago

So I stepped through the code where you have --use-template NAME option

option :use_template, :long => "--use-template NAME", :description => "Try to use an existing template instead of importing disk", :default => nil

if config[:use_template] ui.info "Using template #{config[:use_template]}" if connection.template_exist?(config[:use_template]) puts "#{ui.color("Cloning template...",:magenta)}" connection.copy_from_template config[:use_template], destination_path + "/#{vm_name}.vmdk" else ui.error "Template #{config[:use_template]} not found" exit 1 end else puts "#{ui.color("Importing VM disk... ", :magenta)}" connection.import_disk vm_disk, destination_path + "/#{vm_name}.vmdk" end

is the Name supposed to be the name of the template or template name with .vmdk

for example my template name is server1 - but unless I put server1.vmdk the following code below from the ESX gem will always evaluate to false. Just wanted to confirm with this. Maybe when you specify --use-template you should provide some instructions since it's misleading to use just the name when it should really be --use-template VMDKFile

This code is from the esx gem

def template_exist?(vmdk_file) template_file = File.join(@templates_dir, File.basename(vmdk_file)) Log.debug "Checking if template #{template_file} exists" Net::SSH.start(@address, @user, :password => @password) do |ssh| return false if (ssh.exec! "ls -la #{@templates_dir} 2>/dev/null").nil? return false if (ssh.exec! "ls #{template_file} 2>/dev/null").nil? end Log.debug "Template #{template_file} found" true end

harryyeh commented 11 years ago

Fixed Bug with Commit please check