I'm using cassandradb with the datastax python driver on a linux system. Typically when using other databases, I've found that that on unix-compatible systems there's usually a way to establish a connection to the database via a unix socket, instead of using the loopback interface. By connecting via socket, you can bypass the OS networking stack altogether, and the result is usually better performance.
I'm pretty sure that cassandra supports this, not in the least because there is a UnixSocketEndPoint class in the cassandra.connection module of the cassandra pip package. This class is implemented in the github repo, but there's no documentation whatsoever about how to use it. Is anybody using this? How do I go about configuring a unix-socket connection to cassandra with the python API?
I've managed to find the following code snippet, from the cassandra python driver tests on github:
lbp = UnixSocketWhiteListRoundRobinPolicy([UNIX_SOCKET_PATH])
ep = ExecutionProfile(load_balancing_policy=lbp)
endpoint = UnixSocketEndPoint(UNIX_SOCKET_PATH)
cls.cluster = TestCluster(contact_points=[endpoint], execution_profiles={EXEC_PROFILE_DEFAULT: ep})
Which actually is most of what I'm looking for. I'm just confused about how to configure cassandra to listen via socket instead of TCP. Or does cassandra have a default socket path?
Many thanks in advance.
Related
I'm implementing Bluetooth on an embedded device and have a few questions about the BlueZ protocol stack. I'm using BlueZ-4.101 (do not have the option to upgrade to BlueZ-5), and do not have Python available.
Here are my questions after spending some time looking into BlueZ:
Is bluetoothd needed in my situation? As in, is it just a daemon that handles Python dbus messages between user-space and the kernel, or is it more? I've looked through the source and can only find mostly dbus related calls
How does one determine the value of DeviceID in /etc/bluetooth/main.conf? I found these instructions (section 3.4), but they are for a different platform using BlueZ 5
Will sdptool work without setting the DeviceID value? I've tried the following command and receive timeouts every time (only for my local device):
# sdptool browse local
Browsing FF:FF:FF:00:00:00 ...
Service Search failed: Connection timed out
Is it viable to replace all of the python simple-agent scripts with libbluetooth instead, or do I need to try and port them over to a supported scripting language?
Any help would be greatly appreciated!!!
If more logs are needed I can try and get them.
I'm trying to install MYSQLdb on a windows client. The goal is, from the Windows client, run a python script that connects to a MySQL server on a LINUX client. Looking at the setup code (and based on the errors I am getting when I try to run setup.py for mysqldb, it appears that I have to have my own version of MySQL on the windows box. Is there a way (perhaps another module) that will let me accomplish this? I need to have people on multiple boxes run a script that will interact with a MySQL database on a central server.
you could use a pure python implementation of the mysql client like
pymysql
(can be used as a dropin-replacement for MySQLdb by calling pymysql.install_as_MySQLdb())
MySql-Connector
You don't need the entire MySQL database server, only the MySQL client libraries.
It's been a long time since I wrote python db code for windows...but I think something like this should still work.
If you're running the client only on windows machines, install the pywin32 package. This should have an odbc module in it.
Using the windows control / management tools, create an odbc entry for either the user or the system. In that entry, you'll give the connection parameter set a unique name, then select the driver (in this case MySQL), and populate the connection parameters (e.g. host name, etc.) See PyWin32 Documentation for some notes on the odbc module in pywin32.
Also, see this post: Common ways to connect to odbc from python on windows.
I have a Twisted application that runs in an x86 64bit machine with Win 2008 server.
It needs to be connected to a SQL Server database that runs in another machine (in a cloud actually but I have IP, port, db name, credentials).
Do I need to install anything more that Twisted to my machine?
And which API should be used?
twisted.enterprise.adbapi will help you use any DB-API 2.0 module without blocking. It gives you a non-blocking, Deferred-based API by running database operations in a thread pool. python-mssql appears to be a DB-API 2.0 compliant module for MSSQL (I've never used it myself though).
If you want to have portable mssql server library, you can try the module from www.pytds.com.
It works with 2.5+ and 3.1, have a good stored procedure support. It's api is more "functional", and has some good features you won't find anywhere else.
If Python, if you are developing a system service that communicates with user applications through sockets, and you want to treat sockets connected by different users differently, how would you go about that?
If I know that all connecting sockets will be from localhost, is there a way to lookup through the OS (either on windows or linux) which user is making the connection request?
On Linux and other unixy system, you can use the ident service.
I'm not sure if Windows offers something similar.
Unfortunately, at this point in time the python libraries don't support the usual SCM_CREDENTIALS method of passing credentials along a Unix socket.
You'll need to use an "ugly" method as described in another answer to find it.
On Linux you can get the source (i.e. client-side) port of the socket and parse the output of the lsof(8) utility searching for who is using that port.
Here's the manual page.
I decided to tackle Python as a new language to learn. The first thing I want to do is code a script that will allow me to remotely restart services on other machines from my local machine. How would I accomplish this when the remote machine requires a username and password to log on? I don't need a full solution to be given to me but maybe some pointers on what libraries I should use or any issues I need to address when writing the script.
EDIT: All the remote machines are using Windows 2003
People usually recommend paramiko as a library to do ssh (and I'm assuming that you need ssh to get into the remote machine). There is a good tutorial for it.
Edit: On windows, the easiest way is probably to use SysInternals psservice utility, to be invoked with os.system; this can start a remote service, and accepts logon credentials.
If you want to do it directly in Python, you need win32service.StartService. Before that, you need to open the remote service manager, and then the remote service. Before that, you need to impersonate the user as which you want to perform the operation, see the example.
Take a look at Fabric wich is based on paramiko.
This is really a good tool to automate remote tasks with python.
Fabric Documentation will show you how easy it is to use.
What kind of OS is your remote machine running? If it's linux, run ssh(1) using the subprocess module.
If it's windows, then get the win32 extensions. They allow you to call Windows functions. There should be an API to allow to access services. If they don't, there is a tool called sc (docs) which you can run using the subprocess module.
Which OS for the target machines? If 'service' is 'Windows NT service', and your local machine is also Windows, I'd use IronPython as the Python language implementation and call straight into the WMI facilities in the .net System.Management namespace -- they're meant for remote admin like that.
On Windows, the wmi module is now fantastic for this.