Class: VagrantPlugins::ProviderLibvirt::Action::CreateNetworks
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderLibvirt::Action::CreateNetworks
- Includes:
- Vagrant::Util::NetworkIP, Vagrant::Util::ScopedHashOverride, Util::ErbTemplate, Util::NetworkUtil
- Defined in:
- lib/vagrant-libvirt/action/create_networks.rb
Overview
Prepare all networks needed for domain connections.
Constant Summary collapse
- @@lock =
Mutex.new
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ CreateNetworks
constructor
A new instance of CreateNetworks.
Methods included from Util::NetworkUtil
#configured_networks, #libvirt_networks
Methods included from Util::ErbTemplate
Constructor Details
#initialize(app, env) ⇒ CreateNetworks
Returns a new instance of CreateNetworks.
19 20 21 22 23 24 25 26 27 |
# File 'lib/vagrant-libvirt/action/create_networks.rb', line 19 def initialize(app, env) mess = 'vagrant_libvirt::action::create_networks' @logger = Log4r::Logger.new(mess) @app = app @available_networks = [] @options = {} @libvirt_client = env[:libvirt_compute].client end |
Instance Method Details
#call(env) ⇒ Object
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 |
# File 'lib/vagrant-libvirt/action/create_networks.rb', line 29 def call(env) # only one vm at a time should try to set up networks # otherwise they'll have inconsitent views of current state # and conduct redundant operations that cause errors @@lock.synchronize do # Iterate over networks If some network is not # available, create it if possible. Otherwise raise an error. configured_networks(env, @logger).each do || # Only need to create private networks next if [:iface_type] != :private_network @logger.debug "Searching for network with options #{}" # should fix other methods so this doesn't have to be instance var @options = # 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) # Prepare a hash describing network for this specific interface. @interface_network = { name: nil, ip_address: nil, netmask: @options[:netmask], network_address: nil, bridge_name: nil, created: false, active: false, autostart: false, libvirt_network: nil, } if @options[:ip] handle_ip_option(env) # in vagrant 1.2.3 and later it is not possible to take this branch # because cannot have name without ip # https://github.com/mitchellh/vagrant/commit/cf2f6da4dbcb4f57c9cdb3b94dcd0bba62c5f5fd elsif @options[:network_name] handle_network_name_option end autostart_network if !@interface_network[:autostart] activate_network if !@interface_network[:active] end end @app.call(env) end |