mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-10-07 17:40:30 +00:00
Able to get console output from the machine now!
It's blocking though, so maybe there should be a check for "Entering runlevel: 2" or some shit...
This commit is contained in:
parent
6a0bef147a
commit
ed98ab30fd
2 changed files with 31 additions and 9 deletions
|
@ -45,12 +45,37 @@ class VirtualBoxInstance(Instance):
|
||||||
os.close(handle)
|
os.close(handle)
|
||||||
serial_port.path = self.serial_port_path
|
serial_port.path = self.serial_port_path
|
||||||
serial_port.host_mode = vboxapi.library.PortMode.host_pipe
|
serial_port.host_mode = vboxapi.library.PortMode.host_pipe
|
||||||
# serial_port.server = True
|
serial_port.server = True # Create the socket on startup
|
||||||
machine.save_settings()
|
machine.save_settings()
|
||||||
|
|
||||||
def boot(self):
|
def boot(self):
|
||||||
self.machine.launch_vm_process(self.session, 'headless').wait_for_completion(-1)
|
self.machine.launch_vm_process(self.session, 'headless').wait_for_completion(-1)
|
||||||
|
|
||||||
|
def get_console_output(self):
|
||||||
|
import socket
|
||||||
|
import select
|
||||||
|
import errno
|
||||||
|
import sys
|
||||||
|
console = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||||
|
console.connect(self.serial_port_path)
|
||||||
|
|
||||||
|
console.setblocking(0)
|
||||||
|
output = ''
|
||||||
|
continue_select = True
|
||||||
|
while continue_select:
|
||||||
|
read_ready, _, _ = select.select([console], [], [])
|
||||||
|
if console in read_ready:
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
sys.stdout.write(console.recv(1024))
|
||||||
|
break
|
||||||
|
except socket.error, e:
|
||||||
|
if e.errno != errno.EWOULDBLOCK:
|
||||||
|
raise Exception(e)
|
||||||
|
continue_select = False
|
||||||
|
console.close()
|
||||||
|
return output
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
self.session.console.power_down().wait_for_completion(-1)
|
self.session.console.power_down().wait_for_completion(-1)
|
||||||
self.Lock(self.machine, self.session).unlock()
|
self.Lock(self.machine, self.session).unlock()
|
||||||
|
|
|
@ -45,23 +45,20 @@ volume:
|
||||||
image_path = '/Users/anders/Workspace/cloud/images/debian-wheezy-amd64-141130.vmdk'
|
image_path = '/Users/anders/Workspace/cloud/images/debian-wheezy-amd64-141130.vmdk'
|
||||||
|
|
||||||
image = VirtualBoxImage(manifest, image_path)
|
image = VirtualBoxImage(manifest, image_path)
|
||||||
lines = []
|
output = None
|
||||||
try:
|
try:
|
||||||
instance = VirtualBoxInstance('unpartitioned_extlinux', image)
|
instance = VirtualBoxInstance('unpartitioned_extlinux', image)
|
||||||
try:
|
try:
|
||||||
instance.create()
|
instance.create()
|
||||||
try:
|
try:
|
||||||
instance.boot()
|
instance.boot()
|
||||||
lines = instance.get_console_output()
|
output = instance.get_console_output()
|
||||||
# tools.reachable_with_ssh(instance)
|
# tools.reachable_with_ssh(instance)
|
||||||
finally:
|
finally:
|
||||||
instance.shutdown()
|
instance.shutdown()
|
||||||
finally:
|
finally:
|
||||||
instance.destroy()
|
instance.destroy()
|
||||||
finally:
|
finally:
|
||||||
# pass
|
image.destroy()
|
||||||
if len(lines) > 0:
|
import os
|
||||||
raise Exception('\n'.join(lines))
|
os.remove(image_path)
|
||||||
# image.destroy()
|
|
||||||
# import os
|
|
||||||
# os.remove(image_path)
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue