Beispiel #1
0
    def start(self):
        debugmsg(2, "xVBOXInstance::start()")
        global WORKDIR
        self.vmname = self.image

        if self.console_support == 'True':
            p = re.compile('\s+', re.UNICODE)
            pipe_name = p.sub("_", self.vmname)
            if sys.platform.startswith('win'):
                pipe_name = r'\\.\pipe\VBOX\%s' % pipe_name
            elif os.path.exists(WORKDIR):
                pipe_name = WORKDIR + os.sep + "pipe_%s" % pipe_name
            else:
                pipe_name = "/tmp/pipe_%s" % pipe_name
        else:
            pipe_name = None

        started = self.vbc.start(self.vmname, self.nics, self.udp, self.capture, self.netcard, self.first_nic_managed, self.headless_mode, pipe_name)
        
        if started:
            self.vbc.setName(self.name)

        if started and self.console_support == 'True' and int(self.console) and self.console_telnet_server == 'True':

            global IP
            if sys.platform.startswith('win'):
                try:
                    self.pipe = open(pipe_name, 'a+b')
                except:
                    return started
                self.pipeThread = PipeProxy(self.vmname, msvcrt.get_osfhandle(self.pipe.fileno()), IP, int(self.console))
                self.pipeThread.setDaemon(True)
                self.pipeThread.start()
            else:
                try:
                    self.pipe = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
                    self.pipe.connect(pipe_name)
                except socket.error, err:
                    print "connection to pipe %s failed -> %s" % (pipe_name, err[1])
                    return started

                self.pipeThread = PipeProxy(self.vmname, self.pipe, IP, int(self.console))
                self.pipeThread.setDaemon(True)
                self.pipeThread.start()