[Pkg-uml-commit] r97 - trunk/src/umlrun

Stefano Melchior stex-guest at costa.debian.org
Fri May 26 12:21:30 UTC 2006


Author: stex-guest
Date: 2006-05-26 12:21:29 +0000 (Fri, 26 May 2006)
New Revision: 97

Added:
   trunk/src/umlrun/Makefile
   trunk/src/umlrun/README
   trunk/src/umlrun/TODO
   trunk/src/umlrun/rootstrap
   trunk/src/umlrun/umli
   trunk/src/umlrun/umlrun
   trunk/src/umlrun/umlrun-server
   trunk/src/umlrun/umlrun.py
Log:
Added umlrun content

Added: trunk/src/umlrun/Makefile
===================================================================
--- trunk/src/umlrun/Makefile	2006-05-26 12:19:22 UTC (rev 96)
+++ trunk/src/umlrun/Makefile	2006-05-26 12:21:29 UTC (rev 97)
@@ -0,0 +1,13 @@
+prefix?=/usr
+
+all:
+
+install:
+	install -d $(DESTDIR)$(prefix)/bin $(DESTDIR)$(prefix)/sbin
+	install -m 755 umlrun umli $(DESTDIR)$(prefix)/bin
+	install -m 755 umlrun-server $(DESTDIR)$(prefix)/sbin
+	install -d $(DESTDIR)$(prefix)/lib/rootstrap/modules
+	install -m 755 rootstrap $(DESTDIR)$(prefix)/lib/rootstrap/modules/umlrun
+	install -d $(DESTDIR)$(prefix)/share/umlrun/scripts
+	install -d $(DESTDIR)$(prefix)/lib/site-python
+	install -m 644 umlrun.py $(DESTDIR)$(prefix)/lib/site-python

Added: trunk/src/umlrun/README
===================================================================
--- trunk/src/umlrun/README	2006-05-26 12:19:22 UTC (rev 96)
+++ trunk/src/umlrun/README	2006-05-26 12:21:29 UTC (rev 97)
@@ -0,0 +1,49 @@
+Quick start
+-----------
+
+In order to run umlrun, you must prepare a UML root filesystem which
+has umlrun-uml installed.  The easiest way to do this is typically
+with rootstrap, especially if you will be doing it multiple times, but
+any root filesystem should work fine.
+
+1. apt-get install rootstrap
+
+2. Edit /etc/rootstrap/rootstrap.conf
+
+   2.1 Configure networking parameters, etc.
+
+   2.2a If building a release which includes umlrun-uml (currently
+        only unstable), it can be automatically installed by adding
+        the following to rootstrap.conf:
+
+         [debian]
+         include=umlrun-uml
+
+   2.2b Otherwise, install umlrun-uml's dependencies so that it can be
+        installed easily by hand.  Currently, this is only Python, but
+        check the latest umlrun-uml package to be sure.
+
+         [debian]
+         include=python
+
+3. rootstrap umlrun.ext2
+
+4. If umlrun-uml could not be automatically installed, install it by hand:
+
+   4.1 Downoad umlrun-uml.deb into /tmp on host
+
+   4.2 linux ubd0=umlrun.ext2
+
+   4.3 [within UML]
+       mount -t hostfs hostfs /mnt
+       dpkg -i /mnt/tmp/umlrun-uml.deb
+
+   4.4 halt
+
+To execute a command within UML:
+
+umlrun --umlargs "...<UML options>..." <commands>
+
+For example:
+
+umlrun --umlargs "ubd0=umlrun.ext2 eth0=slirp" apt-get install build-essential

Added: trunk/src/umlrun/TODO
===================================================================
--- trunk/src/umlrun/TODO	2006-05-26 12:19:22 UTC (rev 96)
+++ trunk/src/umlrun/TODO	2006-05-26 12:21:29 UTC (rev 97)
@@ -0,0 +1,2 @@
+- option to specify COW
+- documentation

Added: trunk/src/umlrun/rootstrap
===================================================================
--- trunk/src/umlrun/rootstrap	2006-05-26 12:19:22 UTC (rev 96)
+++ trunk/src/umlrun/rootstrap	2006-05-26 12:21:29 UTC (rev 97)
@@ -0,0 +1,23 @@
+#!/bin/sh -e
+
+mv $TARGET/sbin/start-stop-daemon $TARGET/sbin/start-stop-daemon.real
+ln -s /bin/true $TARGET/sbin/start-stop-daemon
+
+RELEASE=$(cat $TARGET/etc/debian_version)
+if [ "$RELEASE" = "testing/unstable" ] || [ "$RELEASE" -gt 3.0 ]; then
+    chroot $TARGET apt-get update
+    chroot $TARGET apt-get -y install umlrun-uml
+else
+    # umlrun is not available in woody and earlier
+    SOURCES=$(tempfile -d $TARGET/tmp)
+    cp $TARGET/etc/apt/sources.list $SOURCES
+    echo "deb http://people.debian.org/~mdz/umlrun ./" >> $SOURCES
+    CHROOT_SOURCES=$(echo $SOURCES | sed -e "s,^$TARGET,,")
+    APT_GET="apt-get -o Dir::Etc::sourcelist=$CHROOT_SOURCES -y"
+    chroot $TARGET $APT_GET update
+    chroot $TARGET $APT_GET install umlrun-uml
+    rm -f $SOURCES
+fi
+
+rm -f $TARGET/sbin/start-stop-daemon
+mv $TARGET/sbin/start-stop-daemon.real $TARGET/sbin/start-stop-daemon


Property changes on: trunk/src/umlrun/rootstrap
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/src/umlrun/umli
===================================================================
--- trunk/src/umlrun/umli	2006-05-26 12:19:22 UTC (rev 96)
+++ trunk/src/umlrun/umli	2006-05-26 12:21:29 UTC (rev 97)
@@ -0,0 +1,19 @@
+#!/usr/bin/python
+
+import umlrun
+import sys
+import signal
+
+umli = umlrun.UMLI(sys.argv[1:])
+
+def cleanup(signum, stackframe):
+    umli.halt()
+    # Write the message after we do it, because the terminal might have
+    # been in raw mode
+    sys.stderr.write('\numli: Caught fatal signal, halting UML\n')
+    sys.exit(1)
+
+for sig in (signal.SIGHUP, signal.SIGINT, signal.SIGTERM, signal.SIGQUIT):
+    signal.signal(sig, cleanup)
+
+umli.run()


Property changes on: trunk/src/umlrun/umli
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/src/umlrun/umlrun
===================================================================
--- trunk/src/umlrun/umlrun	2006-05-26 12:19:22 UTC (rev 96)
+++ trunk/src/umlrun/umlrun	2006-05-26 12:21:29 UTC (rev 97)
@@ -0,0 +1,54 @@
+#!/usr/bin/python
+
+import sys
+import os
+import getopt
+import umlrun
+
+propagate_env = ['http_proxy', 'ftp_proxy','DEBEMAIL']
+
+def usage(exitcode):
+    sys.stderr.write('Usage: umlrun --umlargs=uml_args [-v] [command]\n')
+    sys.exit(exitcode)
+
+def main():
+    optlist, args = getopt.getopt(sys.argv[1:], 'hu:vie:',
+                                  ['help',
+                                   'umlargs=',
+                                   'verbose',
+                                   'interactive',
+                                   'environment'])
+
+    umlargs = []
+    envvars = {}
+    verbose = 0
+    interactive = 0
+    for opt, arg in optlist:
+        if opt in ('-h', '--help'):
+            usage(0)
+        elif opt in ('-u', '--umlargs'):
+            umlargs.append(arg)
+        elif opt in ('-v', '--verbose'):
+            verbose += 1
+        elif opt in ('-i', '--interactive'):
+            interactive = 1
+        elif opt in ('-e', '--environment'):
+            name, value = arg.split('=', 1)
+            envvars[name] = value
+
+    uml = umlrun.UML()
+
+    uml.start(umlargs=umlargs, verbose=verbose, interactive=interactive)
+    try:
+        for name in propagate_env:
+            value = envvars.get(name,os.getenv(name))
+
+            if value != None:
+                uml.setenv(name, value)
+
+        uml.shellcommand(' '.join(args))
+    finally:
+        uml.shutdown()
+
+if __name__ == '__main__':
+    main()


Property changes on: trunk/src/umlrun/umlrun
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/src/umlrun/umlrun-server
===================================================================
--- trunk/src/umlrun/umlrun-server	2006-05-26 12:19:22 UTC (rev 96)
+++ trunk/src/umlrun/umlrun-server	2006-05-26 12:21:29 UTC (rev 97)
@@ -0,0 +1,129 @@
+#!/usr/bin/python
+
+import os
+import sys
+import fcntl
+import tty
+import termios
+
+hostfsdir = '/host'
+
+def main():
+    try:
+        channels = None
+        for arg in open('/proc/cmdline').read().split():
+            argsplit = arg.split('=')
+            if len(argsplit) > 1 and argsplit[0] == 'umlrun':
+                channels = argsplit[1].split(',')
+
+        if not channels:
+            print "No umlrun invocation detected, proceeding with normal startup"
+            cleanup()
+            sys.exit(0)
+
+        controlchan = open(umldev_to_devpath(channels[0]),'r+')
+        datafd = os.open(umldev_to_devpath(channels[1]), os.O_RDWR)
+
+        # Disable echo
+        tcattr = termios.tcgetattr(controlchan.fileno())
+        tcattr[3] = tcattr[3] & ~termios.ECHO
+        termios.tcsetattr(controlchan.fileno(), termios.TCSANOW, tcattr)
+
+        # set close-on-exec
+        fcntl.fcntl(controlchan.fileno(), fcntl.F_SETFD, 1)
+        
+        controlchan.write('umlrun-2\n')
+
+        SUCCESS, FAILURE = 0, 1
+        while 1:
+            line = controlchan.readline()
+            if not line:
+                break
+
+            command,args = line[:-1].split(' ', 1)
+            if not command:
+                break
+
+            status, text = FAILURE, 'Internal error'
+            if command == 'EXEC' or command == 'EXEC_INTERACTIVE':
+                if command == 'EXEC':
+                    execstatus = execute_shellcmd(args, datafd)
+                else:
+                    execstatus = execute_shellcmd(args, datafd, 1)
+                if execstatus == 0:
+                    status, text = SUCCESS, 'Command executed successfully'
+                else:
+                    status, text = FAILURE, 'Command exited with status %d' % execstatus
+            elif command == 'SHUTDOWN':
+                controlchan.write('200 Shutting down\n')
+                os.system('shutdown -h -t1 now')
+                break
+            elif command == 'FASTSHUTDOWN':
+                controlchan.write('200 Shutting down\n')
+                os.system('halt -n -f')
+                break
+            elif command == 'SETENV':
+                name, value = args.split(' ', 1)
+                os.putenv(name, value)
+                status, text = SUCCESS, 'Environment variable set'
+            elif command == 'MOUNT_HOST':
+                if os.getenv('UMLRUN_HOSTMOUNT'):
+                    status, text = SUCCESS, 'Host already mounted'
+                else:
+                    cwd = args
+                    if not os.path.isdir(hostfsdir):
+                        os.makedirs(hostfsdir)
+                    status = os.system('mount -t hostfs hostfs ' + hostfsdir)
+                    if status != 0:
+                        status, text = 'mount command gave status %d' % status
+
+                    os.putenv('UMLRUN_HOSTMOUNT', hostfsdir)
+                    os.putenv('UMLRUN_HOSTCWD', hostfsdir + cwd)
+                    status, text = SUCCESS, 'Host mounted'
+            elif command == 'ADDUSER':
+                username, uid = args.split(' ', 1)
+                ret = os.system('adduser --uid %s %s' % (username, uid))
+                if ret != 0:
+                    status, text = FAILURE, 'adduser command gave status %d' % ret
+            else:
+                status, text = FAILURE, 'Unrecognized command %s' % command
+
+            if status == SUCCESS:
+                response = '200 ' + text
+            else:
+                response = '400 ' + text
+
+            controlchan.write(response + '\n')
+
+    finally:
+        cleanup()
+
+def cleanup():
+    os.chdir('/')
+
+def umldev_to_devpath(dev):
+    if dev[:3] == 'ssl':
+        return '/dev/ttyS' + dev[3:]
+    if dev[:3] == 'con':
+        return '/dev/tty' + dev[3:]
+    raise 'Unrecognized UML device: ' + dev
+
+def execute_shellcmd(cmd, iofd, interactive=0):
+    pid = os.fork()
+    if pid == 0:
+        if interactive:
+            os.setsid()
+            fcntl.ioctl(iofd, tty.TIOCSCTTY)
+        os.dup2(iofd, 0)
+        os.dup2(iofd, 1)
+        os.dup2(iofd, 2)
+        os.execl('/bin/sh','sh','-c',cmd)
+        sys.exit(1)
+    else:
+        status = os.waitpid(pid,0)
+        if os.WIFEXITED(status[1]):
+            return os.WEXITSTATUS(status[1])
+        return status[1]
+
+if __name__ == '__main__':
+    main()


Property changes on: trunk/src/umlrun/umlrun-server
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/src/umlrun/umlrun.py
===================================================================
--- trunk/src/umlrun/umlrun.py	2006-05-26 12:19:22 UTC (rev 96)
+++ trunk/src/umlrun/umlrun.py	2006-05-26 12:21:29 UTC (rev 97)
@@ -0,0 +1,426 @@
+import sys
+import exceptions
+import time
+import os
+import signal
+import termios
+import getopt
+import ConfigParser
+import pwd
+
+class UML:
+    def __init__(self):
+        self.umid = 'umlrun-%d' % os.getpid()
+        self.verbose = False
+        self.umlpid = None
+
+    def __del__(self):
+        if self.is_running():
+            self.halt()
+
+    def start(self, umlargs, verbose=None, timeout=60, interactive='auto'):
+        uml = ['linux',
+               'umid=' + self.umid]
+        if verbose is not None:
+            self.verbose = verbose
+        self.saved_ttyattr = None
+        if sys.stdout.isatty():
+            self.saved_ttyattr = termios.tcgetattr(sys.stdout.fileno())
+            
+        if not self.verbose:
+            uml.append('quiet')
+
+        uml.extend(umlargs)
+
+        self.umlpid = os.fork()
+        if self.umlpid == 0:
+            os.execvp(uml[0], uml)
+            sys.exit(1)
+
+        self.log("Waiting for UML to start up...")
+        timeleft = timeout
+        while timeleft > 0:
+            if self.wait(nohang=True) is not None:
+                raise Error('UML exited unexpectedly')
+
+            try:
+                self.mconsole('version')
+                break
+            except MConsoleConnectionFailed:
+                pass
+            time.sleep(1)
+            timeleft -= 1
+        if timeleft <= 0:
+            raise TimeoutError('UML did not start up within %d seconds' % timeout)
+
+        self.log("UML startup OK (pid %s)" % self.umlpid)
+
+    def is_running(self):
+        return hasattr(self, 'umlpid') and self.umlpid != None
+
+    def wait(self, nohang=False):
+        if not self.is_running():
+            return None
+
+        if nohang:
+            flags = os.WNOHANG
+        else:
+            flags = 0
+        pid, status = os.waitpid(self.umlpid, flags)
+        if pid == self.umlpid:
+            self.umlpid = None
+            self.restoretty()
+            return status
+        return None
+        
+    def run(self):
+        self.start()
+        self.wait()
+
+    def mconsole(self, command):
+        fd = os.popen('uml_mconsole %s %s 2>/dev/null' % (self.umid, command))
+        output = fd.read().rstrip()
+        status = fd.close()
+        if status != None or len(output) == 0:
+            raise MConsoleConnectionFailed()
+
+        if ' ' in output:
+            status, rest = output.split(' ', 1)
+        else:
+            status, rest = output, None
+
+        if status != 'OK':
+            raise MConsoleError(status, rest)
+
+        if rest:
+            return rest
+        return True
+
+    def halt(self, timeout=60):
+        if not self.is_running():
+            return
+
+        self.log("Halting UML via mconsole")
+        try:
+            self.mconsole('halt')
+        except:
+            self.kill()
+
+        return self.wait()
+
+    def kill(self, timeout=2):
+        self.log("Killing UML with SIGTERM")
+        os.kill(self.umlpid, signal.SIGTERM)
+        timeleft = timeout
+        while timeleft > 0:
+            if self.wait(nohang=True) is not None:
+                return
+            timeleft -= 1
+
+        if timeleft <= 0:
+            self.log("Killing UML with SIGKILL")
+            os.kill(self.umlpid, signal.SIGKILL)
+
+        return self.wait()
+
+    def restoretty(self):
+        if self.saved_ttyattr:
+            termios.tcsetattr(sys.stdout.fileno(), termios.TCSANOW, self.saved_ttyattr)
+
+    def log(self, msg):
+        if self.verbose:
+            sys.stderr.write(msg + '\r\n')
+
+class UMLRun(UML):
+    def __init__(self):
+        UML.__init__(self)
+        self.control = None
+        self.interactive = None
+        self.version = None
+
+    def start(self, umlargs, verbose=0, timeout=60, interactive='auto'):
+        if interactive == 'auto':
+            if sys.stdin.isatty() and sys.stdout.isatty():
+                self.interactive = 1
+            else:
+                self.interactive = 0
+        else:
+            self.interactive = interactive
+
+        if self.interactive:
+            ssl1 = 'ssl1=tty:/dev/tty'
+        else:
+            ssl1 = 'ssl1=fd:0,fd:1'
+
+        UML.start(self, umlargs + ['con=pts', 'umlrun=ssl0,ssl1', 'ssl0=pts', ssl1],
+                  verbose, timeout)
+
+        control_pts = None
+        timeleft = timeout
+        self.log("Waiting for umlrun-server to start up...")
+        while timeleft > 0:
+            control_pts = self._ptspath('ssl0')
+            if control_pts:
+                break
+
+            time.sleep(1)
+            timeleft -= 1
+        if timeleft <= 0:
+            raise TimeoutError('umlrun-server did not start up within %d seconds' % timeout)
+
+        self.log("umlrun-server startup OK")
+
+        self.control = open(control_pts, 'r+')
+
+        self.version = self.control.readline().rstrip()
+        self.log('umlrun-server version is ' + self.version)
+
+    def shellcommand(self, args):
+        if self.interactive:
+            self._command('exec_interactive', args)
+        else:
+            self._command('exec', args)
+
+    def setenv(self, name, value=None):
+        if value == None:
+            value = os.getenv(name)
+            if value == None:
+                return
+        self._command('setenv', name, value)
+
+    def mounthost(self):
+        if self.version < 2:
+            raise InterfaceUnsupported('mounthost')
+
+        self._command('mount_host', os.getcwd())
+
+    def shutdown(self, timeout=60):
+        killed = 0
+        
+        if self.control:
+            self.log("Waiting for UML to shut down...")
+            self._command('shutdown')
+            self.control.close()
+            self.wait()
+        else:
+            UML.halt(self, timeout)
+
+    def fast_shutdown(self):
+        if self.version < 3:
+            raise InterfaceUnsupported('fast_shutdown')
+        self._command('FASTSHUTDOWN')
+
+    def adduser(self, username, uid):
+        if self.version < 3:
+            raise InterfaceUnsupported('adduser')
+        self._command('adduser', username, uid)
+
+    def _command(self, cmd, *args):
+        self.control.write('%s %s\n' % (cmd.upper(), ' '.join(args)))
+        line = self.control.readline()[:-1]
+        status, result = line.split(' ', 1)
+        self.log('_command(%s, %s) -> %s %s' % (cmd, ', '.join(args), status, result))
+        if int(status) != 200:
+            raise CommandError(cmd, status, result)
+
+    def _ptspath(self, dev):
+        result = self.mconsole('config ' + dev)
+        if result == 'pts':
+            return None
+        elif result[:4] == 'pts:':
+            return result[4:]
+        else:
+            raise Error('Unexpected result from mconsole config query: ' + result)
+
+
+class UMLI(UML):
+    def __init__(self, argv):
+        UML.__init__(self)
+
+        # Choose a default console mode based on the environment
+        if os.getenv('STY'):
+            self.consoleMode = 'screen'
+        elif os.getenv('DISPLAY'):
+            self.consoleMode = 'xterm'
+        else:
+            self.consoleMode = 'console1'
+
+        self.root = None
+        self.session = None
+        self.modify = False
+
+        self.config = ConfigParser.ConfigParser()
+        self.config.read(('/etc/umli.conf',os.path.expanduser('~/.umli.conf')))
+
+        opts, args = getopt.getopt(argv, 'c:r:xs:vm',
+                                   ['console=',
+                                    'root=',
+                                    'session=',
+                                    'verbose',
+                                    'modify'])
+
+        for opt, arg in opts:
+            if opt == '-x':
+                self.consoleMode = 'xterm'
+            elif opt in ('-c', '--console'):
+                self.consoleMode = arg
+            elif opt in ('-r', '--root'):
+                self.root = arg
+            elif opt in ('-s', '--session'):
+                self.session = arg
+            elif opt in ('-v', '--verbose'):
+                self.verbose = True
+            elif opt in ('-m', '--modify'):
+                self.modify = True
+
+        if 'single' in args:
+            self.consoleMode = 'console0'
+
+
+        self.cmdline = self.consoleModeArgs() + self.rootArgs() + self.globalArgs() + args
+
+    def __del__(self):
+        if hasattr(self, 'cow') and hasattr(self, 'removeCow') and self.removeCow:
+            try:
+                os.unlink(self.cow)
+            except:
+                pass
+        UML.__del__(self)
+
+    def start(self):
+        UML.start(self, self.cmdline)
+
+        if self.consoleMode == 'screen':
+            activateConsoles = ['con%d' % x for x in range(1,7)]
+            while self.is_running() and len(activateConsoles) > 0:
+                time.sleep(1)
+
+                for con in activateConsoles:
+                    channel = self.mconsole('config %s' % con)
+                    if channel and channel.startswith('pts:'):
+                        device = channel.split(':', 1)[1]
+                        if os.spawnlp(os.P_WAIT, 'screen', 'screen', device) == 0:
+                            activateConsoles.remove(con)
+
+    def consoleModeArgs(self):
+        if self.consoleMode == 'console1':
+            # Default mode of operation:
+            # get output from console 0 (initial console), no input
+            # I/O from/to user on console 1 (VC #1)
+            return ['con0=null,fd:1', 'con1=tty:/dev/tty', 'con=none']
+        if self.consoleMode == 'console0':
+            # Only console 0, for single-user
+            return ['con0=tty:/dev/tty','con=none']
+        if self.consoleMode == 'xterm':
+            # Each console in its own xterm
+            return ['con=xterm']
+        if self.consoleMode == 'screen':
+            # Initial console on tty, other consoles each on their own screen
+            return ['con0=tty:/dev/tty','con=pts']
+        raise RuntimeError('Unrecognized console mode: %s' % self.consoleMode)
+
+    def rootArgs(self):
+        root = self.root
+        if root is not None:
+            # Search path for root fs
+            if self.config.has_option('umli', 'rootpath'):
+                for rootdir in self.config.get('umli', 'rootpath').split(os.pathsep):
+                    testroot = os.path.join(rootdir, self.root)
+                    if os.path.exists(testroot):
+                        root = testroot
+                        break
+
+            while os.path.isdir(root):
+                root = os.path.join(root, 'default')
+
+            # Collapse symlinks
+            root = os.path.realpath(root)
+
+        if self.modify:
+            self.cow = None
+        else:
+            sessionDir = self.userSessionDir()
+
+            if self.session is None:
+                self.cow = os.path.join(sessionDir, 'umli-%s.cow' % os.getpid())
+                self.removeCow = True
+            else:
+                self.cow = os.path.join(sessionDir,'%s.cow' % self.session)
+                self.removeCow = False
+
+        ret = []
+        if self.cow:
+            ret.append('root=/dev/ubd0')
+            if os.path.exists(self.cow):
+                ret.append('ubd0=%s' % self.cow)
+            elif root is not None:
+                ret.append('ubd0=%s,%s' % (self.cow, root))
+            else:
+                raise Error('Session "%s" not found' % self.session)
+        elif root is not None:
+            ret.append('root=/dev/ubd0')
+            ret.append('ubd0=%s' % root)
+
+        return ret
+
+    def globalArgs(self):
+        if self.config.has_option('umli', 'args'):
+            return self.config.get('umli', 'args').split()
+        return []
+
+    def userSessionDir(self):
+        sessionDir = '' # cwd
+        if self.config.has_option('umli', 'sessiondir'):
+            sessionDir = self.config.get('umli', 'sessiondir')
+        user = pwd.getpwuid(os.getuid())[0]
+        userSessionDir = os.path.join(sessionDir, user)
+        if os.path.isdir(userSessionDir):
+            stat = os.stat(userSessionDir)
+            if stat.st_uid != os.getuid() or stat.st_mode & 002:
+                raise RuntimeError('Suspicious ownership or permissions on directory %s' % userSessionDir)
+            return userSessionDir
+        os.mkdir(userSessionDir, 0770)
+        return userSessionDir
+        
+class Error(exceptions.RuntimeError):
+    pass
+
+
+class CommandError(Error):
+    def __init__(self, command, status, result):
+        self.command = command
+        self.status = status
+        self.result = result
+        Error.__init__(self, command + ': ' + status + ' ' + result)
+
+class InterfaceUnsupported(Error):
+    def __init__(self, command):
+        self.command = command
+        Error.__init__(self, 'Interface not supported by umlrun-server')
+
+class TimeoutError(Error):
+    def __init__(self, text):
+        Error.__init__(self, text)
+
+class MConsoleConnectionFailed(Error):
+    pass
+
+class MConsoleError(Error):
+    def __init__(self, status, result):
+        Error.__init__(self, 'mconsole: ' + status + ' ' + result)
+
+# if __name__ == '__main__':
+#     # simple self-test
+#     uml = UMLRun()
+#     try:
+#         uml.start(umlargs=['eth0=tuntap,,,192.168.10.1',
+#                            'ubd0=/tmp/cow,/home/mdz/.umldeb/images/unstable/image',
+#                            'con=xterm'],
+#                   verbose=0,interactive=0)
+#         uml.setenv('FOO', 'bar')
+#         #print "Executing a shell command:"
+#         uml.shellcommand('echo "Hello, world! (FOO=$FOO)"')
+#         uml.shellcommand('/bin/bash -i')
+#     finally:
+#         uml.halt()
+#         os.remove('/tmp/cow')




More information about the Pkg-uml-commit mailing list