Private networking: Create bridge if it is missing

This commit is contained in:
Michael Stucki 2015-07-06 17:44:35 +02:00
parent fb661300e7
commit c3508870fd
2 changed files with 17 additions and 2 deletions

View file

@ -134,6 +134,20 @@ module Vagrant
ip += '/24'
end
if ! bridge_exists?(bridge_name)
if not bridge_ip
raise "Bridge is missing and no IP was specified!"
end
@logger.info "Creating the bridge #{bridge_name}"
cmd = [
'brctl',
'addbr',
bridge_name
]
@sudo_wrapper.run(*cmd)
end
if ! bridge_has_an_ip?(bridge_name)
if not bridge_ip
raise "Bridge has no IP and none was specified!"
@ -148,6 +162,7 @@ module Vagrant
bridge_name
]
@sudo_wrapper.run(*cmd)
@sudo_wrapper.run('ifconfig', bridge_name, 'up')
end
cmd = [

View file

@ -106,8 +106,8 @@ Whitelist.add '<%= cmd_paths['tar'] %>', '--numeric-owner', '-cvzf', %r{/tmp/.*/
Whitelist.add '<%= cmd_paths['chown'] %>', /\A\d+:\d+\z/, %r{\A/tmp/.*/rootfs\.tar\.gz\z}
# - Private network script and commands
Whitelist.add '<%= cmd_paths['ip'] %>', 'addr', 'add', /(\d+|\.)+\/24/, 'dev', /.+/
Whitelist.add '<%= cmd_paths['ifconfig'] %>', /.+/, 'down'
Whitelist.add '<%= cmd_paths['brctl'] %>', 'delbr', /.+/
Whitelist.add '<%= cmd_paths['ifconfig'] %>', /.+/, /(up|down)/
Whitelist.add '<%= cmd_paths['brctl'] %>', /(addbr|delbr)/, /.+/
Whitelist.add_regex %r{<%= pipework_regex %>}, '**'
##