From caacc733c01fd2041825797a8ce66da1f02b32ec Mon Sep 17 00:00:00 2001 From: redwiz666 Date: Thu, 29 Dec 2022 15:30:07 -0600 Subject: [PATCH] Fixed ESXI Vagrant File --- README.md | 11 +++++++-- lib/templates/Vagrantfile.erb | 31 ++++++++++++++---------- secgen.rb | 45 ++++++++++++++++++++++++++++------- 3 files changed, 64 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 952a605e4..c1e115fda 100644 --- a/README.md +++ b/README.md @@ -147,10 +147,17 @@ SecGen accepts arguments to change the way that it behaves, the currently implem ESXI OPTIONS: --esxiuser [esxi_username] --esxipass [esxi_password] - --esxi-url [esxi_api_url] + --esxi-hostname [esxi_api_url] + (ESXi hostname/IP) --esxi-datastore [esxi_datastore] - --esxi-disktype [esxi_disktype] + --esxi-disktype [esxi_disktype]: 'thin', 'thick', or 'eagerzeroedthick' + (If unspecified, it will be set to 'thin') --esxi-network [esxi_network_name] + (If its not specified, the default is to use the first found) + --esxi-guest-nictype [esxi_nictype]: 'e1000', 'e1000e', 'vmxnet', 'vmxnet2', 'vmxnet3', 'Vlance', or 'Flexible' + (RISKY - Can cause VM to not respond) + --esxi-no-hostname + (Setting the hostname on some boxes can cause vagrant up to fail if the network configuration was not previously cleaned up.) COMMANDS: run, r: Builds project and then builds the VMs diff --git a/lib/templates/Vagrantfile.erb b/lib/templates/Vagrantfile.erb index 69377b4de..6be42b3f8 100644 --- a/lib/templates/Vagrantfile.erb +++ b/lib/templates/Vagrantfile.erb @@ -63,28 +63,31 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| end # oVirt provider end -<% elsif (@options.has_key? :esxiuser) && (@options.has_key? :esxipass) %> +<% elsif (@options.has_key? :esxiuser) %> # vmware_esxi provider begin <%= system.name %>.vm.provider :vmware_esxi do |esxi| <%= -" esxi.esxi_hostname = '#{@options[:esxi_url]}' +" esxi.esxi_hostname = '#{@options[:esxi_host]}' esxi.esxi_username = '#{@options[:esxiuser]}' - esxi.esxi_password = '#{@options[:esxipass]}' " + esxi.esxi_password = '#{@options[:esxipass]}'" %> - <%= if @options.has_key? :esxidatastore - " esxi.esxi_disk_store = '#{@options[:esxidatastore]}'" + " esxi.esxi_disk_store = '#{@options[:esxidatastore]}'\n" end -%> -<%= if @options.has_key? :esxi_disktype -" esxi.guest_disk_type = '#{@options[:esxi_disktype]}'" +<%= if @options.has_key? :esxidisktype + " esxi.guest_disk_type = '#{@options[:esxidisktype]}'\n" end -%> -<%= " esxi.guest_memsize = '#{system.memory} MB'\n" +<%= " esxi.guest_memsize = '#{system.memory} MB'\n" -%> -<%= if @options.has_key? :cpu_cores -" esxi.guest_numvcpus = #{@options[:cpu_cores]}\n" +<%= if @options.has_key? :cpu_cores + " esxi.guest_numvcpus = #{@options[:cpu_cores]}\n" end -%> -end - # End ESXi provider +<%= if @options.has_key? :esxinetwork + " esxi.esxi_virtual_network = ['#{@options[:esxinetwork]}']\n" + end -%> + <%= " esxi.guest_name = '#{system.get_hostname}'\n" -%> + end +# End ESXi provider <% else %> <%= system.name %>.vm.provider :virtualbox do |vb| @@ -148,7 +151,9 @@ end <%= system.name %>.vm.box = 'ovirt4' <%= system.name %>.vm.box_url = 'https://github.com/myoung34/vagrant-ovirt4/blob/master/example_box/dummy.box?raw=true' <% elsif (@options.has_key? :esxiuser) && (@options.has_key? :esxipass) %> - <%= system.name %>.vm.hostname = '<%= system.get_hostname %>' + <% if !(@options.has_key? :esxinohostname) %> + <%= system.name %>.vm.hostname = '<%= system.get_hostname %>' + <% end %> <%= system.name %>.vm.box = "<%= selected_module.module_path_name %>" <%= system.name %>.vm.box_url = "<%= selected_module.attributes['esxi_url'].first %>" <% else %> diff --git a/secgen.rb b/secgen.rb index 1c43a7624..4775c21c7 100644 --- a/secgen.rb +++ b/secgen.rb @@ -57,10 +57,17 @@ def usage ESXI OPTIONS: --esxiuser [esxi_username] --esxipass [esxi_password] - --esxi-url [esxi_api_url] + --esxi-hostname [esxi_api_url] + (ESXi hostname/IP) --esxi-datastore [esxi_datastore] - --esxi-disktype [esxi_disktype] + --esxi-disktype [esxi_disktype]: 'thin', 'thick', or 'eagerzeroedthick' + (If unspecified, it will be set to 'thin') --esxi-network [esxi_network_name] + (If it's not specified, the default is to use the first found) + --esxi-guest-nictype [esxi_nictype]: 'e1000', 'e1000e', 'vmxnet', 'vmxnet2', 'vmxnet3', 'Vlance', or 'Flexible' + (RISKY - Can cause VM to not respond) + --esxi-no-hostname + (Setting the hostname on some boxes can cause 'vagrant up' to fail if the network configuration wasn't previously cleaned up.) COMMANDS: run, r: Builds project and then builds the VMs @@ -461,9 +468,12 @@ opts = GetoptLong.new( ['--retries', GetoptLong::REQUIRED_ARGUMENT], ['--esxiuser', GetoptLong::REQUIRED_ARGUMENT], ['--esxipass', GetoptLong::REQUIRED_ARGUMENT], - ['--esxi-url', GetoptLong::REQUIRED_ARGUMENT], + ['--esxi-hostname', GetoptLong::REQUIRED_ARGUMENT], ['--esxi-datastore', GetoptLong::REQUIRED_ARGUMENT], ['--esxi-network', GetoptLong::REQUIRED_ARGUMENT], + ['--esxi-disktype', GetoptLong::REQUIRED_ARGUMENT], + ['--esxi-guest-nictype', GetoptLong::REQUIRED_ARGUMENT], + ['--esxi-no-hostname', GetoptLong::NO_ARGUMENT], ) scenario = SCENARIO_XML @@ -564,9 +574,9 @@ opts.each do |opt, arg| when '--esxipass' Print.info "ESXi Password : ********" options[:esxipass] = arg - when '--esxi-url' - Print.info "ESXi host url : #{arg}" - options[:esxi_url] = arg + when '--esxi-hostname' + Print.info "ESXi host : #{arg}" + options[:esxi_host] = arg when '--esxi-datastore' Print.info "ESXi datastore: #{arg}" options[:esxidatastore] = arg @@ -574,8 +584,27 @@ opts.each do |opt, arg| Print.info "ESXi Network Name : #{arg}" options[:esxinetwork] = arg when '--esxi-disktype' - Print.info "ESXi disk type : #{arg}" - options[:esxidisktype] = arg + if ['thin', 'thick', 'eagerzeroedthick'].include? arg + Print.info "ESXi disk type : #{arg}" + options[:esxidisktype] = arg + else + Print.warn "ESXi disk type : #{arg} not supported" + Print.warn "ESXi disk type only supports: 'thin', 'thick', or 'eagerzeroedthick'" + Print.info "Defaulting to ESXi disk type: 'thin'" + options[:esxidisktype] = 'thin' + end + when '--esxi-guest-nictype' + if ['e1000', 'e1000e', 'vmxnet','vmxnet2', 'vmxnet3', 'Vlance','Flexible'].include? arg + Print.info "ESXi Guest Nic type : #{arg}" + options[:esxiguestnictype] = arg + else + Print.warn "ESXi guest nic type : #{arg} not supported" + Print.warn "ESXi guest nic type only supports: 'e1000', 'e1000e', 'vmxnet','vmxnet2', 'vmxnet3', 'Vlance','Flexible'" + Print.info "Defaulting to ESXi disk type: 'thin'" + end + when '--esxi-no-hostname' + Print.info "Not setting hostnames when VMs are created" + options[:esxinohostname] = true when '--no-tests' Print.info "Not running post-provision tests" options[:notests] = true