mirror of
https://github.com/cliffe/SecGen.git
synced 2026-02-21 11:18:06 +00:00
Added ESXi Support
This commit is contained in:
@@ -50,6 +50,7 @@
|
||||
<xs:element name="platform" type="platformOptions" minOccurs="1" maxOccurs="unbounded"/>
|
||||
<xs:element name="distro" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="url" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="esxi_url" type="xs:string" minOccurs="0" maxOccurs="1"/>
|
||||
<xs:element name="ovirt_template" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
|
||||
|
||||
<xs:element name="packerfile_path" type="xs:string" minOccurs="0" maxOccurs="1"/>
|
||||
|
||||
@@ -18,6 +18,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
if selected_module.module_type == 'base'
|
||||
@base_type = selected_module.attributes['type']
|
||||
@ovirt_template = selected_module.attributes['ovirt_template']
|
||||
@esxi_url = selected_module.attributes['esxi_url']
|
||||
@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
|
||||
@@ -58,6 +59,30 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
ovirt.debug = true
|
||||
end
|
||||
# oVirt provider end
|
||||
|
||||
<% elsif (@options.has_key? :esxiuser) && (@options.has_key? :esxipass) %>
|
||||
# vmware_esxi provider begin
|
||||
<%= system.name %>.vm.provider :vmware_esxi do |esxi|
|
||||
<%=
|
||||
" esxi.esxi_hostname = '#{@options[:esxiurl]}'
|
||||
esxi.esxi_username = '#{@options[:esxiuser]}'
|
||||
esxi.esxi_password = '#{@options[:esxipass]}' "
|
||||
%>
|
||||
|
||||
<%= if @options.has_key? :esxidatastore
|
||||
" esxi.esxi_disk_store = '#{@options[:esxidatastore]}'"
|
||||
end -%>
|
||||
<%= if @options.has_key? :esxi_disktype
|
||||
" esxi.guest_disk_type = '#{@options[:esxi_disktype]}'"
|
||||
end -%>
|
||||
<%= if @options.has_key? :memory_per_vm
|
||||
" esxi.guest_memsize = '#{@options[:memory_per_vm]}'"
|
||||
end -%>
|
||||
<%= if @options.has_key? :cpu_cores
|
||||
" esxi.guest_numvcpus = #{@options[:cpu_cores]}\n"
|
||||
end -%>
|
||||
end
|
||||
# End ESXi provider
|
||||
<%
|
||||
else %>
|
||||
config.vm.provider :virtualbox do |vb|
|
||||
@@ -118,6 +143,10 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
<%= system.name %>.vm.hostname = '<%= "#{prefix}#{system.name}".tr('_', '-') %>'
|
||||
<%= 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 = '<%= "#{prefix}#{system.name}".tr('_', '-') %>'
|
||||
<%= system.name %>.vm.box = "<%= selected_module.module_path_name %>"
|
||||
<%= system.name %>.vm.box_url = "<%= selected_module.attributes['esxi_url'].first %>"
|
||||
<% else %>
|
||||
<%= system.name %>.vm.box = "<%= selected_module.module_path_name %>"
|
||||
<%= system.name %>.vm.box_url = "<%= selected_module.attributes['url'].first %>"
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
<platform>unix</platform>
|
||||
<distro>Debian 7.8 (wheezy) 32-bit (i386)</distro>
|
||||
<url>https://app.vagrantup.com/secgen/boxes/debian_wheezy_puppet/versions/1.0.0/providers/virtualbox.box</url>
|
||||
<esxi_url>https://app.vagrantup.com/redwiz666/boxes/debian_wheezy_puppet/versions/1.0.0/providers/vmware_esxi.box</esxi_url>
|
||||
<ovirt_template>debian_server</ovirt_template>
|
||||
|
||||
<reference>https://atlas.hashicorp.com/puppetlabs</reference>
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
<platform>unix</platform>
|
||||
<distro>Debian 9.5.0 Stretch amd64</distro>
|
||||
<url>https://app.vagrantup.com/secgen/boxes/debian_stretch_server/versions/1.1/providers/virtualbox.box</url>
|
||||
<esxi_url>https://app.vagrantup.com/redwiz666/boxes/debian_stretch_server/versions/1.0.0/providers/vmware.box</esxi_url>
|
||||
<ovirt_template>debian_stretch_server_291118</ovirt_template>
|
||||
|
||||
<software_license>various</software_license>
|
||||
</base>
|
||||
</base>
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
<platform>unix</platform>
|
||||
<distro>Debian 9.5.0 Stretch amd64</distro>
|
||||
<url>https://app.vagrantup.com/secgen/boxes/debian_stretch_desktop_kde/versions/1.1/providers/virtualbox.box</url>
|
||||
<esxi_url>https://app.vagrantup.com/redwiz666/boxes/debian_stretch_desktop_kde/versions/1.0.0/providers/vmware.box</esxi_url>
|
||||
<ovirt_template>stretch_desktop_kde_301118</ovirt_template>
|
||||
|
||||
<reference>https://atlas.hashicorp.com/puppetlabs</reference>
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
<platform>unix</platform>
|
||||
<distro>Debian 7.8 (wheezy) 32-bit (i386)</distro>
|
||||
<url>https://app.vagrantup.com/secgen/boxes/debian_wheezy_kde_puppet/versions/1.0.0/providers/virtualbox.box</url>
|
||||
<esxi_url>https://app.vagrantup.com/redwiz666/boxes/debian_wheezy_desktop_kde/versions/1.0.0/providers/vmware.box</esxi_url>
|
||||
<ovirt_template>debian_desktop_kde</ovirt_template>
|
||||
|
||||
<reference>https://atlas.hashicorp.com/puppetlabs</reference>
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
<platform>unix</platform>
|
||||
<distro>Kali Linux 2018.3</distro>
|
||||
<url>https://app.vagrantup.com/secgen/boxes/kali_light/versions/1.0/providers/virtualbox.box</url>
|
||||
<esxi_url>https://app.vagrantup.com/redwiz666/boxes/kali_light/versions/1.0.0/providers/vmware.box</esxi_url>
|
||||
|
||||
<reference>https://app.vagrantup.com/secgen</reference>
|
||||
<software_license>various</software_license>
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
<platform>unix</platform>
|
||||
<distro>Kali Linux 2018.3</distro>
|
||||
<url>https://app.vagrantup.com/secgen/boxes/kali_light_msf/versions/1.0/providers/virtualbox.box</url>
|
||||
<esxi_url></esxi_url>
|
||||
<ovirt_template>kali_linux_msf</ovirt_template>
|
||||
|
||||
|
||||
<reference>https://app.vagrantup.com/secgen</reference>
|
||||
<software_license>various</software_license>
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
<platform>unix</platform>
|
||||
<distro>Ubuntu Xenial 16.04 LTS</distro>
|
||||
<url>https://app.vagrantup.com/puppetlabs/boxes/ubuntu-16.04-64-puppet/versions/1.0.0/providers/virtualbox.box</url>
|
||||
<esxi_url>https://app.vagrantup.com/redwiz666/boxes/ubuntu-16.04-64-puppet/versions/1.0.0/providers/vmware_esxi.box</esxi_url>
|
||||
<ovirt_template>debian_server</ovirt_template>
|
||||
|
||||
<reference>https://atlas.hashicorp.com/puppetlabs</reference>
|
||||
|
||||
58
secgen.rb
58
secgen.rb
@@ -48,6 +48,14 @@ def usage
|
||||
--ovirt-network [ovirt_network_name]
|
||||
--ovirt-affinity-group [ovirt_affinity_group_name]
|
||||
|
||||
ESXI OPTIONS:
|
||||
--esxiuser [esxi_username]
|
||||
--esxipass [esxi_password]
|
||||
--esxi-url [esxi_api_url]
|
||||
--esxi-datastore [esxi_datastore]
|
||||
--esxi-disktype [esxi_disktype]
|
||||
--esxi-network [esxi_network_name]
|
||||
|
||||
COMMANDS:
|
||||
run, r: Builds project and then builds the VMs
|
||||
build-project, p: Builds project (vagrant and puppet config), but does not build VMs
|
||||
@@ -161,6 +169,7 @@ def build_vms(scenario, project_dir, options)
|
||||
Print.info "vagrant #{destroy} completed successfully."
|
||||
else
|
||||
OVirtFunctions::remove_uncreated_vms(destroy_output[:output], options, scenario)
|
||||
# Add ESXI destroy uncreated VMs
|
||||
end
|
||||
else
|
||||
Print.err "Failed to destroy #{failed_vm}. Exiting."
|
||||
@@ -182,6 +191,15 @@ def build_vms(scenario, project_dir, options)
|
||||
end
|
||||
if successful_creation
|
||||
ovirt_post_build(options, scenario, project_dir) if OVirtFunctions.provider_ovirt?(options)
|
||||
if options[:snapshot]
|
||||
Print.info 'Creating a snapshot of VM(s)'
|
||||
sleep(20) # give oVirt/Virtualbox a chance to save any VM config changes before creating the snapshot
|
||||
if OVirtFunctions::provider_ovirt?(options)
|
||||
OVirtFunctions::create_snapshot(options, scenario, get_vm_names(scenario))
|
||||
else
|
||||
GemExec.exe('vagrant', project_dir, 'snapshot push')
|
||||
end
|
||||
end
|
||||
else
|
||||
Print.err "Failed to build VMs"
|
||||
exit 1
|
||||
@@ -200,15 +218,6 @@ def ovirt_post_build(options, scenario, project_dir)
|
||||
Print.info 'Assigning affinity group of VM(s)'
|
||||
OVirtFunctions::assign_affinity_group(options, scenario, get_vm_names(scenario))
|
||||
end
|
||||
if options[:snapshot]
|
||||
Print.info 'Creating a snapshot of VM(s)'
|
||||
sleep(20) # give oVirt/Virtualbox a chance to save any VM config changes before creating the snapshot
|
||||
if OVirtFunctions::provider_ovirt?(options)
|
||||
OVirtFunctions::create_snapshot(options, scenario, get_vm_names(scenario))
|
||||
else
|
||||
GemExec.exe('vagrant', project_dir, 'snapshot push')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Make forensic image helper methods
|
||||
@@ -377,6 +386,11 @@ opts = GetoptLong.new(
|
||||
['--ovirt-network', GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--ovirt-affinity-group', GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--snapshot', GetoptLong::NO_ARGUMENT],
|
||||
['--esxiuser', GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--esxipass', GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--esxi-url', GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--esxi-datastore', GetoptLong::REQUIRED_ARGUMENT],
|
||||
['--esxi-network', GetoptLong::REQUIRED_ARGUMENT],
|
||||
)
|
||||
|
||||
scenario = SCENARIO_XML
|
||||
@@ -470,6 +484,28 @@ opts.each do |opt, arg|
|
||||
when '--snapshot'
|
||||
Print.info "Taking snapshots when VMs are created"
|
||||
options[:snapshot] = true
|
||||
|
||||
when '--esxiuser'
|
||||
Print.info "ESXi Username : #{arg}"
|
||||
options[:esxiuser] = arg
|
||||
when '--esxipass'
|
||||
Print.info "ESXi Password : ********"
|
||||
options[:esxipass] = arg
|
||||
when '--esxi-url'
|
||||
Print.info "ESXi host url : #{arg}"
|
||||
options[:esxiurl] = arg
|
||||
when '--esxi-datastore'
|
||||
Print.info "ESXi datastore: #{arg}"
|
||||
options[:esxidatastore] = arg
|
||||
when '--esxi-network'
|
||||
Print.info "ESXi Network Name : #{arg}"
|
||||
options[:esxinetwork] = arg
|
||||
when '--esxi-disktype'
|
||||
Print.info "ESXi disk type : #{arg}"
|
||||
options[:esxidisktype] = arg
|
||||
when '--snapshot'
|
||||
Print.info "Taking snapshots when VMs are created"
|
||||
options[:snapshot] = true
|
||||
|
||||
else
|
||||
Print.err "Argument not valid: #{arg}"
|
||||
@@ -515,6 +551,10 @@ case ARGV[0]
|
||||
make_forensic_image(project_dir, nil, image_type)
|
||||
end
|
||||
|
||||
when 'esxi-post-build'
|
||||
esxi_post_build(options, scenario, project_dir)
|
||||
exit 0
|
||||
|
||||
when 'ovirt-post-build'
|
||||
ovirt_post_build(options, scenario, project_dir)
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user