Skip to content

Instantly share code, notes, and snippets.

@pcn
Forked from shellbj/vsphere-plugin-mac-change.rb
Created March 21, 2014 21:19
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 pcn/9696731 to your computer and use it in GitHub Desktop.
Save pcn/9696731 to your computer and use it in GitHub Desktop.
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