Class: VagrantPlugins::OVirtProvider::Action::CreateNetworkInterfaces
- Inherits:
-
Object
- Object
- VagrantPlugins::OVirtProvider::Action::CreateNetworkInterfaces
- Defined in:
- lib/vagrant-ovirt/action/create_network_interfaces.rb
Overview
Create network interfaces for machine, before VM is running.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ CreateNetworkInterfaces
constructor
A new instance of CreateNetworkInterfaces.
Constructor Details
#initialize(app, env) ⇒ CreateNetworkInterfaces
Returns a new instance of CreateNetworkInterfaces.
9 10 11 12 |
# File 'lib/vagrant-ovirt/action/create_network_interfaces.rb', line 9 def initialize(app, env) @logger = Log4r::Logger.new("vagrant_ovirt::action::create_network_interfaces") @app = app end |
Instance Method Details
#call(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/vagrant-ovirt/action/create_network_interfaces.rb', line 14 def call(env) # Get machine first. begin machine = OVirtProvider::Util::Collection.find_matching( env[:ovirt_compute].servers.all, env[:machine].id.to_s) rescue => e raise Errors::NoVMError, :vm_name => env[:machine].id.to_s end # Setup list of interfaces before creating them adapters = [] # First interface is for provisioning, so this slot is not usable. # This interface should be available already from template. adapters[0] = :reserved env[:machine].config.vm.networks.each do |type, | # Other types than bridged are not supported for now. next if type != :bridged network_name = 'rhevm' network_name = [:bridge] if [:bridge] if [:adapter] if adapters[[:adapter]] raise Errors::InterfaceSlotNotAvailable end adapters[[:adapter].to_i] = network_name else empty_slot = find_empty(adapters, start=1) raise Errors::InterfaceSlotNotAvailable if empty_slot == nil adapters[empty_slot] = network_name end end # Create each interface as new domain device adapters.each_with_index do |network_name, slot_number| next if network_name == :reserved iface_number = slot_number + 1 # Get network id network = OVirtProvider::Util::Collection.find_matching( env[:ovirt_client].networks(:cluster => env[:ovirt_cluster].id), network_name) if network == nil raise Errors::NoNetworkError, :network_name => network_name end @logger.info("Creating network interface nic#{iface_number}") begin machine.add_interface( :name => "nic#{iface_number}", :network => network.id, # TODO This should be configurable in Vagrantfile. :interface => 'virtio', ) rescue => e raise Errors::AddInterfaceError, :error_message => e. end end @app.call(env) end |