Skip to content

Instantly share code, notes, and snippets.

@gizmomogwai
Created May 3, 2013 15:13
Show Gist options
  • Save gizmomogwai/5509735 to your computer and use it in GitHub Desktop.
Save gizmomogwai/5509735 to your computer and use it in GitHub Desktop.
Clone a stopped VMWare vm.
from = ARGV[0]
to = ARGV[1]
puts "copy from #{from} to #{to}"
def run(cmd)
puts "Executing #{cmd}"
if !system(cmd)
raise "error while executing #{cmd}"
end
end
run("cp -r \"#{from}\" \"#{to}\"")
Dir.glob("#{to}/*").each do |f|
if f.index(from)
new_name = f.gsub(from, to)
run("mv \"#{f}\" \"#{new_name}\"")
end
end
def replace_vm_name(filename, from, to)
original_content = File.read(filename)
new_content = original_content.gsub(from, to)
File.write(filename, new_content)
end
replace_vm_name("#{to}/#{to}.vmx", from, to)
replace_vm_name("#{to}/#{to}.vmdk", from, to)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment