From cef610bf044a05b7d222fb2d64a1784c7f2adb2b Mon Sep 17 00:00:00 2001 From: thomashaw Date: Thu, 28 Sep 2017 14:55:21 +0100 Subject: [PATCH] oVirt now uses VM memory allocation based on command line options. Added missing options to usage. Added default memory allocations for oVirt VMs based on base type. --- lib/templates/Vagrantfile.erb | 36 +++++++++++++------ .../Packerfile.erb | 4 +-- secgen.rb | 13 ++++--- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/lib/templates/Vagrantfile.erb b/lib/templates/Vagrantfile.erb index bd98a1655..87191b104 100644 --- a/lib/templates/Vagrantfile.erb +++ b/lib/templates/Vagrantfile.erb @@ -13,6 +13,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| <% @systems.each do |system| %> <% system.module_selections.each do |selected_module| if selected_module.module_type == 'base' + @base_type = selected_module.attributes['type'] @cpu_word_size = selected_module.attributes['cpu_word_size'].first.downcase if (@options.has_key? :ovirtuser) && (@options.has_key? :ovirtpass) @ovirt_base_template = selected_module.attributes['ovirt_template'].first @@ -23,17 +24,30 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| <% if (@options.has_key? :ovirtuser) && (@options.has_key? :ovirtpass) %> #oVirt provider begin <%= system.name %>.vm.provider :ovirt4 do |ovirt| - <%= -" ovirt.username = '#{@options[:ovirtuser]}' - ovirt.password = '#{@options[:ovirtpass]}'" %> - <%= if @options.has_key? :ovirturl -" ovirt.url = '#{@options[:ovirturl]}'" +<%= +" ovirt.username = '#{@options[:ovirtuser]}' + ovirt.password = '#{@options[:ovirtpass]}'" %> +<%= if @options.has_key? :ovirturl +" ovirt.url = '#{@options[:ovirturl]}'" end %> - <%= if @options.has_key? :ovirtcluster -" ovirt.cluster = '#{@options[:ovirtcluster]}'" +<%= if @options.has_key? :ovirtcluster +" ovirt.cluster = '#{@options[:ovirtcluster]}'" end %> - <%= -" ovirt.template = '#{@ovirt_base_template}'" %> +<%= +" ovirt.template = '#{@ovirt_base_template}'" %> +<%= if @options.has_key? :memory_per_vm +" ovirt.memory_size = '#{@options[:memory_per_vm]} MB'\n" + elsif @options.has_key? :total_memory +" ovirt.memory_size = '#{(@options[:total_memory].to_i / @systems.length.to_i)} MB'\n" + elsif @base_type.include? 'desktop' +" ovirt.memory_size = '2048 MB' + ovirt.memory_guaranteed = '512 MB'\n" + else +" ovirt.memory_size = '512 MB'\n" + end -%> +<%= if @options.has_key? :cpu_cores +" ovirt.cpu_cores = #{@options[:cpu_cores]}\n" + end -%> ovirt.console = 'vnc' ovirt.insecure = true ovirt.filtered_api = true @@ -68,8 +82,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| elsif @options.has_key? :total_memory " vb.memory = #{@options[:total_memory]}/#{@systems.length}\n" end -%> -<%= if @options.has_key? :max_cpu_cores - " vb.cpus = #{@options[:max_cpu_cores]}\n" +<%= if @options.has_key? :cpu_cores + " vb.cpus = #{@options[:cpu_cores]}\n" end -%> <%= if @options.has_key? :max_cpu_usage " vb.customize ['modifyvm', :id, '--cpuexecutioncap', '#{@options[:max_cpu_usage]}']\n" diff --git a/modules/bases/windows_server_2008_r2_amd64/Packerfile.erb b/modules/bases/windows_server_2008_r2_amd64/Packerfile.erb index d01d790b8..7b1ef9500 100644 --- a/modules/bases/windows_server_2008_r2_amd64/Packerfile.erb +++ b/modules/bases/windows_server_2008_r2_amd64/Packerfile.erb @@ -8,8 +8,8 @@ elsif (@options.has_key? :total_memory) "[ \"modifyvm\", \"{{.Name}}\", \"--memory\", \"#{@options[:total_memory]/@systems.length}\" ]," end %> -<%= if (@options.has_key? :max_cpu_cores) - "[ \"modifyvm\", \"{{.Name}}\", \"--cpus\", \"#{@options[:max_cpu_cores]}\" ]," +<%= if (@options.has_key? :cpu_cores) + "[ \"modifyvm\", \"{{.Name}}\", \"--cpus\", \"#{@options[:cpu_cores]}\" ]," end %> <%= if (@options.has_key? :max_cpu_usage) "[ \"modifyvm\", \"{{.Name}}\", \"--cpuexecutioncap\", \"#{@options[:max_cpu_usage]}\" ]," diff --git a/secgen.rb b/secgen.rb index 1f1b7702f..b4f5c2918 100644 --- a/secgen.rb +++ b/secgen.rb @@ -18,10 +18,13 @@ def usage (defaults to #{SCENARIO_XML}) --project [output dir], -p [output dir]: Directory for the generated project (output will default to #{default_project_dir}) - --shutdown: Shutdown vms after provisioning + --shutdown: Shutdown VMs after provisioning (vagrant halt) --network-ranges: Override network ranges within the scenario, use a comma-separated list --forensic-image-type [image type]: Forensic image format of generated image (raw, ewf) --read-options [conf path]: Reads options stored in file as arguments (see example.conf) + --memory-per-vm: Allocate generated VMs memory in MB (e.g. --memory-per-vm 1024) + --total-memory: Allocate total VM memory for the scenario, split evenly across all VMs. + --cpu-cores: Number of virtual CPUs for generated VMs --help, -h: Shows this usage information VIRTUALBOX OPTIONS: @@ -29,6 +32,8 @@ def usage --nopae: disable PAE support --hwvirtex: enable HW virtex support --vtxvpid: enable VTX support + --max-cpu-usage [1-100]: controls how much cpu time a virtual CPU can use + (e.g. 50 implies a single virtual CPU can use up to 50% of a single host CPU) OVIRT OPTIONS: --ovirtuser [ovirt_username] @@ -277,7 +282,7 @@ opts = GetoptLong.new( [ '--vtxvpid', GetoptLong::NO_ARGUMENT], [ '--memory-per-vm', GetoptLong::REQUIRED_ARGUMENT], [ '--total-memory', GetoptLong::REQUIRED_ARGUMENT], - [ '--max-cpu-cores', GetoptLong::REQUIRED_ARGUMENT], + [ '--cpu-cores', GetoptLong::REQUIRED_ARGUMENT], [ '--max-cpu-usage', GetoptLong::REQUIRED_ARGUMENT], [ '--shutdown', GetoptLong::NO_ARGUMENT], [ '--network-ranges', GetoptLong::REQUIRED_ARGUMENT], @@ -334,9 +339,9 @@ opts.each do |opt, arg| Print.info "Total memory to be used set to #{arg}" options[:total_memory] = arg end - when '--max-cpu-cores' + when '--cpu-cores' Print.info "Number of cpus to be used set to #{arg}" - options[:max_cpu_cores] = arg + options[:cpu_cores] = arg when '--max-cpu-usage' Print.info "Max CPU usage set to #{arg}" options[:max_cpu_usage] = arg