connecting to a mongo client using .OVPN file in python script - mongodb

I am kind of a stuck in a situation where I want to use python script to connect to a VPN and then connect to the Mongo Client. Our company has given me a ovpn file which I connect to using OPENVPN connect client. After the VPN connection is made, I then connect to the mongo client/server with the pymongo module in python and everything works fine and i can run all the relevant scripts on the DB.
I want to ask if it is possible to NOT use the OPENVPN connect client(because this actually connects my whole internet to the VPN and that what i dont want) and somehow use the OVPN file in python script and connect to the mongo server. I heard the that we can use the subprocess module to connect using a OVPN file but dont know how.
I am on a windows computer if this information helps. I how i got the message across. Any help will be appreciated.
here is the script i wrote but it gave me a server timeout error.
import subprocess
import pymongo
subprocess.run(["openvpn", "--config", "test-vpn.ovpn" ], shell = True)
client = pymongo.MongoClient('CONNECTIONSTRING')
client.list_database_names()

Related

Trouble retrieving DNS Server information on PowerShell

So here's my use case:
Im connecting to a remote windows server machine using the pypsrp python library.
Using the pypsrp.client Client module, I am able to easily execute powershell scripts remotely on my remote machine.
Im trying to fetch DNS server information from my remote windows server.
I am able to retrieve the DNS Server IP via ipconfig /all, however - when using the retrieved IP with any of the following commands I get an error.
For example, I tried: Show-DnsServerCache -ComputerName "10.0.0.5" but It returns the following error:
Failed to get the zone information for ..Cache on server 10.0.0.5.
Any idea if any further configuration from the DNS server side is needed?
Any help would be appreciated!

Unable to connect to remote jupyter server using the vscode python plugin

To connect to a remote jupyter server started with --no-browser option, I usually do a local port forward and connect to the server using the web-browser. However, I would like to connect to that server using the vscode's python extension using its "Specify Jupyter server URI" option. At present, I tried passing the same url , something like http://127.0.01:8888/notebooks/some_nb.ipynb?token=asd45366778875434.adsdsgd35331, but nothing happens.
How do I connect to this server form within vscode?Any help would be appreciated.

How to configure ipython notebook on laptop to point to remote server for execution

Well, my previous attempt to connect Pycharm from laptop to remote server did not see any ray of hope because of tcp/ip issues (which honestly I could not understand much and am still battling with) therefore I am looking to ipython as an alternative
Question: How can I configure ipython on laptop to point to the remote CentOS6 server for code processing and execution
Use Case: I want to use my laptop (using Win 7 Professional) to connect to the CentOS 6.4 master server using iPython.
Objective: To write the code in iPython on the laptop and then send the job to the server which will do the processing and should then return the result back to the laptop or to any other visualizing API.
The server and 3 namenodes already installed with pyspark and I have checked pyspark works in standalone mode on all four servers. Pyspark works in standalone mode on my laptop too.
Current setup: I use SSH to access the server. python 2.6 is installed on the server and the nodes. Able to run pyspark on all 4 servers in standalone mode
Any pointers will be helpful.
You have to start the IPython Notebook server on one cluster-node and then connect to the cluster-node's url. To do this, you have to create a profile, where you may specify hostname, port and so on. Have a look at this:
http://ipython.org/ipython-doc/1/interactive/public_server.html

MySQL connection not working from within Perl CGI script

I can easily connect to a remote MySQL server using the DBI module in my Perl scripts. However, when I try to use the same connection settings/properties from within a CGI script, the connection fails.
There are no helpful errors/warnings being logged either in the apache error log, or the browser, in spite of using
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
Strangely, the exact same script works fine when executed from the terminal. I also tried connecting the CGI script to the MySQL server on localhost, but without any success.
On the other hand, phpMyAdmin works great on the machine.
I'm using CentOS Release 5.8. I'm suspecting it is a system/priveleges issue with the apache user or anywhere else on the OS, but have hit a dead end.
Any pointers would be much appreciated!
Thanks a lot.
Edit: I'm using the following connection string
$dbh = DBI->connect($ds, $uname, $pwd,{RaiseError => 1 }) or die "$DBI::errstr Could not connect: $!<br>";
Fixed it. In case anyone not too familiar with Linux administration faces similar issue, here's what had happened. The security system 'selinux' on my CentOS machine was prohibiting the httpd to establish network connection to the remote MySQL server. It had to be explicitly enabled with the following command
setsebool -P httpd_can_network_connect=1
One can read more about selinux over here:
http://wiki.centos.org/HowTos/SELinux
Check what users you have set up in MySQL. If you're trying to connect across a network connection, you could have a problem with the host association for the user.
Try:
select host,user from mysql.user

How to connect eclipse from local to server

I have a eclipse on windows 7 system and I am trying some code on it.
But as my database is on server that is not my local systems so how can I connect eclipse to remote server so that I can write code on local and run on server.
Is it possible then please let me know and that server to which I want to connect that is Linux server.
Do you have to run your program remotely just because your database resides on the other server? Most databases allow connecting over TCP/IP.
Otherwise my suggestion is to add you public ssh key on the server, and then create a script which copies your class files and then executes your java program on your server, such as:
scp -r classfolder remoteuser#remotesystem:folderpath
ssh remoteuser#remotesystem java -cp folderpath the.created.Program
The public key removes the need for you to enter your password for each command.