nise-bosh-vagrant 0.4.3 → 0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,6 @@
2
2
  $:.push File.dirname(__FILE__) + '/../lib'
3
3
 
4
4
  require "rubygems"
5
- require "nise-bosh-vagrant/cli"
5
+ require "nise-bosh-vagrant"
6
6
 
7
- NiseBOSHVagrant::CLI.start
7
+ NiseBOSHVagrant::CLI.start
@@ -1,5 +1,7 @@
1
1
  require 'nise-bosh-vagrant/version'
2
2
 
3
- require 'nise-bosh-vagrant/runer'
3
+ require 'nise-bosh-vagrant/runner'
4
4
 
5
- require 'nise-bosh-vagrant/cli'
5
+ require 'nise-bosh-vagrant/cli'
6
+
7
+ require 'nise-bosh-vagrant/network_interface'
@@ -27,19 +27,25 @@ EOS
27
27
  opt :memory, "Amount of memory to allocate to the VM in MB", :type => :integer, :default => 512
28
28
  opt :preinstall, "Preinstall hook script", :type => :string
29
29
  opt :postinstall, "Postinstall hook script", :type => :string
30
- opt :address, "IP address for the VM", :type => :string, :default => "192.168.10.10"
30
+ opt :address, "IP address for the VM", :type => :string
31
+ opt :bridge, "Use bridged network interface"
31
32
  end
32
33
 
33
34
  Trollop::die :manifest, "must provide a manifest file" if opts[:manifest].nil?
34
35
  Trollop::die :manifest, "must exist" unless File.exist?(opts[:manifest])
35
36
  Trollop::die :preinstall, "must exist" unless opts[:preinstall].nil? || File.exist?(opts[:preinstall])
36
37
  Trollop::die :postinstall, "must exist" unless opts[:postinstall].nil? || File.exist?(opts[:postinstall])
38
+ Trollop::die :address, "must exist" if opts[:bridge] && opts[:address].nil?
37
39
 
38
40
  opts[:release] = ARGV[0]
39
41
 
40
42
  if opts[:start]
41
43
  opts[:install] = true
42
44
  end
45
+ if ! opts[:bridge]
46
+ opts[:address] ||= "192.168.10.10"
47
+ end
48
+
43
49
 
44
50
  # Generate, start and prepare a fresh VM
45
51
  runner = NiseBOSHVagrant::Runner.new(opts)
@@ -0,0 +1,58 @@
1
+ module NiseBOSHVagrant
2
+
3
+ class NetworkInterface
4
+ def self.detect
5
+ device_list = `VBoxManage list bridgedifs`
6
+ raise "VBoxManage command not found" unless $?.success?
7
+
8
+ device_list.split(/^$\n/).inject([]) { |devices, device|
9
+ device = Hash[*device.split("\n").map { |line| line.match(/^([^:]+): *(.*)/).captures }.flatten]
10
+ kernel_device_name = device["Name"].split(":")[0]
11
+
12
+ ifconfig = `ifconfig #{kernel_device_name}`
13
+ if match = ifconfig.match(/inet ([.0-9]+) netmask 0x([0-9a-f]+) broadcast/) # BSD
14
+ address = match[1]
15
+ mask = match[2].unpack("a2a2a2a2").map { |block| block.hex }.join(".")
16
+ gateway = `route -n get -ifscope #{kernel_device_name} 0.0.0.0 | grep gateway | awk '{print $2}'`.strip
17
+ elsif match = ifconfig.match(/inet addr:([.0-9]+) Bcast:[.0-9]+ Mask:([.0-9]+)/) # Linux
18
+ address = match[1]
19
+ mask = match[2]
20
+ gateway = `ip route show oif #{kernel_device_name} | grep 'default via' | awk '{print $3}'`.strip
21
+ else
22
+ next devices
23
+ end
24
+
25
+ devices << self.new(device["Name"], address, mask, gateway)
26
+ devices
27
+ }
28
+ end
29
+
30
+ def self.find(ip_address)
31
+ self.detect.find do |device|
32
+ device.same_network?(ip_address)
33
+ end
34
+ end
35
+
36
+ attr_reader :name, :vbox_name, :ip_address, :network_mask, :gateway
37
+
38
+ def initialize(vbox_name, ip_address, network_mask, gateway)
39
+ @vbox_name = vbox_name
40
+ @ip_address = ip_address
41
+ @network_mask = network_mask
42
+ @gateway = gateway
43
+ end
44
+
45
+ def name()
46
+ vbox_name.split(":")[0]
47
+ end
48
+
49
+ def same_network?(address)
50
+ (self.class.ip_address_to_int(@ip_address) & self.class.ip_address_to_int(@network_mask)) ==
51
+ (self.class.ip_address_to_int(address) & self.class.ip_address_to_int(@network_mask))
52
+ end
53
+
54
+ def self.ip_address_to_int(ip_address)
55
+ ip_address.split(".").map{|s|s.to_i}.pack("C*").unpack("N")[0]
56
+ end
57
+ end
58
+ end
@@ -19,6 +19,7 @@ module NiseBOSHVagrant
19
19
  @postinstall_file = opts[:postinstall]
20
20
  @memory = opts[:memory]
21
21
  @ip_address = opts[:address]
22
+ @bridge = opts[:bridge]
22
23
 
23
24
  copy_file_prefix = '.nise-bosh'
24
25
  @copy_name = {
@@ -28,6 +29,10 @@ module NiseBOSHVagrant
28
29
  :install_script => "#{copy_file_prefix}-install.sh",
29
30
  }
30
31
 
32
+ if @bridge
33
+ @bridge_if = NetworkInterface.find(@ip_address)
34
+ raise "No available interface found" if @bridge_if.nil?
35
+ end
31
36
  end
32
37
 
33
38
  def generate_vagrantfile(output_path=@vagrantfile_path)
@@ -1,3 +1,3 @@
1
1
  module NiseBOSHVagrant
2
- VERSION = "0.4.3"
2
+ VERSION = "0.5"
3
3
  end
@@ -9,7 +9,12 @@ Vagrant.configure("2") do |config|
9
9
  v.customize ["modifyvm", :id, "--memory", "<%= @memory %>"]
10
10
  end
11
11
 
12
+ <% if @bridge %>
13
+ config.vm.network :public_network, :bridge => "<%= @bridge_if.vbox_name %>"
14
+ config.vm.provision :shell, :path => "<%= File.expand_path("../scripts/bridge_interface.sh", __FILE__) %>", :args => "<%= @ip_address %> <%= @bridge_if.network_mask %> <%= @bridge_if.gateway %>"
15
+ <% else %>
12
16
  config.vm.network :private_network, ip: "<%= @ip_address %>"
17
+ <% end %>
13
18
 
14
19
  <% if not @nise_path.nil? %>config.vm.synced_folder "<%= @nise_path %>", "/home/vagrant/nise_bosh"<% end %>
15
20
  config.vm.synced_folder "./", "/home/vagrant/release"
@@ -0,0 +1,25 @@
1
+ #!/bin/sh
2
+ sudo /sbin/ifconfig eth1 ${1} netmask ${2} up
3
+ sudo /sbin/route add default gw ${3} eth1
4
+ # drop the defalt gataway of eth0
5
+ sudo /sbin/route del default dev eth0
6
+
7
+ sudo cat <<EOF | sudo tee /etc/network/interfaces > /dev/null
8
+ # Generated by nise-bosh-vagrant
9
+
10
+ # The loopback network interface
11
+ auto lo
12
+ iface lo inet loopback
13
+
14
+ # The primary network interface
15
+ auto eth0
16
+ iface eth0 inet dhcp
17
+ post-up /bin/sleep 5; /sbin/route del default dev \$IFACE
18
+
19
+ # Bridge interface
20
+ auto eth1
21
+ iface eth1 inet static
22
+ address ${1}
23
+ netmask ${2}
24
+ gateway ${3}
25
+ EOF
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nise-bosh-vagrant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: '0.5'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-30 00:00:00.000000000 Z
12
+ date: 2013-06-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: trollop
@@ -43,11 +43,13 @@ files:
43
43
  - bin/nise-bosh-vagrant
44
44
  - lib/nise-bosh-vagrant.rb
45
45
  - lib/nise-bosh-vagrant/cli.rb
46
+ - lib/nise-bosh-vagrant/network_interface.rb
46
47
  - lib/nise-bosh-vagrant/runner.rb
47
48
  - lib/nise-bosh-vagrant/version.rb
48
49
  - nise-bosh-vagrant.gemspec
49
50
  - resources/Vagrantfile.erb
50
51
  - resources/install_release.sh.erb
52
+ - scripts/bridge_interface.sh
51
53
  - scripts/prepare.sh
52
54
  - scripts/start.sh
53
55
  - scripts/stop.sh
@@ -65,7 +67,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
67
  version: '0'
66
68
  segments:
67
69
  - 0
68
- hash: 32819581895332205
70
+ hash: -3310966476080707238
69
71
  required_rubygems_version: !ruby/object:Gem::Requirement
70
72
  none: false
71
73
  requirements: