예제 #1
0
 def _write(self, key, data):
     path = self.prependPath(key)
     try:
         xshandle().write(self.transaction, path, data)
     except RuntimeError, ex:
         raise RuntimeError(ex.args[0], ('%s, while writing %s : %s' %
                                         (ex.args[1], path, str(data))))
예제 #2
0
 def _write(self, key, data):
     path = self.prependPath(key)
     try:
         xshandle().write(self.transaction, path, data)
     except RuntimeError, ex:
         raise RuntimeError(ex.args[0],
                            ('%s, while writing %s : %s' %
                             (ex.args[1], path, str(data))))
예제 #3
0
    def set_permissions(self, *args):
        if len(args) == 0:
            raise TypeError
        elif isinstance(args[0], str):
            self.callRebased(args[0], self.set_permissions, *args[1:])
        else:
            if not self.path:
                raise RuntimeError('Cannot set permissions on the root')

            xshandle().set_permissions(self.transaction, self.path, list(args))
예제 #4
0
 def remove(self, *args):
     """If no arguments are given, remove this transaction's path.
     Otherwise, treat each argument as a subpath to this transaction's
     path, and remove each of those instead.
     """
     if len(args) == 0:
         xshandle().rm(self.transaction, self.path)
     else:
         for key in args:
             self._remove(key)
예제 #5
0
 def remove(self, *args):
     """If no arguments are given, remove this transaction's path.
     Otherwise, treat each argument as a subpath to this transaction's
     path, and remove each of those instead.
     """
     if len(args) == 0:
         xshandle().rm(self.transaction, self.path)
     else:
         for key in args:
             self._remove(key)
예제 #6
0
 def list_recursive_(self, subdir, keys):
     ret = []
     for key in keys:
         new_subdir = subdir + "/" + key
         l = xshandle().ls(self.transaction, new_subdir)
         if l:
             ret.append([key, self.list_recursive_(new_subdir, l)])
         else:
             ret.append([key, xshandle().read(self.transaction, new_subdir)])
     return ret
예제 #7
0
 def list_recursive_(self, subdir, keys):
     ret = []
     for key in keys:
         new_subdir = subdir + "/" + key
         l = xshandle().ls(self.transaction, new_subdir)
         if l:
             ret.append([key, self.list_recursive_(new_subdir, l)])
         else:
             ret.append(
                 [key, xshandle().read(self.transaction, new_subdir)])
     return ret
예제 #8
0
    def set_permissions(self, *args):
        if len(args) == 0:
            raise TypeError
        elif isinstance(args[0], str):
            self.callRebased(args[0], self.set_permissions, *args[1:])
        else:
            if not self.path:
                raise RuntimeError('Cannot set permissions on the root')

            xshandle().set_permissions(self.transaction, self.path,
                                       list(args))
예제 #9
0
 def _read(self, key):
     path = self.prependPath(key)
     try:
         return xshandle().read(self.transaction, path)
     except RuntimeError, ex:
         raise RuntimeError(ex.args[0],
                            '%s, while reading %s' % (ex.args[1], path))
예제 #10
0
 def abort(self):
     if not self.in_transaction:
         return True
     self.in_transaction = False
     rc = xshandle().transaction_end(self.transaction, True)
     self.transaction = "0"
     return rc
예제 #11
0
 def commit(self):
     if not self.in_transaction:
         raise RuntimeError
     self.in_transaction = False
     rc = xshandle().transaction_end(self.transaction, False)
     self.transaction = "0"
     return rc
예제 #12
0
 def commit(self):
     if not self.in_transaction:
         raise RuntimeError
     self.in_transaction = False
     rc = xshandle().transaction_end(self.transaction, False)
     self.transaction = "0"
     return rc
예제 #13
0
 def abort(self):
     if not self.in_transaction:
         return True
     self.in_transaction = False
     rc = xshandle().transaction_end(self.transaction, True)
     self.transaction = "0"
     return rc
예제 #14
0
 def _read(self, key):
     path = self.prependPath(key)
     try:
         return xshandle().read(self.transaction, path)
     except RuntimeError, ex:
         raise RuntimeError(ex.args[0],
                            '%s, while reading %s' % (ex.args[1], path))
예제 #15
0
 def _get_permissions(self, key):
     path = self.prependPath(key)
     try:
         return xshandle().get_permissions(self.transaction, path)
     except RuntimeError, ex:
         raise RuntimeError(
             ex.args[0],
             '%s, while getting permissions from %s' % (ex.args[1], path))
예제 #16
0
 def _get_permissions(self, key):
     path = self.prependPath(key)
     try:
         return xshandle().get_permissions(self.transaction, path)
     except RuntimeError, ex:
         raise RuntimeError(ex.args[0],
                            '%s, while getting permissions from %s' %
                            (ex.args[1], path))
예제 #17
0
 def __init__(self, path = ""):
     assert path is not None
     
     self.in_transaction = False # Set this temporarily -- if this
                                 # constructor fails, then we need to
                                 # protect __del__.
     self.path = path.rstrip("/")
     self.transaction = xshandle().transaction_start()
     self.in_transaction = True
예제 #18
0
    def __init__(self, path=""):

        self.in_transaction = False  # Set this temporarily -- if this
        # constructor fails, then we need to
        # protect __del__.

        assert path is not None
        self.path = path.rstrip("/")
        self.transaction = xshandle().transaction_start()
        self.in_transaction = True
예제 #19
0
    def __init__(self, receive_prefix = "data/host", send_prefix = "data/guest", data_prefix = "vm-data", *args, **kwargs): # pylint: disable=C0301
        """Initialize a communication "bus" with the Xen Hypervisor.

        ### Description

        Sets up watches on paths we'll be receiving data on in xenstore and 
        initializes pathing information used elsewhere.

        """

        super(XenCommunicator, self).__init__(*args, **kwargs)

        self._receive_prefix = receive_prefix
        self._send_prefix = send_prefix
        self._network_prefix = data_prefix + "/networking"
        self._hostname_prefix = data_prefix + "/hostname"

        self._queue = Queue.Queue()

        self.xs = xs.xshandle() # pylint: disable=C0103

        def xs_watch(path):
            logger.info("Received a watch even on %s", path)

            if path in [ self._receive_prefix, data_prefix ]:
                return True

            transaction = self.xs.transaction_start()
            message = self.xs.read(transaction, path)
            self.xs.transaction_end(transaction)

            logger.info("Received message, %s", message)

            self._queue.put((path, message))

            transaction = self.xs.transaction_start()
            message = self.xs.rm(transaction, path)
            self.xs.transaction_end(transaction)

            return True

        self.watches = []
        self.watches.append(xswatch(self._receive_prefix, xs_watch))

        transaction = self.xs.transaction_start()
        entries = self.xs.ls(transaction, self._receive_prefix)
        self.xs.transaction_end(transaction)

        logger.debug("Missed messages: %s", entries)

        if entries is not None:
            for path in [ self._receive_prefix + "/" + entry for entry in entries ]: # pylint: disable=C0301
                xs_watch(path)
예제 #20
0
def watchStart():
    global watchThread
    global xs

    xslock.acquire()
    try:
        if watchThread:
            return
        xs = xshandle()
        watchThread = threading.Thread(name="Watcher", target=watchMain)
        watchThread.setDaemon(True)
        watchThread.start()
    finally:
        xslock.release()
예제 #21
0
def watchStart():
    global watchThread
    global xs
    
    xslock.acquire()
    try:
        if watchThread:
            return
        xs = xshandle()
        watchThread = threading.Thread(name="Watcher", target=watchMain)
        watchThread.setDaemon(True)
        watchThread.start()
    finally:
        xslock.release()
예제 #22
0
 def read(self, *args):
     """If no arguments are given, return the value at this transaction's
     path.  If one argument is given, treat that argument as a subpath to
     this transaction's path, and return the value at that path.
     Otherwise, treat each argument as a subpath to this transaction's
     path, and return a list composed of the values at each of those
     instead.
     """
     if len(args) == 0:
         return xshandle().read(self.transaction, self.path)
     if len(args) == 1:
         return self._read(args[0])
     ret = []
     for key in args:
         ret.append(self._read(key))
     return ret
예제 #23
0
 def read(self, *args):
     """If no arguments are given, return the value at this transaction's
     path.  If one argument is given, treat that argument as a subpath to
     this transaction's path, and return the value at that path.
     Otherwise, treat each argument as a subpath to this transaction's
     path, and return a list composed of the values at each of those
     instead.
     """
     if len(args) == 0:
         return xshandle().read(self.transaction, self.path)
     if len(args) == 1:
         return self._read(args[0])
     ret = []
     for key in args:
         ret.append(self._read(key))
     return ret
예제 #24
0
 def list(self, *args):
     """If no arguments are given, list this transaction's path, returning
     the entries therein, or the empty list if no entries are found.
     Otherwise, treat each argument as a subpath to this transaction's
     path, and return the cumulative listing of each of those instead.
     """
     if len(args) == 0:
         ret = xshandle().ls(self.transaction, self.path)
         if ret is None:
             return []
         else:
             return ret
     else:
         ret = []
         for key in args:
             ret.extend(self._list(key))
         return ret
예제 #25
0
 def list(self, *args):
     """If no arguments are given, list this transaction's path, returning
     the entries therein, or the empty list if no entries are found.
     Otherwise, treat each argument as a subpath to this transaction's
     path, and return the cumulative listing of each of those instead.
     """
     if len(args) == 0:
         ret = xshandle().ls(self.transaction, self.path)
         if ret is None:
             return []
         else:
             return ret
     else:
         ret = []
         for key in args:
             ret.extend(self._list(key))
         return ret
예제 #26
0
 def _remove(self, key):
     path = self.prependPath(key)
     return xshandle().rm(self.transaction, path)
예제 #27
0
 def _list(self, key):
     path = self.prependPath(key)
     l = xshandle().ls(self.transaction, path)
     if l:
         return map(lambda x: key + "/" + x, l)
     return []
예제 #28
0
 def mkdir(self, *args):
     if len(args) == 0:
         xshandle().mkdir(self.transaction, self.path)
     else:
         for key in args:
             xshandle().mkdir(self.transaction, self.prependPath(key))
예제 #29
0
 def __del__(self):
     if self.in_transaction:
         xshandle().transaction_end(self.transaction, True)
예제 #30
0
 def mkdir(self, *args):
     if len(args) == 0:
         xshandle().mkdir(self.transaction, self.path)
     else:
         for key in args:
             xshandle().mkdir(self.transaction, self.prependPath(key))
예제 #31
0
 def _remove(self, key):
     path = self.prependPath(key)
     return xshandle().rm(self.transaction, path)
예제 #32
0
 def _list(self, key):
     path = self.prependPath(key)
     l = xshandle().ls(self.transaction, path)
     if l:
         return map(lambda x: key + "/" + x, l)
     return []