Class: VagrantPlugins::GuestOpenWrt::Cap::ConfigureNetworks

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/plugins/guests/openwrt/cap/configure_networks.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(machine, networks) ⇒ ConfigureNetworks

Returns a new instance of ConfigureNetworks.



14
15
16
17
# File 'lib/vagrant/plugins/guests/openwrt/cap/configure_networks.rb', line 14

def initialize(machine, networks)
  @machine = machine
  @networks = networks
end

Instance Attribute Details

#machineObject (readonly)

Returns the value of attribute machine.



12
13
14
# File 'lib/vagrant/plugins/guests/openwrt/cap/configure_networks.rb', line 12

def machine
  @machine
end

#networksObject (readonly)

Returns the value of attribute networks.



12
13
14
# File 'lib/vagrant/plugins/guests/openwrt/cap/configure_networks.rb', line 12

def networks
  @networks
end

Class Method Details

.configure_networks(machine, networks) ⇒ Object



5
6
7
8
9
10
# File 'lib/vagrant/plugins/guests/openwrt/cap/configure_networks.rb', line 5

def self.configure_networks(machine, networks)
  new(machine, networks).configure!
rescue IOError
  # Do nothing, because it probably means the machine shut down
  # and SSH connection was lost.
end

Instance Method Details

#configure!Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/vagrant/plugins/guests/openwrt/cap/configure_networks.rb', line 19

def configure!
  lan = networks[0]
  execute "uci set network.lan.ipaddr='#{lan[:ip]}'"

  wan = networks[1]
  execute "uci add network interface"
  execute "uci rename network.@interface[-1]='wan'"
  execute "uci set network.wan.ifname='eth1'"
  execute "uci set network.wan.proto='#{wan[:type]}'"
  if wan[:type] != :dhcp
    execute "uci set network.wan.ipaddr='#{wan[:ip]}'"
    execute "uci set network.wan.netmask='#{wan[:netmask]}'"
  end

  execute "uci commit network && /etc/init.d/network reload"
end

#execute(cmd, &block) ⇒ Object



36
37
38
# File 'lib/vagrant/plugins/guests/openwrt/cap/configure_networks.rb', line 36

def execute(cmd, &block)
  machine.communicate.execute(cmd, &block)
end