Skip to content

Instantly share code, notes, and snippets.

@swalberg
Created June 2, 2016 14:54
Show Gist options
  • Save swalberg/bbd94309986a09281a11035650cb5b07 to your computer and use it in GitHub Desktop.
Save swalberg/bbd94309986a09281a11035650cb5b07 to your computer and use it in GitHub Desktop.
def add_nic(name)
network = find_network(options["net"])
puts network.class
case network
when RbVmomi::VIM::DistributedVirtualPortgroup
switch, pg_key = network.collect 'config.distributedVirtualSwitch', 'key'
port = RbVmomi::VIM.DistributedVirtualSwitchPortConnection(
switchUuid: switch.uuid,
portgroupKey: pg_key)
summary = network.name
backing = RbVmomi::VIM.VirtualEthernetCardDistributedVirtualPortBackingInfo(port: port)
when VIM::Network
summary = network.name
backing = RbVmomi::VIM.VirtualEthernetCardNetworkBackingInfo(deviceName: network.name)
else fail
end
vm = find_by_name(name)
vm.ReconfigVM_Task(spec: {
deviceChange: [
{ operation: :add,
fileOperation: nil,
device: RbVmomi::VIM::VirtualVmxnet3(
key: -1,
deviceInfo: {
summary: summary,
label: ""
},
backing: backing,
addressType: "generated"
)
}
]}).wait_for_completion
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment