Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add networks configuration to configure networks
  • Loading branch information
elynn authored and Ethan Lynn committed Dec 19, 2016
commit 3a543c2d58682c677b47ea6bcc73ade0413473dc
62 changes: 56 additions & 6 deletions lib/vSphere/action/clone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ def call(env)

spec[:customization] = get_customization_spec(machine, customization_info) unless customization_info.nil?

env[:ui].info "Setting custom address: #{config.addressType}" unless config.addressType.nil?
add_custom_address_type(template, spec, config.addressType) unless config.addressType.nil?
# env[:ui].info "Setting custom address: #{config.addressType}" unless config.addressType.nil?
# add_custom_address_type(template, spec, config.addressType) unless config.addressType.nil?

env[:ui].info "Setting custom mac: #{config.mac}" unless config.mac.nil?
add_custom_mac(template, spec, config.mac) unless config.mac.nil?
# env[:ui].info "Setting custom mac: #{config.mac}" unless config.mac.nil?
# add_custom_mac(template, spec, config.mac) unless config.mac.nil?

env[:ui].info "Setting custom vlan: #{config.vlan}" unless config.vlan.nil?
add_custom_vlan(template, dc, spec, config.vlan) unless config.vlan.nil?
# env[:ui].info "Setting custom vlan: #{config.vlan}" unless config.vlan.nil?
# add_custom_vlan(template, dc, spec, config.vlan) unless config.vlan.nil?

env[:ui].info "Setting custom networks: #{config.networks}" unless config.networks.empty?
add_custom_networks(template, spec, config.networks) unless config.networks.empty?

env[:ui].info "Setting custom memory: #{config.memory_mb}" unless config.memory_mb.nil?
add_custom_memory(spec, config.memory_mb) unless config.memory_mb.nil?
Expand Down Expand Up @@ -267,6 +270,53 @@ def add_custom_vlan(template, dc, spec, vlan)
end
end

def add_custom_networks(template, spec, networks)
spec[:config][:deviceChange] ||= []
cards = template.config.hardware.device.grep(RbVmomi::VIM::VirtualEthernetCard)
cards.each do |card|
dev_spec = RbVmomi::VIM.VirtualDeviceConfigSpec(device: card, operation: 'remove')
spec[:config][:deviceChange].push dev_spec
end

networks.each do |net|
network = net[:network] || ''
adaptertype = net[:adaptertype] || ''
mac = net[:mac] || ''
if mac == ''
addresstype = net[:addresstype] || 'generated'
else
addresstype = 'manual'
end
backing = RbVmomi::VIM::VirtualEthernetCardNetworkBackingInfo(
deviceName: network)
if adaptertype == 'e1000'
card_device = RbVmomi::VIM::VirtualE1000(
key: -1,
deviceInfo: {
label: '',
summary: network,
},
backing: backing,
addressType: addresstype,
macAddress: mac
)
else
card_device = RbVmomi::VIM::VirtualVmxnet3(
key: -1,
deviceInfo: {
label: '',
summary: network,
},
backing: backing,
addressType: addresstype,
macAddress: mac
)
end
dev_spec = RbVmomi::VIM.VirtualDeviceConfigSpec(device: card_device, operation: 'add')
spec[:config][:deviceChange].push dev_spec
end
end

def add_custom_memory(spec, memory_mb)
spec[:config][:memoryMB] = Integer(memory_mb)
end
Expand Down
2 changes: 2 additions & 0 deletions lib/vSphere/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ class Config < Vagrant.plugin('2', :config)
attr_accessor :extra_config
attr_accessor :real_nic_ip
attr_accessor :notes
attr_accessor :networks

attr_reader :custom_attributes

def initialize
@ip_address_timeout = UNSET_VALUE
@custom_attributes = {}
@extra_config = {}
@networks = []
end

def finalize!
Expand Down