Skip to content

Commit

Permalink
Pass in URL path to use when calling wait_for_http_request or allow_f…
Browse files Browse the repository at this point in the history
…or_http_request

Use to_slug gem to clean up invalid characters when generating URL
  • Loading branch information
c0state committed Aug 25, 2013
1 parent 219c4e3 commit d9a6379
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 30 deletions.
17 changes: 11 additions & 6 deletions lib/veewee/provider/core/box/build.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'to_slug'

module Veewee
module Provider
module Core
Expand Down Expand Up @@ -218,12 +220,15 @@ def handle_kickstart(options)
# For each kickstart file spinup a webserver and wait for the file to be fetched
unless kickstartfiles.nil?
kickstartfiles.each do |kickfile|
wait_for_http_request(kickfile,{
:port => definition.kickstart_port,
:host => definition.kickstart_ip,
:timeout => definition.kickstart_timeout,
:web_dir => definition.path
})
wait_for_http_request(
File.join(definition.path, kickfile),
kickfile.start_with?('/') ? kickfile : '/' + kickfile,
{
:port => definition.kickstart_port,
:host => definition.kickstart_ip,
:timeout => definition.kickstart_timeout,
}
)
end
end
end
Expand Down
24 changes: 15 additions & 9 deletions lib/veewee/provider/core/box/wincp.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'to_slug'
require 'veewee/provider/core/helper/winrm'

module Veewee
module Provider
module Core
Expand All @@ -14,7 +16,6 @@ def wincp(localfile,remotefile,options={})
end
end


# Calculate an available kickstart port which we will use for wincp
definition.kickstart_port = "7000" if definition.kickstart_port.nil?
guessed_port=guess_free_port(definition.kickstart_port.to_i,7199).to_s
Expand All @@ -23,18 +24,23 @@ def wincp(localfile,remotefile,options={})
definition.kickstart_port=guessed_port.to_s
end

env.ui.warn "Spinning up a wait_for_http_request on http://#{host_ip_as_seen_by_guest}:#{definition.kickstart_port}#{localfile}"
webthread=allow_for_http_request(localfile,{
:port => definition.kickstart_port,
:host => definition.kickstart_ip,
:timeout => definition.kickstart_timeout,
:web_dir => '/'
})
urlpath = localfile.to_slug
urlpath = urlpath.start_with?('/') ? urlpath : '/' + urlpath
env.ui.warn "Spinning up an allow_for_http_request on http://#{host_ip_as_seen_by_guest}:#{definition.kickstart_port}#{localfile} at URL #{urlpath}"
allow_for_http_request(
localfile,
urlpath,
{
:port => definition.kickstart_port,
:host => definition.kickstart_ip,
:timeout => definition.kickstart_timeout,
}
)

begin
self.when_winrm_login_works(self.ip_address,winrm_options.merge(options)) do
env.ui.info "Going to try and copy #{localfile} to #{remotefile.inspect}"
self.exec("cmd.exe /C cscript %TEMP%\\wget.vbs /url:http://#{host_ip_as_seen_by_guest}:#{definition.kickstart_port}#{localfile} /path:#{remotefile}")
self.exec("cmd.exe /C cscript %TEMP%\\wget.vbs /url:http://#{host_ip_as_seen_by_guest}:#{definition.kickstart_port}#{urlpath} /path:#{remotefile}")
# while true do
# sleep 0.1 # used to debug
# end
Expand Down
29 changes: 14 additions & 15 deletions lib/veewee/provider/core/helper/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module Provider
module Core
module Helper
require 'webrick'

include WEBrick
module Servlet

module Servlet

class FileServlet < WEBrick::HTTPServlet::AbstractServlet

attr_reader :ui, :threaded

def initialize(server,localfile,ui,threaded)
Expand Down Expand Up @@ -37,45 +37,44 @@ def do_GET(request,response)
end
end
end

end
module Web

def wait_for_http_request(filename,options) # original blocking
s = server_for_http_request(filename,options)
module Web
def wait_for_http_request(filename, urlname, options) # original blocking
s = server_for_http_request(filename, urlname, options)
s.start
end

def allow_for_http_request(filename,options) # start in new thread
s = server_for_http_request(filename,options.merge({:threaded => false}))
def allow_for_http_request(filename, urlname, options) # start in new thread
s = server_for_http_request(filename, urlname, options.merge({:threaded => false}))
Thread.new { s.start }
end

def server_for_http_request(filename,options={:timeout => 10, :web_dir => "", :port => 7125, :threaded => false})
def server_for_http_request(filename, urlname, options={:timeout => 10, :port => 7125, :threaded => false})
# Calculate the OS equivalent of /dev/null , on windows this is NUL:
# http://www.ruby-forum.com/topic/115472
fn = test(?e, '/dev/null') ? '/dev/null' : 'NUL:'

webrick_logger=WEBrick::Log.new(fn, WEBrick::Log::INFO)

web_dir=options[:web_dir]
filename=filename
s= ::WEBrick::HTTPServer.new(
:Port => options[:port],
:Logger => webrick_logger,
:AccessLog => webrick_logger
)
mount_filename = filename.start_with?('/') ? filename : "/#{filename}"
env.logger.debug("mounting file #{mount_filename}")
s.mount("#{mount_filename}", Veewee::Provider::Core::Helper::Servlet::FileServlet,File.join(web_dir,filename),ui,options[:threaded])

env.logger.debug("mounting file #{urlname}")

s.mount("#{urlname}", Veewee::Provider::Core::Helper::Servlet::FileServlet, filename, ui, options[:threaded])

trap("INT"){
s.shutdown
ui.info "Stopping webserver"
exit
}

s
end

end #Class
end #Module
end #Module
Expand Down
1 change: 1 addition & 0 deletions veewee.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Gem::Specification.new do |s|
s.add_dependency "grit"
s.add_dependency "fission", "0.4.0"
s.add_dependency "whichr"
s.add_dependency "to_slug"

# Modified dependency version, as libxml-ruby dependency has been removed in version 2.1.1
# See : https://github.com/ckruse/CFPropertyList/issues/14
Expand Down

0 comments on commit d9a6379

Please sign in to comment.