Module: Veewee::Provider::Virtualbox::BoxCommand
- Included in:
- Box
- Defined in:
- lib/veewee/provider/virtualbox/box/up.rb,
lib/veewee/provider/virtualbox/box/ssh.rb,
lib/veewee/provider/virtualbox/box/halt.rb,
lib/veewee/provider/virtualbox/box/build.rb,
lib/veewee/provider/virtualbox/box/create.rb,
lib/veewee/provider/virtualbox/box/destroy.rb,
lib/veewee/provider/virtualbox/box/poweroff.rb,
lib/veewee/provider/virtualbox/box/helper/ip.rb,
lib/veewee/provider/virtualbox/box/helper/create.rb,
lib/veewee/provider/virtualbox/box/helper/status.rb,
lib/veewee/provider/virtualbox/box/export_vagrant.rb,
lib/veewee/provider/virtualbox/box/helper/version.rb,
lib/veewee/provider/virtualbox/box/validate_vagrant.rb,
lib/veewee/provider/virtualbox/box/helper/buildinfo.rb,
lib/veewee/provider/virtualbox/box/helper/forwarding.rb,
lib/veewee/provider/virtualbox/box/helper/ssh_options.rb,
lib/veewee/provider/virtualbox/box/helper/console_type.rb,
lib/veewee/provider/virtualbox/box/helper/guest_additions.rb
Instance Method Summary (collapse)
- - (Object) add_floppy_controller
- - (Object) add_ide_controller
- - (Object) add_sata_controller
- - (Object) add_shared_folder
- - (Object) add_ssh_nat_mapping
- - (Object) attach_disk
- - (Object) attach_floppy
- - (Object) attach_guest_additions
- - (Object) attach_isofile
- - (Object) attach_serial_console
- - (Object) build(options = {})
- - (Object) build_info
- - (Object) console_type(sequence)
- - (Object) create(options = {})
- - (Object) create_disk
- - (Object) create_vm
- - (Object) delete_forwarding(name)
- - (Object) destroy(option = {})
- - (Object) download_vbox_guest_additions_iso(options)
- - (Boolean) exists?
-
- (Object) export_vagrant(options)
Shellutil.execute("vagrant package --base #vmname --include /tmp/Vagrantfile --output /tmp/#vmname.box", => "on").
- - (Object) forwarding(name)
- - (Object) get_vbox_home
- - (Object) halt(options = {})
- - (Object) host_ip_as_seen_by_guest
-
- (Object) ip_address
Get the IP address of the box.
- - (Object) poweroff(options = {})
- - (Boolean) running?
- - (Object) send_keycode(keycode)
- - (Object) send_virtualbox_sequence(sequence)
- - (Object) ssh(command, options = {})
- - (Object) ssh_options
- - (Object) suppress_messages
-
- (Object) transfer_buildinfo(options)
Transfer information provide by the provider to the box.
- - (Object) up(options = {})
- - (Object) validate_vagrant(options)
- - (Object) vbox_os_type_id(veewee_type_id)
- - (Object) vbox_version
Instance Method Details
- (Object) add_floppy_controller
105 106 107 108 109 110 111 112 |
# File 'lib/veewee/provider/virtualbox/box/helper/create.rb', line 105 def add_floppy_controller # Create floppy controller unless definition.floppy_files.nil? command="#{@vboxcmd} storagectl '#{name}' --name 'Floppy Controller' --add floppy" shell_exec("#{command}") end end |
- (Object) add_ide_controller
6 7 8 9 10 |
# File 'lib/veewee/provider/virtualbox/box/helper/create.rb', line 6 def add_ide_controller #unless => "${vboxcmd} showvminfo '${vname}' | grep 'IDE Controller' " command ="#{@vboxcmd} storagectl '#{name}' --name 'IDE Controller' --add ide" shell_exec("#{command}") end |
- (Object) add_sata_controller
12 13 14 15 16 |
# File 'lib/veewee/provider/virtualbox/box/helper/create.rb', line 12 def add_sata_controller #unless => "${vboxcmd} showvminfo '${vname}' | grep 'SATA Controller' "; command ="#{@vboxcmd} storagectl '#{name}' --name 'SATA Controller' --add sata --hostiocache #{definition.hostiocache} --sataportcount 1" shell_exec("#{command}") end |
- (Object) add_shared_folder
34 35 36 37 |
# File 'lib/veewee/provider/virtualbox/box/helper/create.rb', line 34 def add_shared_folder command="#{@vboxcmd} sharedfolder add '#{name}' --name 'veewee-validation' --hostpath '#{File.(env.validation_dir)}' --automount" shell_exec("#{command}") end |
- (Object) add_ssh_nat_mapping
25 26 27 28 29 30 31 32 |
# File 'lib/veewee/provider/virtualbox/box/helper/create.rb', line 25 def add_ssh_nat_mapping unless definition.nil? #Map SSH Ports command="#{@vboxcmd} modifyvm '#{name}' --natpf1 'guestssh,tcp,,#{definition.ssh_host_port},,#{definition.ssh_guest_port}'" shell_exec("#{command}") end end |
- (Object) attach_disk
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/veewee/provider/virtualbox/box/helper/create.rb', line 75 def attach_disk place=get_vbox_home location=name+"."+definition.disk_format.downcase location="#{File.join(place,name,location)}" env.ui.info "Attaching disk: #{location}" #command => "${vboxcmd} storageattach '${vname}' --storagectl 'SATA Controller' --port 0 --device 0 --type hdd --medium '${vname}.vdi'", command ="#{@vboxcmd} storageattach '#{name}' --storagectl 'SATA Controller' --port 0 --device 0 --type hdd --medium '#{location}'" shell_exec("#{command}") end |
- (Object) attach_floppy
115 116 117 118 119 120 121 122 123 |
# File 'lib/veewee/provider/virtualbox/box/helper/create.rb', line 115 def attach_floppy unless definition.floppy_files.nil? # Attach floppy to machine (the vfd extension is crucial to detect msdos type floppy) floppy_file=File.join(definition.path,"virtualfloppy.vfd") command="#{@vboxcmd} storageattach '#{name}' --storagectl 'Floppy Controller' --port 0 --device 0 --type fdd --medium '#{floppy_file}'" shell_exec("#{command}") end end |
- (Object) attach_guest_additions
97 98 99 100 101 102 |
# File 'lib/veewee/provider/virtualbox/box/helper/create.rb', line 97 def attach_guest_additions full_iso_file=File.join(env.config.veewee.iso_dir,"VBoxGuestAdditions_#{self.vbox_version}.iso") env.ui.info "Mounting guest additions: #{full_iso_file}" command ="#{@vboxcmd} storageattach '#{name}' --storagectl 'IDE Controller' --type dvddrive --port 1 --device 0 --medium '#{full_iso_file}'" shell_exec("#{command}") end |
- (Object) attach_isofile
90 91 92 93 94 95 |
# File 'lib/veewee/provider/virtualbox/box/helper/create.rb', line 90 def attach_isofile full_iso_file=File.join(env.config.veewee.iso_dir,definition.iso_file) env.ui.info "Mounting cdrom: #{full_iso_file}" command ="#{@vboxcmd} storageattach '#{name}' --storagectl 'IDE Controller' --type dvddrive --port 0 --device 0 --medium '#{full_iso_file}'" shell_exec("#{command}") end |
- (Object) attach_serial_console
18 19 20 21 22 23 |
# File 'lib/veewee/provider/virtualbox/box/helper/create.rb', line 18 def attach_serial_console command ="#{@vboxcmd} modifyvm '#{name}' --uart1 0x3F8 4" shell_exec("#{command}") command ="#{@vboxcmd} modifyvm '#{name}' --uartmode1 file '#{File.join(FileUtils.pwd,name+"-serial-console"+'.log')}'" shell_exec("#{command}") end |
- (Object) build(options = {})
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/veewee/provider/virtualbox/box/build.rb', line 6 def build(={}) download_vbox_guest_additions_iso() unless definition.floppy_files.nil? unless self.shell_exec("java").status == 0 raise Veewee::Error,"This box contains floppyfiles, to create it you require to have java installed or have it in your path" end end super() end |
- (Object) build_info
6 7 8 9 10 |
# File 'lib/veewee/provider/virtualbox/box/helper/buildinfo.rb', line 6 def build_info info=super info << { :filename => ".vbox_version", :content => "#{self.vbox_version}" } end |
- (Object) console_type(sequence)
9 10 11 |
# File 'lib/veewee/provider/virtualbox/box/helper/console_type.rb', line 9 def console_type(sequence) send_virtualbox_sequence(sequence) end |
- (Object) create(options = {})
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/veewee/provider/virtualbox/box/create.rb', line 6 def create(={}) # First check if the directory where we create the VM is empty # Sometimes there are leftovers from badly terminated vms box_directory=File.join(self.get_vbox_home,name) if File.exists?(box_directory) raise Veewee::Error,"To create the vm '#{name}' the directory '#{box_directory}' needs to be empty. \nThis could be caused by an badly closed vm.\nRemove it manually before you proceed." end guessed_port=guess_free_port(definition.ssh_host_port.to_i,definition.ssh_host_port.to_i+40).to_s if guessed_port.to_s!=definition.ssh_host_port env.ui.warn "Changing ssh port from #{definition.ssh_host_port} to #{guessed_port}" definition.ssh_host_port=guessed_port.to_s end # Suppress those annoying virtualbox messages self. self.create_vm # Attach ttyS0 to the VM for console output redirect_console=[:redirectconsole] if redirect_console self.attach_serial_console end # Adds a folder to the vm for testing purposes self.add_shared_folder #Create a disk with the same name as the box_name self.create_disk self.add_ide_controller self.attach_isofile self.attach_guest_additions self.add_sata_controller self.attach_disk self.create_floppy("virtualfloppy.vfd") self.add_floppy_controller self.attach_floppy self.add_ssh_nat_mapping end |
- (Object) create_disk
65 66 67 68 69 70 71 72 73 |
# File 'lib/veewee/provider/virtualbox/box/helper/create.rb', line 65 def create_disk env.ui.info "Creating new harddrive of size #{definition.disk_size.to_i} " place=get_vbox_home command ="#{@vboxcmd} createhd --filename '#{File.join(place,name,name+"."+definition.disk_format.downcase)}' --size '#{definition.disk_size.to_i}' --format #{definition.disk_format.downcase}" shell_exec("#{command}") end |
- (Object) create_vm
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/veewee/provider/virtualbox/box/helper/create.rb', line 131 def create_vm command="#{@vboxcmd} createvm --name '#{name}' --ostype '#{vbox_os_type_id(definition.os_type_id)}' --register" #Exec and system stop the execution here shell_exec("#{command}") env.ui.info "Creating vm #{name} : #{definition.memory_size}M - #{definition.cpu_count} CPU - #{vbox_os_type_id(definition.os_type_id)}" #setting cpu's command="#{@vboxcmd} modifyvm '#{name}' --cpus #{definition.cpu_count}" shell_exec("#{command}") #setting memory size command="#{@vboxcmd} modifyvm '#{name}' --memory #{definition.memory_size}" shell_exec("#{command}") #setting bootorder command="#{@vboxcmd} modifyvm '#{name}' --boot1 disk --boot2 dvd --boot3 none --boot4 none" shell_exec("#{command}") # Modify the vm to enable or disable hw virtualization extensions vm_flags=%w{pagefusion acpi ioapic pae hpet hwvirtex hwvirtexcl nestedpaging largepages vtxvpid synthxcpu rtcuseutc} vm_flags.each do |vm_flag| if definition.instance_variable_defined?("@#{vm_flag}") vm_flag_value=definition.instance_variable_get("@#{vm_flag}") env.ui.info "Setting VM Flag #{vm_flag} to #{vm_flag_value}" env.ui.warn "Used of #{vm_flag} is deprecated - specify your options in :virtualbox => { : vm_options => [\"#{vm_flag}\" => \"#{vm_flag_value}\"]}" command="#{@vboxcmd} modifyvm #{name} --#{vm_flag.to_s} #{vm_flag_value}" shell_exec("#{command}") end end unless definition.virtualbox[:vm_options][0].nil? definition.virtualbox[:vm_options][0].each do |vm_flag,vm_flag_value| env.ui.info "Setting VM Flag #{vm_flag} to #{vm_flag_value}" command="#{@vboxcmd} modifyvm #{name} --#{vm_flag.to_s} #{vm_flag_value}" shell_exec("#{command}") end end end |
- (Object) delete_forwarding(name)
29 30 31 32 33 |
# File 'lib/veewee/provider/virtualbox/box/helper/forwarding.rb', line 29 def delete_forwarding(name) forward=self.forwarding(name) command="#{@vboxcmd} controlvm '#{self.name}' natpf#{forward[:nr]} delete #{name}" shell_results=shell_exec("#{command}") end |
- (Object) destroy(option = {})
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/veewee/provider/virtualbox/box/destroy.rb', line 6 def destroy(option={}) unless self.exists? env.ui.error "Error:: You tried to destroy a non-existing box '#{name}'" exit -1 end # If it has a save state,remove that first if self.running? # Poweroff self.poweroff # Wait for it to happen sleep 2 end command="#{@vboxcmd} unregistervm '#{name}' --delete" env.ui.info command env.ui.info "Deleting vm #{name}" #Exec and system stop the execution here shell_exec("#{command}",{:mute => true}) sleep 1 #if the disk was not attached when the machine was destroyed we also need to delete the disk pattern=name+"." #+definition.disk_format.downcase found=false command="#{@vboxcmd} list hdds -l" hdds=shell_exec("#{command}",{:mute => true}).stdout.split(/\n\n/) hdds.each do |hdd_text| location=hdd_text.split(/\n/).grep(/^Location/).first.split(':')[1].strip if location.match(/#{pattern}/) if File.exists?(location) command="#{@vboxcmd} closemedium disk '#{location}' --delete" else command="#{@vboxcmd} closemedium disk '#{location}'" end env.ui.info "Deleting disk #{location}" env.ui.info "#{command}" shell_exec("#{command}",{:mute => true}) if File.exists?(location) env.ui.info "We tried to delete the disk file via virtualbox '#{location} but failed" env.ui.info "Removing it manually" FileUtils.rm(location) exit -1 end break end end end |
- (Object) download_vbox_guest_additions_iso(options)
6 7 8 9 10 11 12 |
# File 'lib/veewee/provider/virtualbox/box/helper/guest_additions.rb', line 6 def download_vbox_guest_additions_iso() version=self.vbox_version isofile="VBoxGuestAdditions_#{version}.iso" url="http://download.virtualbox.org/virtualbox/#{version}/#{isofile}" env.ui.info "Downloading vbox guest additions iso v #{version} - #{url}" download_iso(url,isofile) end |
- (Boolean) exists?
6 7 8 9 10 11 12 13 |
# File 'lib/veewee/provider/virtualbox/box/helper/status.rb', line 6 def exists? command="#{@vboxcmd} list vms" shell_results=shell_exec("#{command}",{:mute => true}) exists=shell_results.stdout.split(/\n/).grep(/\"#{name}\"/).size!=0 env.logger.info("Vm exists? #{exists}") return exists end |
- (Object) export_vagrant(options)
Shellutil.execute("vagrant package --base #vmname --include /tmp/Vagrantfile --output /tmp/#vmname.box", => "on")
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/veewee/provider/virtualbox/box/export_vagrant.rb', line 9 def export_vagrant() # Check if box already exists unless self.exists? env.ui.info "#{name} is not found, maybe you need to build it first?" exit end if File.exists?("#{name}.box") if ["force"] env.logger.debug("#{name}.box exists, but --force was provided") env.logger.debug("removing #{name}.box first") FileUtils.rm("#{name}.box") env.logger.debug("#{name}.box removed") else raise Veewee::Error, "export file #{name}.box already exists. Use --force option to overwrite." end end # We need to shutdown first if self.running? env.ui.info "Vagrant requires the box to be shutdown, before it can export" env.ui.info "Sudo also needs to work for user #{definition.ssh_user}" env.ui.info "Performing a clean shutdown now." self.halt #Wait for state poweroff while (self.running?) do env.ui.info ".",{:new_line => false} sleep 1 end env.ui.info "" env.ui.info "Machine #{name} is powered off cleanly" end #Vagrant requires a relative path for output of boxes #4.0.x. not using boxes as a subdir boxdir=Pathname.new(Dir.pwd) full_path=File.join(boxdir,name+".box") path1=Pathname.new(full_path) path2=Pathname.new(Dir.pwd) box_path=path1.relative_path_from(path2).to_s if File.exists?("#{box_path}") env.ui.info "box #{name}.box already exists" exit end env.ui.info "Excuting vagrant voodoo:" export_command="vagrant package --base '#{name}' --output '#{box_path}'" env.ui.info "#{export_command}" shell_exec("#{export_command}") #hmm, needs to get the gem_home set? env.ui.info "" #add_ssh_nat_mapping back!!!! #vagrant removes the mapping #we need to restore it in order to be able to login again self.add_ssh_nat_mapping env.ui.info "To import it into vagrant type:" env.ui.info "vagrant box add '#{name}' '#{box_path}'" env.ui.info "" env.ui.info "To use it:" env.ui.info "vagrant init '#{name}'" env.ui.info "vagrant up" env.ui.info "vagrant ssh" end |
- (Object) forwarding(name)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/veewee/provider/virtualbox/box/helper/forwarding.rb', line 6 def forwarding(name) command="#{@vboxcmd} showvminfo --details --machinereadable '#{self.name}'" shell_results=shell_exec("#{command}") rules=shell_results.stdout.split(/\n/).grep(/^Forward/) result=nil rules.each do |rule| #Forwarding(0) nr=rule.split('=')[0].split('(')[1].split(')')[0].to_i + 1 # guestssh,tcp,,2222,,22 details=rule.split('=')[1].split('"')[1].split(',') result = { :nr => nr, :name => details[0], :protocol => details[1], :host_ip => details[2], :host_port => details[3], :guest_ip => details[4], :guest_port => details[5] } end return result end |
- (Object) get_vbox_home
39 40 41 42 43 44 |
# File 'lib/veewee/provider/virtualbox/box/helper/create.rb', line 39 def get_vbox_home command="#{@vboxcmd} list systemproperties" shell_results=shell_exec("#{command}") location=shell_results.stdout.split(/\n/).grep(/Default machine/)[0].split(":")[1].strip return location end |
- (Object) halt(options = {})
6 7 8 |
# File 'lib/veewee/provider/virtualbox/box/halt.rb', line 6 def halt(={}) super() end |
- (Object) host_ip_as_seen_by_guest
7 8 9 |
# File 'lib/veewee/provider/virtualbox/box/helper/ip.rb', line 7 def host_ip_as_seen_by_guest "10.0.2.2" end |
- (Object) ip_address
Get the IP address of the box
12 13 14 |
# File 'lib/veewee/provider/virtualbox/box/helper/ip.rb', line 12 def ip_address return "127.0.0.1" end |
- (Object) poweroff(options = {})
6 7 8 9 10 11 12 13 14 |
# File 'lib/veewee/provider/virtualbox/box/poweroff.rb', line 6 def poweroff(={}) # If the vm is not powered off, perform a shutdown if (self.exists? && self.running?) env.ui.info "Shutting down vm #{name}" #We force it here, maybe vm.shutdown is cleaner command="#{@vboxcmd} controlvm '#{name}' poweroff" shell_exec("#{command}") end end |
- (Boolean) running?
15 16 17 18 19 20 21 22 |
# File 'lib/veewee/provider/virtualbox/box/helper/status.rb', line 15 def running? command="#{@vboxcmd} list runningvms" shell_results=shell_exec("#{command}",{:mute => true}) running=shell_results.stdout.split(/\n/).grep(/\"#{name}\"/).size!=0 env.logger.info("Vm running? #{running}") return running end |
- (Object) send_keycode(keycode)
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/veewee/provider/virtualbox/box/helper/console_type.rb', line 46 def send_keycode(keycode) command= "#{@vboxcmd} controlvm '#{name}' keyboardputscancode #{keycode}" env.logger.info "#{command}" sshresult=shell_exec("#{command}",{:mute => true}) unless sshresult.stdout.index("E_ACCESSDENIED").nil? env.ui.error "There was an error typing the commands on the console" env.ui.error "Probably the VM did not get started." env.ui.error "" env.ui.error "#{sshresult.stdout}" exit -1 end end |
- (Object) send_virtualbox_sequence(sequence)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/veewee/provider/virtualbox/box/helper/console_type.rb', line 13 def send_virtualbox_sequence(sequence) env.ui.info "" counter=0 sequence.each { |s| counter=counter+1 env.ui.info "Typing:[#{counter}]: "+s keycodes=Veewee::Provider::Core::Helper::Scancode.string_to_keycode(s) # VBox seems to have issues with sending the scancodes as one big # .join()-ed string. It seems to get them out or order or ignore some. # A workaround is to send the scancodes one-by-one. codes="" for keycode in keycodes.split(' ') do unless keycode=="wait" send_keycode(keycode) sleep 0.01 else sleep 1 end end #sleep after each sequence (needs to be param) sleep 0.5 } env.ui.info "Done typing." env.ui.info "" end |
- (Object) ssh(command, options = {})
6 7 8 |
# File 'lib/veewee/provider/virtualbox/box/ssh.rb', line 6 def ssh(command,={}) super(command,) end |
- (Object) ssh_options
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/veewee/provider/virtualbox/box/helper/ssh_options.rb', line 6 def port=definition.ssh_host_port if self.exists? forward=self.forwarding("guestssh") unless forward.nil? port=forward[:host_port] end end ={ :user => definition.ssh_user, :port => port, :password => definition.ssh_password, :timeout => definition.ssh_login_timeout.to_i } return end |
- (Object) suppress_messages
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/veewee/provider/virtualbox/box/helper/create.rb', line 47 def day=24*60*60 update_date=Time.now+365*day extraData = [ ["Gui/RegistrationData","triesLeft=0"], ["Gui/SuppressMessages","confirmInputCapture,remindAboutAutoCapture,remindAboutMouseIntegrationOff,remindAboutMouseIntegrationOn,remindAboutWrongColorDepth"], ["GUI/UpdateDate", "1 d, #{update_date.year}-#{update_date.month.to_s.rjust(2,'0')}-#{update_date.day.to_s.rjust(2,'0')}, stable"], ["GUI/UpdateCheckCount","60"] ] extraData.each do |data| command="#{@vboxcmd} setextradata global '#{data[0]}' '#{data[1]}'" shell_results=shell_exec("#{command}") end end |
- (Object) transfer_buildinfo(options)
Transfer information provide by the provider to the box
15 16 17 18 19 20 |
# File 'lib/veewee/provider/virtualbox/box/helper/buildinfo.rb', line 15 def transfer_buildinfo() super() iso_image="VBoxGuestAdditions_#{self.vbox_version}.iso" env.logger.info "About to transfer virtualbox guest additions iso to the box #{name} - #{ip_address} - #{}" self.scp("#{File.join(env.config.veewee.iso_dir,iso_image)}",File.basename(iso_image)) end |
- (Object) up(options = {})
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/veewee/provider/virtualbox/box/up.rb', line 6 def up(={}) gui_enabled=[:nogui]==true ? false : true raise Veewee::Error,"Box is already running" if self.running? # Before we start,correct the ssh port if needed forward=self.forwarding("guestssh") guessed_port=guess_free_port(definition.ssh_host_port.to_i,definition.ssh_host_port.to_i+40).to_s definition.ssh_host_port=guessed_port.to_s unless forward.nil? if guessed_port!=forward[:guest_port] # Remove the existing one self.delete_forwarding("guestssh") env.ui.warn "Changing ssh port from #{forward[:guest_port]} to #{guessed_port}" self.add_ssh_nat_mapping end else self.add_ssh_nat_mapping end self. # Once assembled we start the machine env.logger.info "Started the VM with GUI Enabled? #{gui_enabled}" command="#{@vboxcmd} startvm --type gui '#{name}'" unless (gui_enabled) command="#{@vboxcmd} startvm --type headless '#{name}'" end shell_results=shell_exec("#{command}",{:mute => true}) end |
- (Object) validate_vagrant(options)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/veewee/provider/virtualbox/box/validate_vagrant.rb', line 6 def validate_vagrant() require 'cucumber' require 'cucumber/rspec/disable_option_parser' require 'cucumber/cli/main' # Passing ssh options via ENV varialbles to cucumber # VEEWEE_SSH_USER, VEEWEE_SSH_PASSWORD ,VEEWEE_SSH_PORT cucumber_vars=self. cucumber_vars.each do |key,value| ENV['VEEWEE_'+key.to_s.upcase]=cucumber_vars[key].to_s end # Pass the name of the box ENV['VEEWEE_BOXNAME']=@name ENV['VEEWEE_PROVIDER']="virtualbox" feature_path=File.join(File.dirname(__FILE__),"..","..","..","..","..","validation","veewee.feature") features=Array.new features[0]=feature_path features[1]="--tags" features[2]="@vagrant,@virtualbox" begin # The dup is to keep ARGV intact, so that tools like ruby-debug can respawn. failure = Cucumber::Cli::Main.execute(features.dup) Kernel.exit(failure ? 1 : 0) rescue SystemExit => e Kernel.exit(e.status) rescue Exception => e env.ui.error("#{e.} (#{e.class})") env.ui.error(e.backtrace.join("\n")) Kernel.exit(1) end end |
- (Object) vbox_os_type_id(veewee_type_id)
125 126 127 128 129 |
# File 'lib/veewee/provider/virtualbox/box/helper/create.rb', line 125 def vbox_os_type_id(veewee_type_id) type=env.ostypes[veewee_type_id][:vbox] env.logger.info("Using VBOX os_type_id #{type}") return type end |
- (Object) vbox_version
6 7 8 9 10 11 |
# File 'lib/veewee/provider/virtualbox/box/helper/version.rb', line 6 def vbox_version command="#{@vboxcmd} --version" shell_results=shell_exec("#{command}",{:mute => true}) version=shell_results.stdout.strip.split('r')[0] return version end |