Skip to content

Instantly share code, notes, and snippets.

@jasonwbarnett
Last active January 1, 2020 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonwbarnett/0f7522527f982d3200fd04aa7725547e to your computer and use it in GitHub Desktop.
Save jasonwbarnett/0f7522527f982d3200fd04aa7725547e to your computer and use it in GitHub Desktop.
diff --git /opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/kitchen-vcenter-2.6.0/lib/support/clone_vm.rb /opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/kitchen-vcenter-2.6.0/lib/support/clone_vm.rb
index d73c4cc..e672f0a 100644
--- /opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/kitchen-vcenter-2.6.0/lib/support/clone_vm.rb
+++ /opt/chefdk/embedded/lib/ruby/gems/2.4.0/gems/kitchen-vcenter-2.6.0/lib/support/clone_vm.rb
@@ -395,15 +395,34 @@ class Support
options[:clone_type] == :full
end
+ def root_folder
+ vim.serviceInstance.content.rootFolder
+ end
+
+ #
+ # @return [String]
+ #
+ def datacenter
+ options[:datacenter]
+ end
+
+ #
+ # @return [RbVmomi::VIM::Datacenter]
+ #
+ def find_datacenter
+ vim.serviceInstance.find_datacenter(datacenter)
+ rescue RbVmomi::Fault
+ root_folder.childEntity.grep(RbVmomi::VIM::Datacenter).find { |x| x.name == datacenter }
+ end
+
def clone
benchmark_start if benchmark?
# set the datacenter name
- dc = vim.serviceInstance.find_datacenter(options[:datacenter])
+ dc = find_datacenter
# reference template using full inventory path
- root_folder = vim.serviceInstance.content.rootFolder
- inventory_path = format("/%s/vm/%s", options[:datacenter], options[:template])
+ inventory_path = format("/%s/vm/%s", datacenter, options[:template])
src_vm = root_folder.findByInventoryPath(inventory_path)
raise Support::CloneError.new(format("Unable to find template: %s", options[:template])) if src_vm.nil?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment