selectel / pyxs Goto Github PK
View Code? Open in Web Editor NEWPure Python bindings to XenStore
Home Page: http://pyxs.readthedocs.org/
License: GNU Lesser General Public License v3.0
Pure Python bindings to XenStore
Home Page: http://pyxs.readthedocs.org/
License: GNU Lesser General Public License v3.0
Trying to use this in order to interact with xenbus on a guest VM but keep running into an issue where I get the following:
UnexpectedPacket: _Packet(op=2, rq_id=66813, tx_id=0, size=360, payload='{}')
The code I am running is pretty straight forward as I am just trying to read the networking info from a particular mac address.
from pyxs.client import Router, Client
from pyxs.connection import XenBusConnection
router = Router(XenBusConnection())
with Client(router=router) as c:
try:
networking = c[b"vm-data/networking/BC764E20394F"]
print(networking)
except:
pass
Is there something that I need to set that I am missing, or is it that this can only be run on the underlying host and not the guest vm.
Test code:
#!/usr/bin/python3
import pyxs
router = pyxs.Router(pyxs.connection.XenBusConnection())
xs = pyxs.Client(router=router)
try:
xs.connect()
except pyxs.ConnectionError:
print("ConnectionError caught")
Expected output on non-xen VM:
ConnectionError caught
Actual output on non-xen VM:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/share/python3.5/site-packages/pyxs/connection.py", line 199, in __init__
self.fd = os.open(path, os.O_RDWR)
FileNotFoundError: [Errno 2] No such file or directory: '/proc/xen/xenbus'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/share/python3.5/threading.py", line 923, in _bootstrap_inner
self.run()
File "/usr/share/python3.5/threading.py", line 871, in run
self._target(*self._args, **self._kwargs)
File "/usr/share/python3.5/site-packages/pyxs/client.py", line 101, in __call__
self.connection.connect()
File "/usr/share/python3.5/site-packages/pyxs/connection.py", line 52, in connect
self.transport = self.create_transport()
File "/usr/share/python3.5/site-packages/pyxs/connection.py", line 245, in create_transport
return _XenBusTransport(self.path)
File "/usr/share/python3.5/site-packages/pyxs/connection.py", line 202, in __init__
.format(path, e.args))
pyxs.exceptions.ConnectionError: error while opening '/proc/xen/xenbus': (2, 'No such file or directory')
ConnectionError caught
Hi
Could you please update my email (in contributors) to sandeep DOT murthy AT icloud.com. Thanks.
Hi
At the moment there's no method to check whether a given path is a valid Xenstore path - would it be useful to add such a method to pyxs.helpers
? A corresponding exception would be added to pyxs.exceptions
. I am happy to do that, if you think this is useful.
SM
I'm integrating pyxs within a twisted base application.
I hit an issue where the select.select() call within Router.call was interrupted.
This call is within a try block without any except clause. It does not handle interrupted system calls within the select system call.
It seems that any error from select.select() would end up with a select.error exception which is not caught and the Router connection is terminated.
Is it right to catch such exception and re-issue the select.select() call?
The referenced AUTHORS file is missing and the BSD variant is not stated.
The copyright years are also missing for the named copyright holders.
The client.py currently contains a check for setting up a watch on xenstore:
https://github.com/selectel/pyxs/blob/master/pyxs/client.py#L619-L621
if isinstance(self.router.connection, XenBusConnection):
raise PyXSError("using ``Monitor`` over XenBus is not supported",
UserWarning)
This no longer seems to be a valid check with Xen 4.14.x + Linux 5.4 (Ubuntu kernel). I don't know whether the solution to the original problem was in Xen or Linux or with which versions that it started working. This code works in dom0 and domU with that check commented out:
#!/usr/bin/env python3
import sys
import threading
import time
import pyxs
class Watcher(threading.Thread):
def __init__(self):
super().__init__()
self._monitor = None
self._watch = b"/"
self._token = b"token"
self.start()
def run(self):
with pyxs.client.Client(xen_bus_path="/dev/xen/xenbus") as xsc:
self._monitor = xsc.monitor()
self._monitor.watch(self._watch, self._token)
while self._monitor:
print(next(self._monitor.wait(unwatched=True)))
def stop(self):
mtmp = self._monitor
self._monitor = None
# poke an event in queue for anything currently .wait()ing
mtmp.events.put(pyxs.client.Event(self._watch, self._token)),
def main():
watcher = Watcher()
time.sleep(4)
watcher.stop()
watcher.join()
if __name__ == "__main__":
sys.exit(
main()
)
It is possible to bypass the check by instantiating the Monitor()
class directly with an existing Client()
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.