mirror of
https://github.com/cliffe/SecGen.git
synced 2026-02-20 13:50:45 +00:00
networking
This commit is contained in:
@@ -163,6 +163,79 @@ class OVirtFunctions
|
||||
end
|
||||
end
|
||||
|
||||
def self.assign_networks(options, scenario_path, vm_names)
|
||||
vms = []
|
||||
ovirt_connection = get_ovirt_connection(options)
|
||||
ovirt_vm_names = build_ovirt_names(scenario_path, options[:prefix], vm_names)
|
||||
ovirt_vm_names.each do |vm_name|
|
||||
vms << vms_service(ovirt_connection).list(search: "name=#{vm_name}")
|
||||
end
|
||||
|
||||
network_name = options[:ovirtnetwork]
|
||||
network_network = nil
|
||||
network_profile = nil
|
||||
# Replace 'network' with 'snoop' where the system name contains snoop
|
||||
snoop_network_name = network_name.gsub(/network/, 'snoop')
|
||||
snoop_profile = nil
|
||||
|
||||
# get the service that manages the nics
|
||||
vnic_profiles_service = ovirt_connection.system_service.vnic_profiles_service
|
||||
|
||||
vnic_profiles_service.list.shuffle.each do |vnic_profile|
|
||||
|
||||
if vnic_profile.name =~ /#{network_name}/
|
||||
puts vnic_profile.name
|
||||
puts vnic_profile.network.id
|
||||
network_profile = vnic_profile
|
||||
network_network = vnic_profile.network
|
||||
|
||||
vnic_profiles_service.list.each do |vnic_snoop_profile|
|
||||
if vnic_snoop_profile.name =~ /snoop/ && vnic_snoop_profile.network.id == network_network.id
|
||||
puts vnic_snoop_profile.name
|
||||
snoop_profile = vnic_snoop_profile
|
||||
end
|
||||
end
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
vms.each do |vm_list|
|
||||
vm_list.each do |vm|
|
||||
Print.std " VM: #{vm.name}"
|
||||
Print.std " Assigning network: #{vm.name}"
|
||||
begin
|
||||
# find the service that manages that vm
|
||||
vm_service = vms_service(ovirt_connection).vm_service(vm.id)
|
||||
|
||||
# find the service that manages the nics of that vm
|
||||
nics_service = vm_service.nics_service
|
||||
|
||||
nic = nics_service.list.last
|
||||
|
||||
puts " #{nic.name}"
|
||||
puts " Updating nic"
|
||||
|
||||
update = {}
|
||||
|
||||
if vm.name =~ /snoop/
|
||||
nic.vnic_profile = snoop_profile
|
||||
else
|
||||
nic.vnic_profile = network_profile
|
||||
end
|
||||
|
||||
nics_service.nic_service(nic.id).update(nic, update)
|
||||
puts " #{nic.vnic_profile.name}"
|
||||
|
||||
rescue Exception => e
|
||||
Print.err 'Error adding network:'
|
||||
Print.err e.message
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.assign_permissions(options, scenario_path, vm_names)
|
||||
ovirt_connection = get_ovirt_connection(options)
|
||||
username = options[:prefix].chomp
|
||||
@@ -238,4 +311,4 @@ class OVirtFunctions
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -140,17 +140,9 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
<% else -%>
|
||||
<% if (@options.has_key? :ovirtuser) && (@options.has_key? :ovirtpass) -%>
|
||||
<% if @ovirt_template and (@ovirt_template.include? 'debian_server' ) -%>
|
||||
<% if @options.has_key? :ovirtnetwork -%>
|
||||
<%= system.name %>.vm.network :private_network,
|
||||
:ovirt__network_name => <%= get_ovirt_network_name(system.name, @options[:ovirtnetwork]) %>
|
||||
<% end -%>
|
||||
<%= system.name %>.vm.provision 'shell', inline: "echo \"auto lo\niface lo inet loopback\n\nauto eth0\niface eth0 inet static\n\taddress <%= resolve_network(selected_module)%>\" > /etc/network/interfaces"
|
||||
<%= system.name %>.vm.provision 'shell', inline: "echo '' > /etc/environment"
|
||||
<% elsif @ovirt_template and @ovirt_template.include? 'debian_desktop_kde' -%>
|
||||
<% if @options.has_key? :ovirtnetwork -%>
|
||||
<%= system.name %>.vm.network :private_network,
|
||||
:ovirt__network_name => <%= get_ovirt_network_name(system.name, @options[:ovirtnetwork]) %>
|
||||
<% end -%>
|
||||
<%= system.name %>.vm.provision 'shell', inline: "echo \"\nauto eth1\niface eth1 inet static\n\taddress <%= resolve_network(selected_module)%>\" >> /etc/network/interfaces"
|
||||
<%= system.name %>.vm.provision 'shell', inline: "echo '' > /etc/environment"
|
||||
<% elsif @ovirt_template and (@ovirt_template.include? 'kali_linux_msf'or @ovirt_template.include? 'debian_stretch_server' or @ovirt_template.include? 'debian_stretch_desktop_kde') -%>
|
||||
|
||||
20
secgen.rb
20
secgen.rb
@@ -80,7 +80,7 @@ def build_config(scenario, out_dir, options)
|
||||
}
|
||||
|
||||
Print.info "Creating project: #{out_dir}..."
|
||||
# create's vagrant file / report a starts the vagrant installation'
|
||||
# creates Vagrantfile and other outputs and starts the vagrant installation
|
||||
creator = ProjectFilesCreator.new(systems, out_dir, scenario, options)
|
||||
creator.write_files
|
||||
|
||||
@@ -177,12 +177,18 @@ def build_vms(project_dir, options)
|
||||
end
|
||||
retry_count -= 1
|
||||
end
|
||||
if successful_creation && options[:snapshot]
|
||||
Print.info 'Creating a snapshot of VM(s)'
|
||||
if OVirtFunctions::provider_ovirt?(options)
|
||||
OVirtFunctions::create_snapshot(options, scenario, get_vm_names(scenario))
|
||||
else
|
||||
GemExec.exe('vagrant', project_dir, 'snapshot push')
|
||||
if successful_creation
|
||||
if options[:snapshot]
|
||||
Print.info 'Creating a snapshot of VM(s)'
|
||||
if OVirtFunctions::provider_ovirt?(options)
|
||||
OVirtFunctions::create_snapshot(options, scenario, get_vm_names(scenario))
|
||||
else
|
||||
GemExec.exe('vagrant', project_dir, 'snapshot push')
|
||||
end
|
||||
end
|
||||
if options[:ovirtnetwork]
|
||||
Print.info 'Assigning network(s) of VM(s)'
|
||||
OVirtFunctions::assign_networks(options, scenario, get_vm_names(scenario))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user