lib/vagrant-vcenter/action/build_vm.rb in vagrant-vcenter-0.1.1 vs lib/vagrant-vcenter/action/build_vm.rb in vagrant-vcenter-0.2.0

- old
+ new

@@ -91,15 +91,76 @@ spec = RbVmomi::VIM.VirtualMachineCloneSpec( :location => relocate_spec, :powerOn => false, :template => false) + + if config.vm_network_name or config.num_cpu or config.memory + config_spec = RbVmomi::VIM.VirtualMachineConfigSpec + config_spec.numCPUs = config.num_cpu if config.num_cpu + config_spec.memoryMB = config.memory if config.memory + + if config.vm_network_name + # First we must find the specified network + network = dc.network.find { |f| f.name == config.vm_network_name } or + abort "Could not find network with name #{config.vm_network_name} to join vm to" + card = template.config.hardware.device.grep( + RbVmomi::VIM::VirtualEthernetCard).first or + abort "could not find network card to customize" + if config.vm_network_type == "DistributedVirtualSwitchPort" + switch_port = RbVmomi::VIM.DistributedVirtualSwitchPortConnection( + :switchUuid => network.config.distributedVirtualSwitch.uuid, + :portgroupKey => network.key) + card.backing = RbVmomi::VIM.VirtualEthernetCardDistributedVirtualPortBackingInfo( + :port => switch_port) + else + abort "vm network type of #{config.vm_network_type} is unknown" + end + dev_spec = RbVmomi::VIM.VirtualDeviceConfigSpec(:device => card, :operation => "edit") + config_spec.deviceChange = [dev_spec] + end + + spec.config = config_spec + end + if config.enable_vm_customization or config.enable_vm_customization == 'true' + gIPSettings = RbVmomi::VIM.CustomizationGlobalIPSettings( + :dnsServerList => config.dns_server_list, + :dnsSuffixList => config.dns_suffix_list) + + prep = RbVmomi::VIM.CustomizationLinuxPrep( + :domain => env[:machine].name, + :hostName => RbVmomi::VIM.CustomizationFixedName( + :name => env[:machine].name)) + + adapter = RbVmomi::VIM.CustomizationIPSettings( + :gateway => [config.gateway], + :ip => RbVmomi::VIM.CustomizationFixedIp( + :ipAddress => config.ipaddress), + :subnetMask => config.netmask) + + nic_map = [RbVmomi::VIM.CustomizationAdapterMapping( + :adapter => adapter)] + + cust_spec = RbVmomi::VIM.CustomizationSpec( + :globalIPSettings => gIPSettings, + :identity => prep, + :nicSettingMap => nic_map) + + spec.customization = cust_spec + end + @logger.debug("Spec: #{spec.pretty_inspect}") - vm_target = "Vagrant-#{Etc.getlogin}-" + - "#{vm_name}-#{Socket.gethostname.downcase}-" + - "#{SecureRandom.hex(4)}" + @logger.debug("disable_auto_vm_name: #{config.disable_auto_vm_name}") + + if config.disable_auto_vm_name or config.disable_auto_vm_name == 'true' + vm_target = vm_name.to_s + else + vm_target = "Vagrant-#{Etc.getlogin}-" + + "#{vm_name}-#{Socket.gethostname.downcase}-" + + "#{SecureRandom.hex(4)}" + end @logger.debug("VM name: #{vm_target}") # FIXME: vm.parent brings us to the template folder, fix this with # folder_path.