mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-10-07 17:40:30 +00:00
Check runlevel in order to terminate reading from the console
This commit is contained in:
parent
ed98ab30fd
commit
27950af66e
2 changed files with 12 additions and 5 deletions
|
@ -50,24 +50,33 @@ class VirtualBoxInstance(Instance):
|
|||
|
||||
def boot(self):
|
||||
self.machine.launch_vm_process(self.session, 'headless').wait_for_completion(-1)
|
||||
self.console_output = self._read_console_output()
|
||||
|
||||
def get_console_output(self):
|
||||
def _read_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)
|
||||
|
||||
runlvl_check = 'INIT: Entering runlevel: 2'
|
||||
output = ''
|
||||
ptr = 0
|
||||
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))
|
||||
read = console.recv(1024)
|
||||
output += read
|
||||
sys.stdout.write(read)
|
||||
if runlvl_check in output[ptr:]:
|
||||
continue_select = False
|
||||
else:
|
||||
ptr = len(output) - len(runlvl_check)
|
||||
break
|
||||
except socket.error, e:
|
||||
if e.errno != errno.EWOULDBLOCK:
|
||||
|
|
|
@ -45,14 +45,12 @@ volume:
|
|||
image_path = '/Users/anders/Workspace/cloud/images/debian-wheezy-amd64-141130.vmdk'
|
||||
|
||||
image = VirtualBoxImage(manifest, image_path)
|
||||
output = None
|
||||
try:
|
||||
instance = VirtualBoxInstance('unpartitioned_extlinux', image)
|
||||
try:
|
||||
instance.create()
|
||||
try:
|
||||
instance.boot()
|
||||
output = instance.get_console_output()
|
||||
# tools.reachable_with_ssh(instance)
|
||||
finally:
|
||||
instance.shutdown()
|
||||
|
|
Loading…
Add table
Reference in a new issue