Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

vnc and webserver port are now guessed, conflicts with existing vms a…

…re solved
  • Loading branch information...
commit 32cc05dcbd41c825ca730ec8731c5db75557a969 1 parent 0c8f2a1
@jedi4ever authored
View
31 lib/veewee/builder/core/builder/build.rb
@@ -56,10 +56,13 @@ def build(definition_name,box_name,options)
gui_enabled=options[:nogui]==true ? false : true
box.start(gui_enabled)
- #waiting for it to boot
+ # Waiting for it to boot
env.ui.info "Waiting #{definition.boot_wait.to_i} seconds for the machine to boot"
sleep definition.boot_wait.to_i
+ # Calculate an available kickstart port
+ definition.kickstart_port=guess_web_port(definition.kickstart_port).to_s
+
# Let fill's in the variable we need
boot_sequence=fill_sequence(definition.boot_cmd_sequence,{
:ip =>Veewee::Util::Tcp.local_ip,
@@ -81,6 +84,32 @@ def build(definition_name,box_name,options)
handle_postinstall(box,definition)
end
+ # This tries to guess a port for the disposable Webserver
+ def guess_web_port(hint)
+ env.ui.info "Received Web port hint - #{hint}"
+
+ min_port=hint.to_i
+ max_port=7200
+ guessed_port=nil
+
+ for port in (min_port..max_port)
+ unless Veewee::Util::Tcp.is_port_open?(Veewee::Util::Tcp.local_ip, port)
+ guessed_port=port
+ break
+ end
+ end
+
+ if guessed_port.nil?
+ env.ui.info "No free Web port available: tried #{min_port}..#{max_port}"
+ exit -1
+ else
+ env.ui.info "Found Web port #{guessed_port} available"
+ end
+
+ return guessed_port
+ end
+
+
# This will take a sequence and fill in the variables specified in the options
# f.i. options={:ip => "name"} will substitute "%IP%" -> "name"
def fill_sequence(sequence,options)
View
48 lib/veewee/builder/vmfusion/box.rb
@@ -4,6 +4,7 @@
require 'veewee/builder/vmfusion/helper/template'
require 'veewee/builder/vmfusion/helper/create'
require 'veewee/builder/vmfusion/helper/export_ova'
+require 'veewee/util/tcp'
module Veewee
@@ -14,6 +15,7 @@ class Box < Veewee::Builder::Core::Box
include ::Veewee::Builder::Vmfusion::BoxHelper
include ::Veewee::Builder::Core::BoxCommand
+ attr_reader :vnc_port
def initialize(name,env)
@@ -22,7 +24,11 @@ def initialize(name,env)
super(name,env)
end
+ # When we create a new box
+ # We assume the box is not running
def create(definition)
+
+ @vnc_port=guess_vnc_port
create_vm(definition)
create_disk(definition)
end
@@ -79,9 +85,45 @@ def ip_address
# Type on the console
def console_type(sequence,type_options={})
- # vnc_port=raw.vnc_port
- vnc_port=20
- vnc_type(sequence,"localhost",vnc_port)
+ vnc_type(sequence,"localhost",vnc_display_port)
+
+ # Once this is over, we can remove the vnc port from the config file
+ remove_vnc_port
+ end
+
+ # This tries to guess a port for the VNC Display
+ def guess_vnc_port
+ min_port=5920
+ max_port=6000
+ guessed_port=nil
+
+ for port in (min_port..max_port)
+ unless Veewee::Util::Tcp.is_port_open?("127.0.0.1", port)
+ guessed_port=port
+ break
+ end
+ end
+
+ if guessed_port.nil?
+ env.ui.info "No free VNC port available: tried #{min_port}..#{max_port}"
+ exit -1
+ else
+ env.ui.info "Found VNC port #{guessed_port} available"
+ end
+
+ return guessed_port
+ end
+
+ def vnc_display_port
+ vnc_port - 5900
+ end
+
+ def remove_vnc_port
+ env.ui.info "Removing vnc_port from #{raw.vmx_path}"
+ lines=File.readlines(raw.vmx_path).reject{|l| l =~ /^RemoteDisplay.vnc/}
+ File.open(raw.vmx_path, 'w') do |f|
+ f.puts lines
+ end
end
private
View
13 lib/veewee/builder/vmfusion/builder.rb
@@ -30,12 +30,17 @@ def ssh_options(definition)
return ssh_options
end
- # Transfer information provide by the builder to the box
- #
- #
+
+ #
+
+ # Transfer information provide by the builder to the box
+ #
+ #
def transfer_buildinfo(box,definition)
super(box,definition)
+ # When we get here, ssh is available and no postinstall scripts have been executed yet
+ # So we begin by transferring the ISO file of the vmware tools
begin
Veewee::Util::Ssh.when_ssh_login_works(box.ip_address,ssh_options(definition).merge({:timeout => definition.postinstall_timeout.to_i})) do
begin
@@ -49,7 +54,7 @@ def transfer_buildinfo(box,definition)
rescue Net::SSH::AuthenticationFailed
env.ui.error "Authentication failure"
exit -1
- end
+ end
end
View
1  lib/veewee/builder/vmfusion/helper/template.rb
@@ -21,6 +21,7 @@ def vmx_template(definition)
:mac_addres => "auto generated",
:iso_file => "#{File.join(env.config.veewee.iso_dir,definition.iso_file)}",
:box_name => name,
+ :vnc_port => vnc_port
}
vars = ErbBinding.new(data)
View
3  lib/veewee/builder/vmfusion/helper/template.vmx.erb
@@ -78,5 +78,4 @@ ethernet0.bsdName = "en0"
ethernet0.displayName = "Ethernet"
sound.startConnected = "FALSE"
RemoteDisplay.vnc.enabled = "TRUE"
-RemoteDisplay.vnc.port = "5920"
-#RemoteDisplay.vnc.key = "Cig8ARE7BS4KLhQ7GzIFIgwNGBIHNS04BwUCMiYiOhknOSstBQoqCBsYKCwbKgInFB89Cgs5FAMVAxERKiUdBzcXFxMiBTQEIRMENTkMOSwxMAwjGD8jOBwqKio4GQ8xOCYLDiYVCBMqFzMENAQ4BSMkJTUdFhQGOjg0BRUSNiY="
+RemoteDisplay.vnc.port = "<%= vnc_port %>"
Please sign in to comment.
Something went wrong with that request. Please try again.