Created
May 31, 2013 15:16
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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