vagrant-libvirt 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a7de8bcfdcab60b3237c7d64fd047fa9b43bbf8
4
- data.tar.gz: f98b1b521b2d6665be337341791ae260244d29eb
3
+ metadata.gz: 693a19302ccb1cda6b30a7be5b5d9b8c5e74b5e3
4
+ data.tar.gz: 951b697e48245021c9cec5d8e392a44d7d0881ec
5
5
  SHA512:
6
- metadata.gz: 6d33e5ae966f1758ec327b73a9d3527cfa0b6c3ab461630beb4e13bc391c5f291ab04b48884bc0d568e2376ee3fda1361bce6efab0d3d5513b987f08f7b75513
7
- data.tar.gz: 83408a1dcb5c55fd745e204b7d23f78cf1ec9d6e6eb5beb8a27f31cbff4154a916bd9068b7e80dade9318f97b504a77671171486ce954e65b9af73474487e151
6
+ metadata.gz: 8d82a8e8257f289130dfc2fc84388adbaff56803012d5a8fdfd6b12395bb100102aa452c75fb98ce1579af2ba0b961d794fe6149e02ed67e8870384ff8c5b402
7
+ data.tar.gz: 21f86a6f84414e3aeb92e801d5114bec30c5c0cac4a391c28142c73468c0825ae620ba527424a1fffac4970f8a75e7abe6119954c60180aef165dfc4baad8e89
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Vagrant Libvirt Provider
2
2
 
3
- This is a [Vagrant](http://www.vagrantup.com) 1.3+ plugin that adds an
3
+ This is a [Vagrant](http://www.vagrantup.com) 1.4.3+ plugin that adds an
4
4
  [Libvirt](http://libvirt.org) provider to Vagrant, allowing Vagrant to
5
5
  control and provision machines via Libvirt toolkit.
6
6
 
7
- **Note:** Actual version (0.0.13) is still a development one. Feedback is
7
+ **Note:** Actual version (0.0.15) is still a development one. Feedback is
8
8
  welcome and can help a lot :-)
9
9
 
10
10
  ## Features (Version 0.0.13)
@@ -29,7 +29,7 @@ welcome and can help a lot :-)
29
29
 
30
30
  ## Installation
31
31
 
32
- Install using standard [Vagrant 1.3+](http://downloads.vagrantup.com) plugin installation methods. After
32
+ Install using standard [Vagrant 1.4.3+](http://downloads.vagrantup.com) plugin installation methods. After
33
33
  installing, `vagrant up` and specify the `libvirt` provider. An example is shown below.
34
34
 
35
35
  ```
@@ -162,7 +162,7 @@ Vagrant goes through steps below when creating new project:
162
162
  ## Networks
163
163
 
164
164
  Networking features in the form of `config.vm.network` support private networks
165
- concept. Port Forwarding is currently not supported.
165
+ concept.
166
166
 
167
167
  Public Network interfaces are currently implemented using the macvtap driver. The macvtap
168
168
  driver is only available with the Linux Kernel version >= 2.6.24. See the following libvirt
@@ -271,6 +271,12 @@ Configurable ssh parameters in Vagrantfile after provider version 0.0.5 are:
271
271
  * `config.ssh.forward_agent` - Default is false.
272
272
  * `config.ssh.forward_x11` - Default is false.
273
273
 
274
+ ## Forwarded Ports
275
+
276
+ vagrant-libvirt supports Forwarded Ports via ssh port forwarding. For each
277
+ `forwarded_port` directive you specify in your Vagrantfile, vagrant-libvirt
278
+ will maintain an active ssh process for the lifetime of the VM.
279
+
274
280
  ## Synced Folders
275
281
 
276
282
  There is minimal support for synced folders. Upon `vagrant up`, the Libvirt
@@ -1,10 +1,12 @@
1
1
  require 'vagrant/action/builder'
2
+ require 'log4r'
2
3
 
3
4
  module VagrantPlugins
4
5
  module ProviderLibvirt
5
6
  module Action
6
7
  # Include the built-in modules so we can use them as top-level things.
7
8
  include Vagrant::Action::Builtin
9
+ @logger = Log4r::Logger.new('vagrant_libvirt::action')
8
10
 
9
11
  # This action is called to bring the box up from nothing.
10
12
  def self.action_up
@@ -25,18 +27,22 @@ module VagrantPlugins
25
27
  b2.use CreateNetworks
26
28
  b2.use CreateNetworkInterfaces
27
29
 
30
+ b2.use StartDomain
31
+ b2.use WaitTillUp
32
+
28
33
  if Vagrant::VERSION < "1.4.0"
29
34
  b2.use NFS
30
35
  else
36
+ b2.use PrepareNFSValidIds
31
37
  b2.use SyncedFolderCleanup
32
38
  b2.use SyncedFolders
33
39
  end
34
40
 
41
+ b2.use ForwardPorts
42
+
35
43
  b2.use PrepareNFSSettings
36
44
  b2.use ShareFolders
37
45
  b2.use SetHostname
38
- b2.use StartDomain
39
- b2.use WaitTillUp
40
46
  b2.use SyncFolders
41
47
  else
42
48
  b2.use action_start
@@ -68,22 +74,26 @@ module VagrantPlugins
68
74
  # Ensure networks are created and active
69
75
  b3.use CreateNetworks
70
76
 
77
+ # Start it..
78
+ b3.use StartDomain
79
+
80
+ # Machine should gain IP address when comming up,
81
+ # so wait for dhcp lease and store IP into machines data_dir.
82
+ b3.use WaitTillUp
83
+
71
84
  # Handle shared folders
72
85
  if Vagrant::VERSION < "1.4.0"
73
86
  b3.use NFS
74
87
  else
88
+ b3.use PrepareNFSValidIds
75
89
  b3.use SyncedFolderCleanup
76
90
  b3.use SyncedFolders
77
91
  end
92
+
93
+ b3.use ForwardPorts
78
94
  b3.use PrepareNFSSettings
79
95
  b3.use ShareFolders
80
96
 
81
- # Start it..
82
- b3.use StartDomain
83
-
84
- # Machine should gain IP address when comming up,
85
- # so wait for dhcp lease and store IP into machines data_dir.
86
- b3.use WaitTillUp
87
97
  end
88
98
  end
89
99
  end
@@ -95,6 +105,7 @@ module VagrantPlugins
95
105
  Vagrant::Action::Builder.new.tap do |b|
96
106
  b.use ConfigValidate
97
107
  b.use ConnectLibvirt
108
+ b.use ClearForwardedPorts
98
109
  b.use Call, IsCreated do |env, b2|
99
110
  if !env[:result]
100
111
  b2.use MessageNotCreated
@@ -144,6 +155,7 @@ module VagrantPlugins
144
155
  end
145
156
 
146
157
  b2.use ConnectLibvirt
158
+ b2.use ClearForwardedPorts
147
159
  b2.use PruneNFSExports
148
160
  b2.use DestroyDomain
149
161
  b2.use DestroyNetworks
@@ -297,6 +309,8 @@ module VagrantPlugins
297
309
  autoload :CreateNetworks, action_root.join('create_networks')
298
310
  autoload :DestroyDomain, action_root.join('destroy_domain')
299
311
  autoload :DestroyNetworks, action_root.join('destroy_networks')
312
+ autoload :ForwardPorts, action_root.join('forward_ports')
313
+ autoload :ClearForwardedPorts, action_root.join('forward_ports')
300
314
  autoload :HaltDomain, action_root.join('halt_domain')
301
315
  autoload :HandleBoxImage, action_root.join('handle_box_image')
302
316
  autoload :HandleStoragePool, action_root.join('handle_storage_pool')
@@ -308,6 +322,7 @@ module VagrantPlugins
308
322
  autoload :MessageNotRunning, action_root.join('message_not_running')
309
323
  autoload :MessageNotSuspended, action_root.join('message_not_suspended')
310
324
  autoload :PrepareNFSSettings, action_root.join('prepare_nfs_settings')
325
+ autoload :PrepareNFSValidIds, action_root.join('prepare_nfs_valid_ids')
311
326
  autoload :PruneNFSExports, action_root.join('prune_nfs_exports')
312
327
  autoload :ReadSSHInfo, action_root.join('read_ssh_info')
313
328
  autoload :ReadState, action_root.join('read_state')
@@ -10,7 +10,7 @@ module VagrantPlugins
10
10
  # Networks for connecting those interfaces should be already prepared.
11
11
  class CreateNetworkInterfaces
12
12
  include VagrantPlugins::ProviderLibvirt::Util::ErbTemplate
13
- include VagrantPlugins::ProviderLibvirt::Util::LibvirtUtil
13
+ include VagrantPlugins::ProviderLibvirt::Util::NetworkUtil
14
14
  include Vagrant::Util::NetworkIP
15
15
  include Vagrant::Util::ScopedHashOverride
16
16
 
@@ -36,14 +36,10 @@ module VagrantPlugins
36
36
  # Vagrant gives you adapter 0 by default
37
37
 
38
38
  # Assign interfaces to slots.
39
- env[:machine].config.vm.networks.each do |type, options|
40
- @logger.debug "In config found network type #{type} options #{options}"
39
+ configured_networks(env, @logger).each do |options|
41
40
 
42
- # Get options for this interface. Options can be specified in
43
- # Vagrantfile in short format (:ip => ...), or provider format
44
- # (:libvirt__network_name => ...).
45
- options = scoped_hash_override(options, :libvirt)
46
- options = { :netmask => '255.255.255.0', :iface_type => type }.merge(options)
41
+ # dont need to create interface for this type
42
+ next if options[:iface_type] == :forwarded_port
47
43
 
48
44
  # TODO fill first ifaces with adapter option specified.
49
45
  if options[:adapter]
@@ -103,9 +99,9 @@ module VagrantPlugins
103
99
  networks_to_configure = []
104
100
 
105
101
  adapters.each_with_index do |options, slot_number|
106
- # Skip configuring first interface. It's used for provisioning and
107
- # it has to be available during provisioning - ifdown command is
108
- # not acceptable here.
102
+ # Skip configuring the management network, which is on the first interface.
103
+ # It's used for provisioning and it has to be available during provisioning,
104
+ # ifdown command is not acceptable here.
109
105
  next if slot_number == 0
110
106
  @logger.debug "Configuring interface slot_number #{slot_number} options #{options}"
111
107
 
@@ -161,13 +157,7 @@ module VagrantPlugins
161
157
  end
162
158
  end
163
159
 
164
- # the management network always gets attached to slot 0
165
- # because the first network is of type forwarded_port.
166
- # this is confusing.
167
- # TODO only iterate over networks of type private_network
168
- # and prepend the management network to that list
169
- @logger.debug "Did not find network so using default of #{@management_network_name}"
170
- @management_network_name
160
+ raise NetworkNotAvailableError, network_name: options[:ip]
171
161
  end
172
162
  end
173
163
  end
@@ -12,7 +12,7 @@ module VagrantPlugins
12
12
  include Vagrant::Util::NetworkIP
13
13
  include Vagrant::Util::ScopedHashOverride
14
14
  include VagrantPlugins::ProviderLibvirt::Util::ErbTemplate
15
- include VagrantPlugins::ProviderLibvirt::Util::LibvirtUtil
15
+ include VagrantPlugins::ProviderLibvirt::Util::NetworkUtil
16
16
 
17
17
  @@lock = Mutex.new
18
18
 
@@ -27,63 +27,15 @@ module VagrantPlugins
27
27
  end
28
28
 
29
29
  def call(env)
30
-
31
- management_network_name = env[:machine].provider_config.management_network_name
32
- management_network_address = env[:machine].provider_config.management_network_address
33
- @logger.info "Using #{management_network_name} at #{management_network_address} as the management network"
34
-
35
- begin
36
- management_network_ip = IPAddr.new(management_network_address)
37
- rescue ArgumentError
38
- raise Errors::ManagementNetworkError,
39
- error_message: "#{management_network_address} is not a valid IP address"
40
- end
41
-
42
- # capture address into $1 and mask into $2
43
- management_network_ip.inspect =~ /IPv4:(.*)\/(.*)>/
44
-
45
- if $2 == '255.255.255.255'
46
- raise Errors::ManagementNetworkError,
47
- error_message: "#{management_network_address} does not include both an address and subnet mask"
48
- end
49
-
50
- management_network_options = {
51
- network_name: management_network_name,
52
- ip: $1,
53
- netmask: $2,
54
- dhcp_enabled: true,
55
- forward_mode: 'nat',
56
- }
57
-
58
- # add management network to list of networks to check
59
- networks = [ management_network_options ]
60
-
61
- env[:machine].config.vm.networks.each do |type, original_options|
62
- # There are two other types public network and port forwarding,
63
- # but there are problems with creating them via libvirt API,
64
- # so this provider doesn't implement them.
65
- next if type != :private_network
66
- # Options can be specified in Vagrantfile in short format (:ip => ...),
67
- # or provider format # (:libvirt__network_name => ...).
68
- # https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/util/scoped_hash_override.rb
69
- options = scoped_hash_override(original_options, :libvirt)
70
- # use default values if not already set
71
- options = {
72
- netmask: '255.255.255.0',
73
- dhcp_enabled: true,
74
- forward_mode: 'nat',
75
- }.merge(options)
76
- # add to list of networks to check
77
- networks.push(options)
78
- end
79
-
80
30
  # only one vm at a time should try to set up networks
81
31
  # otherwise they'll have inconsitent views of current state
82
32
  # and conduct redundant operations that cause errors
83
33
  @@lock.synchronize do
84
34
  # Iterate over networks If some network is not
85
35
  # available, create it if possible. Otherwise raise an error.
86
- networks.each do |options|
36
+ configured_networks(env, @logger).each do |options|
37
+ # Only need to create private networks
38
+ next if options[:iface_type] != :private_network
87
39
  @logger.debug "Searching for network with options #{options}"
88
40
 
89
41
  # should fix other methods so this doesn't have to be instance var
@@ -0,0 +1,164 @@
1
+ module VagrantPlugins
2
+ module ProviderLibvirt
3
+ module Action
4
+ # Adds support for vagrant's `forward_ports` configuration directive.
5
+ class ForwardPorts
6
+ def initialize(app, env)
7
+ @app = app
8
+ @logger = Log4r::Logger.new('vagrant_libvirt::action::forward_ports')
9
+ end
10
+
11
+ def call(env)
12
+ @env = env
13
+
14
+ # Get the ports we're forwarding
15
+ env[:forwarded_ports] = compile_forwarded_ports(env[:machine].config)
16
+
17
+ # Warn if we're port forwarding to any privileged ports
18
+ env[:forwarded_ports].each do |fp|
19
+ if fp[:host] <= 1024
20
+ env[:ui].warn I18n.t(
21
+ 'vagrant.actions.vm.forward_ports.privileged_ports'
22
+ )
23
+ break
24
+ end
25
+ end
26
+
27
+ # Continue, we need the VM to be booted in order to grab its IP
28
+ @app.call env
29
+
30
+ if @env[:forwarded_ports].any?
31
+ env[:ui].info I18n.t('vagrant.actions.vm.forward_ports.forwarding')
32
+ forward_ports
33
+ end
34
+ end
35
+
36
+ def forward_ports
37
+ @env[:forwarded_ports].each do |fp|
38
+ message_attributes = {
39
+ adapter: 'eth0',
40
+ guest_port: fp[:guest],
41
+ host_port: fp[:host]
42
+ }
43
+
44
+ @env[:ui].info(I18n.t(
45
+ 'vagrant.actions.vm.forward_ports.forwarding_entry',
46
+ message_attributes
47
+ ))
48
+
49
+ ssh_pid = redirect_port(
50
+ @env[:machine].name,
51
+ fp[:host_ip] || '0.0.0.0',
52
+ fp[:host],
53
+ fp[:guest_ip] || @env[:machine].provider.ssh_info[:host],
54
+ fp[:guest]
55
+ )
56
+ store_ssh_pid(fp[:host], ssh_pid)
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def compile_forwarded_ports(config)
63
+ mappings = {}
64
+
65
+ config.vm.networks.each do |type, options|
66
+ next if options[:disabled]
67
+
68
+ if type == :forwarded_port && options[:id] != 'ssh'
69
+ if options.fetch(:host_ip, '').to_s.strip.empty?
70
+ options.delete(:host_ip)
71
+ end
72
+ mappings[options[:host]] = options
73
+ end
74
+ end
75
+
76
+ mappings.values
77
+ end
78
+
79
+ def redirect_port(machine, host_ip, host_port, guest_ip, guest_port)
80
+ params = %W(
81
+ #{machine}
82
+ -L #{host_ip}:#{host_port}:#{guest_ip}:#{guest_port}
83
+ -N
84
+ ).join(' ')
85
+ # TODO get options without shelling out
86
+ options = `vagrant ssh-config #{machine} | awk '{printf " -o "$1"="$2}'`
87
+ ssh_cmd = "ssh #{options} #{params}"
88
+
89
+ @logger.debug "Forwarding port with `#{ssh_cmd}`"
90
+ spawn(ssh_cmd, [:out, :err] => '/dev/null')
91
+ end
92
+
93
+ def store_ssh_pid(host_port, ssh_pid)
94
+ data_dir = @env[:machine].data_dir.join('pids')
95
+ data_dir.mkdir unless data_dir.directory?
96
+
97
+ data_dir.join("ssh_#{host_port}.pid").open('w') do |pid_file|
98
+ pid_file.write(ssh_pid)
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ module VagrantPlugins
107
+ module ProviderLibvirt
108
+ module Action
109
+ # Cleans up ssh-forwarded ports on VM halt/destroy.
110
+ class ClearForwardedPorts
111
+ def initialize(app, env)
112
+ @app = app
113
+ @logger = Log4r::Logger.new(
114
+ 'vagrant_libvirt::action::clear_forward_ports'
115
+ )
116
+ end
117
+
118
+ def call(env)
119
+ @env = env
120
+
121
+ if ssh_pids.any?
122
+ env[:ui].info I18n.t(
123
+ 'vagrant.actions.vm.clear_forward_ports.deleting'
124
+ )
125
+ ssh_pids.each do |pid|
126
+ next unless ssh_pid?(pid)
127
+ @logger.debug "Killing pid #{pid}"
128
+ system "kill #{pid}"
129
+ end
130
+
131
+ @logger.info 'Removing ssh pid files'
132
+ remove_ssh_pids
133
+ else
134
+ @logger.info 'No ssh pids found'
135
+ end
136
+
137
+ @app.call env
138
+ end
139
+
140
+ protected
141
+
142
+ def ssh_pids
143
+ glob = @env[:machine].data_dir.join('pids').to_s + '/ssh_*.pid'
144
+ @ssh_pids = Dir[glob].map do |file|
145
+ File.read(file).strip.chomp
146
+ end
147
+ end
148
+
149
+ def ssh_pid?(pid)
150
+ @logger.debug 'Checking if #{pid} is an ssh process '\
151
+ 'with `ps -o cmd= #{pid}`'
152
+ `ps -o cmd= #{pid}`.strip.chomp =~ /ssh/
153
+ end
154
+
155
+ def remove_ssh_pids
156
+ glob = @env[:machine].data_dir.join('pids').to_s + '/ssh_*.pid'
157
+ Dir[glob].each do |file|
158
+ File.delete file
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end
164
+ end
@@ -3,31 +3,35 @@ module VagrantPlugins
3
3
  module ProviderLibvirt
4
4
  module Action
5
5
  class PrepareNFSSettings
6
+ include Vagrant::Action::Builtin::MixinSyncedFolders
7
+
6
8
  def initialize(app,env)
7
9
  @app = app
8
10
  @logger = Log4r::Logger.new("vagrant::action::vm::nfs")
9
11
  end
10
12
 
11
13
  def call(env)
14
+ @machine = env[:machine]
12
15
  @app.call(env)
13
16
 
14
- using_nfs = false
15
- env[:machine].config.vm.synced_folders.each do |id, opts|
16
- if opts[:nfs]
17
- using_nfs = true
18
- break
19
- end
20
- end
21
-
22
- if using_nfs
17
+ if using_nfs?
23
18
  @logger.info("Using NFS, preparing NFS settings by reading host IP and machine IP")
24
19
  env[:nfs_host_ip] = read_host_ip(env[:machine],env)
25
20
  env[:nfs_machine_ip] = env[:machine].ssh_info[:host]
26
21
 
27
- raise Vagrant::Errors::NFSNoHostonlyNetwork if !env[:nfs_machine_ip]
22
+ @logger.info("host IP: #{env[:nfs_host_ip]} machine IP: #{env[:nfs_machine_ip]}")
23
+
24
+ raise Vagrant::Errors::NFSNoHostonlyNetwork if !env[:nfs_machine_ip] || !env[:nfs_host_ip]
28
25
  end
29
26
  end
30
27
 
28
+ # We're using NFS if we have any synced folder with NFS configured. If
29
+ # we are not using NFS we don't need to do the extra work to
30
+ # populate these fields in the environment.
31
+ def using_nfs?
32
+ !!synced_folders(@machine)[:nfs]
33
+ end
34
+
31
35
  # Returns the IP address of the first host only network adapter
32
36
  #
33
37
  # @param [Machine] machine
@@ -0,0 +1,17 @@
1
+ module VagrantPlugins
2
+ module ProviderLibvirt
3
+ module Action
4
+ class PrepareNFSValidIds
5
+ def initialize(app, env)
6
+ @app = app
7
+ @logger = Log4r::Logger.new("vagrant::action::vm::nfs")
8
+ end
9
+
10
+ def call(env)
11
+ env[:nfs_valid_ids] = env[:libvirt_compute].servers.all.map(&:id)
12
+ @app.call(env)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -26,10 +26,7 @@ module VagrantPlugins
26
26
  {}.tap do |result|
27
27
  @env[:machine].config.vm.synced_folders.each do |id, data|
28
28
  # Ignore NFS shared folders
29
- next if !data[:nfs]
30
-
31
- # convert to NFS share
32
- #data[:nfs] = true
29
+ next if !data[:type] == :nfs
33
30
 
34
31
  # This to prevent overwriting the actual shared folders data
35
32
  result[id] = data.dup
@@ -18,7 +18,7 @@ module VagrantPlugins
18
18
  ssh_info = env[:machine].ssh_info
19
19
 
20
20
  env[:machine].config.vm.synced_folders.each do |id, data|
21
- next if data[:nfs]
21
+ next if data[:type] == :nfs
22
22
  proxycommand = "-o ProxyCommand='#{ssh_info[:proxy_command]}'" if ssh_info[:proxy_command]
23
23
  hostpath = File.expand_path(data[:hostpath], env[:root_path])
24
24
  guestpath = data[:guestpath]
@@ -1,4 +1,4 @@
1
- require "vagrant-libvirt/util/timer"
1
+ require 'vagrant-libvirt/util/timer'
2
2
 
3
3
  module VagrantPlugins
4
4
  module ProviderLibvirt
@@ -6,17 +6,14 @@ module VagrantPlugins
6
6
  # This is the same as the builtin provision except it times the
7
7
  # provisioner runs.
8
8
  class TimedProvision < Vagrant::Action::Builtin::Provision
9
- def run_provisioner(env, name, p)
10
- env[:ui].info(I18n.t("vagrant.actions.vm.provision.beginning",
11
- :provisioner => name))
12
-
9
+ def run_provisioner(env)
13
10
  timer = Util::Timer.time do
14
11
  super
15
12
  end
16
13
 
17
14
  env[:metrics] ||= {}
18
- env[:metrics]["provisioner_times"] ||= []
19
- env[:metrics]["provisioner_times"] << [p.class.to_s, timer]
15
+ env[:metrics]['provisioner_times'] ||= []
16
+ env[:metrics]['provisioner_times'] << [env[:provisioner].class.to_s, timer]
20
17
  end
21
18
  end
22
19
  end
@@ -4,7 +4,7 @@ module VagrantPlugins
4
4
  autoload :ErbTemplate, 'vagrant-libvirt/util/erb_template'
5
5
  autoload :Collection, 'vagrant-libvirt/util/collection'
6
6
  autoload :Timer, 'vagrant-libvirt/util/timer'
7
- autoload :LibvirtUtil, 'vagrant-libvirt/util/libvirt_util'
7
+ autoload :NetworkUtil, 'vagrant-libvirt/util/network_util'
8
8
  end
9
9
  end
10
10
  end
@@ -0,0 +1,117 @@
1
+ require 'nokogiri'
2
+ require 'vagrant/util/network_ip'
3
+
4
+ module VagrantPlugins
5
+ module ProviderLibvirt
6
+ module Util
7
+ module NetworkUtil
8
+ include Vagrant::Util::NetworkIP
9
+
10
+ def configured_networks(env, logger)
11
+ management_network_name = env[:machine].provider_config.management_network_name
12
+ management_network_address = env[:machine].provider_config.management_network_address
13
+ logger.info "Using #{management_network_name} at #{management_network_address} as the management network"
14
+
15
+ begin
16
+ management_network_ip = IPAddr.new(management_network_address)
17
+ rescue ArgumentError
18
+ raise Errors::ManagementNetworkError,
19
+ error_message: "#{management_network_address} is not a valid IP address"
20
+ end
21
+
22
+ # capture address into $1 and mask into $2
23
+ management_network_ip.inspect =~ /IPv4:(.*)\/(.*)>/
24
+
25
+ if $2 == '255.255.255.255'
26
+ raise Errors::ManagementNetworkError,
27
+ error_message: "#{management_network_address} does not include both an address and subnet mask"
28
+ end
29
+
30
+ management_network_options = {
31
+ iface_type: :private_network,
32
+ network_name: management_network_name,
33
+ ip: $1,
34
+ netmask: $2,
35
+ dhcp_enabled: true,
36
+ forward_mode: 'nat',
37
+ }
38
+
39
+ # add management network to list of networks to check
40
+ networks = [ management_network_options ]
41
+
42
+ env[:machine].config.vm.networks.each do |type, original_options|
43
+ logger.debug "In config found network type #{type} options #{original_options}"
44
+ # Options can be specified in Vagrantfile in short format (:ip => ...),
45
+ # or provider format # (:libvirt__network_name => ...).
46
+ # https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/util/scoped_hash_override.rb
47
+ options = scoped_hash_override(original_options, :libvirt)
48
+ # store type in options
49
+ # use default values if not already set
50
+ options = {
51
+ iface_type: type,
52
+ netmask: '255.255.255.0',
53
+ dhcp_enabled: true,
54
+ forward_mode: 'nat',
55
+ }.merge(options)
56
+ # add to list of networks to check
57
+ networks.push(options)
58
+ end
59
+
60
+ return networks
61
+ end
62
+
63
+ # Return a list of all (active and inactive) libvirt networks as a list
64
+ # of hashes with their name, network address and status (active or not)
65
+ def libvirt_networks(libvirt_client)
66
+ libvirt_networks = []
67
+
68
+ active = libvirt_client.list_networks
69
+ inactive = libvirt_client.list_defined_networks
70
+
71
+ # Iterate over all (active and inactive) networks.
72
+ active.concat(inactive).each do |network_name|
73
+ libvirt_network = libvirt_client.lookup_network_by_name(
74
+ network_name)
75
+
76
+ # Parse ip address and netmask from the network xml description.
77
+ xml = Nokogiri::XML(libvirt_network.xml_desc)
78
+ ip = xml.xpath('/network/ip/@address').first
79
+ ip = ip.value if ip
80
+ netmask = xml.xpath('/network/ip/@netmask').first
81
+ netmask = netmask.value if netmask
82
+
83
+ if xml.at_xpath('//network/ip/dhcp')
84
+ dhcp_enabled = true
85
+ else
86
+ dhcp_enabled = false
87
+ end
88
+
89
+ # Calculate network address of network from ip address and
90
+ # netmask.
91
+ if ip && netmask
92
+ network_address = network_address(ip, netmask)
93
+ else
94
+ network_address = nil
95
+ end
96
+
97
+ libvirt_networks << {
98
+ name: network_name,
99
+ ip_address: ip,
100
+ netmask: netmask,
101
+ network_address: network_address,
102
+ dhcp_enabled: dhcp_enabled,
103
+ bridge_name: libvirt_network.bridge_name,
104
+ created: true,
105
+ active: libvirt_network.active?,
106
+ autostart: libvirt_network.autostart?,
107
+ libvirt_network: libvirt_network
108
+ }
109
+ end
110
+
111
+ libvirt_networks
112
+ end
113
+
114
+ end
115
+ end
116
+ end
117
+ end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module ProviderLibvirt
3
- VERSION = '0.0.14'
3
+ VERSION = '0.0.15'
4
4
  end
5
5
  end
@@ -2,12 +2,12 @@
2
2
  require File.expand_path('../lib/vagrant-libvirt/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ['Lukas Stanek','Dima Vasilets']
6
- gem.email = ['ls@elostech.cz','pronix.service@gmail.com']
5
+ gem.authors = ['Lukas Stanek','Dima Vasilets','Brian Pitts']
6
+ gem.email = ['ls@elostech.cz','pronix.service@gmail.com','brian@polibyte.com']
7
7
  gem.license = 'MIT'
8
8
  gem.description = %q{Vagrant provider for libvirt.}
9
9
  gem.summary = %q{Vagrant provider for libvirt.}
10
- gem.homepage = "https://github.com/pradels/vagrant-libvirt"
10
+ gem.homepage = 'https://github.com/pradels/vagrant-libvirt'
11
11
 
12
12
  gem.files = `git ls-files`.split($\)
13
13
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -16,9 +16,9 @@ Gem::Specification.new do |gem|
16
16
  gem.require_paths = ['lib']
17
17
  gem.version = VagrantPlugins::ProviderLibvirt::VERSION
18
18
 
19
- gem.add_runtime_dependency 'fog', '1.15.0'
19
+ gem.add_runtime_dependency 'fog', '~> 1.15'
20
20
  gem.add_runtime_dependency 'ruby-libvirt', '~> 0.4.0'
21
- gem.add_runtime_dependency 'nokogiri', '1.5.10'
21
+ gem.add_runtime_dependency 'nokogiri', '~> 1.5.9'
22
22
 
23
23
  gem.add_development_dependency 'rake'
24
24
  end
metadata CHANGED
@@ -1,30 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-libvirt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Stanek
8
8
  - Dima Vasilets
9
+ - Brian Pitts
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2014-01-21 00:00:00.000000000 Z
13
+ date: 2014-02-01 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: fog
16
17
  requirement: !ruby/object:Gem::Requirement
17
18
  requirements:
18
- - - '='
19
+ - - "~>"
19
20
  - !ruby/object:Gem::Version
20
- version: 1.15.0
21
+ version: '1.15'
21
22
  type: :runtime
22
23
  prerelease: false
23
24
  version_requirements: !ruby/object:Gem::Requirement
24
25
  requirements:
25
- - - '='
26
+ - - "~>"
26
27
  - !ruby/object:Gem::Version
27
- version: 1.15.0
28
+ version: '1.15'
28
29
  - !ruby/object:Gem::Dependency
29
30
  name: ruby-libvirt
30
31
  requirement: !ruby/object:Gem::Requirement
@@ -43,16 +44,16 @@ dependencies:
43
44
  name: nokogiri
44
45
  requirement: !ruby/object:Gem::Requirement
45
46
  requirements:
46
- - - '='
47
+ - - "~>"
47
48
  - !ruby/object:Gem::Version
48
- version: 1.5.10
49
+ version: 1.5.9
49
50
  type: :runtime
50
51
  prerelease: false
51
52
  version_requirements: !ruby/object:Gem::Requirement
52
53
  requirements:
53
- - - '='
54
+ - - "~>"
54
55
  - !ruby/object:Gem::Version
55
- version: 1.5.10
56
+ version: 1.5.9
56
57
  - !ruby/object:Gem::Dependency
57
58
  name: rake
58
59
  requirement: !ruby/object:Gem::Requirement
@@ -71,6 +72,7 @@ description: Vagrant provider for libvirt.
71
72
  email:
72
73
  - ls@elostech.cz
73
74
  - pronix.service@gmail.com
75
+ - brian@polibyte.com
74
76
  executables: []
75
77
  extensions: []
76
78
  extra_rdoc_files: []
@@ -93,6 +95,7 @@ files:
93
95
  - lib/vagrant-libvirt/action/create_networks.rb
94
96
  - lib/vagrant-libvirt/action/destroy_domain.rb
95
97
  - lib/vagrant-libvirt/action/destroy_networks.rb
98
+ - lib/vagrant-libvirt/action/forward_ports.rb
96
99
  - lib/vagrant-libvirt/action/halt_domain.rb
97
100
  - lib/vagrant-libvirt/action/handle_box_image.rb
98
101
  - lib/vagrant-libvirt/action/handle_storage_pool.rb
@@ -104,6 +107,7 @@ files:
104
107
  - lib/vagrant-libvirt/action/message_not_running.rb
105
108
  - lib/vagrant-libvirt/action/message_not_suspended.rb
106
109
  - lib/vagrant-libvirt/action/prepare_nfs_settings.rb
110
+ - lib/vagrant-libvirt/action/prepare_nfs_valid_ids.rb
107
111
  - lib/vagrant-libvirt/action/prune_nfs_exports.rb
108
112
  - lib/vagrant-libvirt/action/read_ssh_info.rb
109
113
  - lib/vagrant-libvirt/action/read_state.rb
@@ -128,7 +132,7 @@ files:
128
132
  - lib/vagrant-libvirt/util.rb
129
133
  - lib/vagrant-libvirt/util/collection.rb
130
134
  - lib/vagrant-libvirt/util/erb_template.rb
131
- - lib/vagrant-libvirt/util/libvirt_util.rb
135
+ - lib/vagrant-libvirt/util/network_util.rb
132
136
  - lib/vagrant-libvirt/util/timer.rb
133
137
  - lib/vagrant-libvirt/version.rb
134
138
  - locales/en.yml
@@ -1,64 +0,0 @@
1
- require 'nokogiri'
2
- require 'vagrant/util/network_ip'
3
-
4
- module VagrantPlugins
5
- module ProviderLibvirt
6
- module Util
7
- module LibvirtUtil
8
- include Vagrant::Util::NetworkIP
9
-
10
- # Return a list of all (active and inactive) libvirt networks as a list
11
- # of hashes with their name, network address and status (active or not)
12
- def libvirt_networks(libvirt_client)
13
- libvirt_networks = []
14
-
15
- active = libvirt_client.list_networks
16
- inactive = libvirt_client.list_defined_networks
17
-
18
- # Iterate over all (active and inactive) networks.
19
- active.concat(inactive).each do |network_name|
20
- libvirt_network = libvirt_client.lookup_network_by_name(
21
- network_name)
22
-
23
- # Parse ip address and netmask from the network xml description.
24
- xml = Nokogiri::XML(libvirt_network.xml_desc)
25
- ip = xml.xpath('/network/ip/@address').first
26
- ip = ip.value if ip
27
- netmask = xml.xpath('/network/ip/@netmask').first
28
- netmask = netmask.value if netmask
29
-
30
- if xml.at_xpath('//network/ip/dhcp')
31
- dhcp_enabled = true
32
- else
33
- dhcp_enabled = false
34
- end
35
-
36
- # Calculate network address of network from ip address and
37
- # netmask.
38
- if ip && netmask
39
- network_address = network_address(ip, netmask)
40
- else
41
- network_address = nil
42
- end
43
-
44
- libvirt_networks << {
45
- name: network_name,
46
- ip_address: ip,
47
- netmask: netmask,
48
- network_address: network_address,
49
- dhcp_enabled: dhcp_enabled,
50
- bridge_name: libvirt_network.bridge_name,
51
- created: true,
52
- active: libvirt_network.active?,
53
- autostart: libvirt_network.autostart?,
54
- libvirt_network: libvirt_network
55
- }
56
- end
57
-
58
- libvirt_networks
59
- end
60
-
61
- end
62
- end
63
- end
64
- end