Class: VagrantPlugins::ProviderLibvirt::Action::CreateNetworks
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderLibvirt::Action::CreateNetworks
- Includes:
- Vagrant::Util::NetworkIP, Vagrant::Util::ScopedHashOverride, Util::ErbTemplate, Util::LibvirtUtil
- Defined in:
- lib/vagrant-libvirt/action/create_networks.rb
Overview
Prepare all networks needed for domain connections.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ CreateNetworks
constructor
A new instance of CreateNetworks.
Methods included from Util::LibvirtUtil
Methods included from Util::ErbTemplate
Constructor Details
#initialize(app, env) ⇒ CreateNetworks
Returns a new instance of CreateNetworks.
16 17 18 19 20 21 22 23 |
# File 'lib/vagrant-libvirt/action/create_networks.rb', line 16 def initialize(app, env) @logger = Log4r::Logger.new("vagrant_libvirt::action::create_networks") @app = app @available_networks = [] = {} @libvirt_client = env[:libvirt_compute].client end |
Instance Method Details
#call(env) ⇒ Object
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 83 |
# File 'lib/vagrant-libvirt/action/create_networks.rb', line 25 def call(env) # Iterate over networks requested from config. If some network is not # available, create it if possible. Otherwise raise an error. env[:machine].config.vm.networks.each do |type, | # Get a list of all (active and inactive) libvirt networks. This # list is used throughout this class and should be easier to # process than libvirt API calls. @available_networks = libvirt_networks(env[:libvirt_compute].client) # Now, we support private networks only. There are two other types # public network and port forwarding, but there are problems with # creating them via libvirt API, so this provider doesn't implement # them. next if type != :private_network # Get options for this interface network. Options can be specified # in Vagrantfile in short format (:ip => ...), or provider format # (:libvirt__network_name => ...). = scoped_hash_override(, :libvirt) = { :netmask => '255.255.255.0', :dhcp_enabled => true, :forward_mode => 'nat', }.merge() # Prepare a hash describing network for this specific interface. @interface_network = { :name => nil, :ip_address => nil, :netmask => [:netmask], :network_address => nil, :bridge_name => nil, :created => false, :active => false, :autostart => false, :libvirt_network => nil, } if [:ip] handle_ip_option(env) elsif [:network_name] handle_network_name_option else # TODO Should be smarter than just using fixed 'default' string. @interface_network = lookup_network_by_name('default') if not @interface_network raise Errors::NetworkNotAvailableError, :network_name => 'default' end end autostart_network if not @interface_network[:autostart] activate_network if not @interface_network[:active] end @app.call(env) end |