Skip to content

Instantly share code, notes, and snippets.

@shellbj
Created May 31, 2013 15:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save shellbj/5685674 to your computer and use it in GitHub Desktop.
Save shellbj/5685674 to your computer and use it in GitHub Desktop.
Knife VSphere plugin we use to change the MAC address on the cloned VM's network adapter.
require 'rbvmomi'
class KnifeVspherePlugin
def data=(cplugin_data)
@mac_address = cplugin_data
end
def reconfig_vm(target_vm)
if (!@mac_address)
abort ("MAC address not provided")
end
card = target_vm.config.hardware.device.grep(RbVmomi::VIM::VirtualEthernetCard).find { |x| x.deviceInfo.label == "Network adapter 1" } or
abort "Can't find source network card to customize"
card.macAddress = @mac_address
card_spec = {
:deviceChange => [
{
:operation => :edit,
:device => card
}
]
}
target_vm.ReconfigVM_Task(:spec => card_spec).wait_for_completion
puts "Finished Changing the MAC to #{@mac_address}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment