Using paramiko tring to connect RHEL6.5 vm giving "Servname not supported for ai_socktype" error message - redhat

I new in python, I am try to connect RHEL vm by key authentication.I have two RHEL6.5 vm1,vm2 and Python 2.6.6 on both.
First I generate keys on vm1 and copy to vm2 as using below cmd.
On vm1 execute below cmd:
1) ssh-keygen -t rsa
2) After key generation
3) ssh-copy-id -i .ssh/id_rsa.pub root#vm2
After that I am able to login that vm2 from vm1
ssh -i /root/.ssh/id_rsa root#vm2
manually this is working fine but i am doing it programmatically by using python, below is my code: run from vm1
SSHKey.py
import paramiko
sshcon = paramiko.SSHClient()
sshcon.set_missing_host_key_policy(paramiko.AutoAddPolicy())
connection = sshcon.connect('vm2', 'root','/root/.ssh/id_rsa')
print "-----------------"
print connection
**OutPut:**
Traceback (most recent call last):
File "SSHKey.py", line 5, in <module>
connection = sshcon.connect('vm2', 'root')
File "/usr/lib/python2.6/site-packages/paramiko/client.py", line 277, in connect
socket.getaddrinfo(hostname, port):
socket.gaierror: [Errno -8] Servname not supported for ai_socktype

I think RHEL6.5 vm1 not able to communicate with RHEL6.5 vm2.Python version looks good you need to install paramiko on RHEL6.5 vm2.Run below cmd.
1) yum list python-paramiko --showduplicates
This will give you available package
2) yum install python-paramiko
This will install paramiko on your rhel vm.

Related

CISCO IOS-XR, Python3.7, Not able to run commands like 'ls' and 'df' on Cisco router

Cisco ios-xr router using CLI:
RP/0/RP0#show version
Thu Nov 25 07:53:59.103 UTC
Cisco IOS XR Software, Version 6.5.32.11I
Copyright (c) 2013-2020 by Cisco Systems, Inc.
RP/0/RP0#run
Thu Nov 25 07:54:05.231 UTC
[xr-vm_node0_RP0_CPU0:~]$df
Filesystem 1K-blocks Used Available Use% Mounted on
rootfs 3966080 1332040 2412860 36% /
76892 11848320 43% /mnt/ecu/vdd
[xr-vm_node0_RP0_CPU0:~]$
Using python:
I am able to run show commands using Connecthandler .send.command:
from netmiko import ConnectHandler
import subprocess
Network_Device = {"host": "10.111.22.333", "username": "USER123", "password": "Pass123", "device_type": "cisco_xr",}
Connect = ConnectHandler(**Network_Device)
Connect.enable()
version1 = "show version"
print(Connect.send_command(version1))
But not able to run 'df' or 'ls' commands, as not able to reach bash prompt i reach by running 'run' command on router.
I tried:
disk1files = subprocess.run("df", stdout=subprocess.PIPE)
print(disk1files.stdout.decode())
But seems its wrong. Please suggest the right library or code I can use here.
This is my first question here, so bear some silly questions or mistakes done in code
if on DF you are referring to "Don't fragment" then it is posible to send it like
Connect.send_command("ping 192.168.10.10 df-bit size 1600")
where 1600 represents MTU, and for ls commands is link command,
Connect.send_command("ls-active")
Connect.send_command("ls-active-enabled")
but if you are referring to df and ls in linux (disk free and list files..) then you can use os module for sending commands:
import os
os.system("ls -l")
or use call from subprocess module:
from subprocess import call
call(["ls", "-l"])
If you need to acccess cisco bash:
switch# configure terminal
switch(config)# feature bash-shell
switch# run?
run Execute/run program
run-script Run shell scripts
switch# run bash?
bash Linux-bash
switch# run bash
bash-4.2$ whoami
admin
bash-4.2$ pwd
/bootflash/home/admin
bash-4.2$

Error installing AutoitLibrary through command line

I need to install robotframework-autoitlibrary to use on my test cases.
My problem is when I try to install AutoIt Library through command line with the following command:
pip install -U robotframework-autoitlibrary --no-cache-dir --pre
I have this error:
C:\windows\system32>pip install -U robotframework-autoitlibrary --no-cache-
dir --pre
Collecting robotframework-autoitlibrary
Downloading
https://files.pythonhosted.org/packages/4e/a4/9e51fe35b1da7a006b773c9c234f78e89bcc4f267152c4e9fa8260631fa8/robotframework-autoitlibrary-1.2.2.zip (701kB)
100% |################################| 706kB 1.6MB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\users\user-a~1\appdata\local\temp\pip-install-
oro1ov\robotframework-autoitlibrary\setup.py", line 93, in <module>
destPath = os.path.normpath(os.path.join(os.getenv("HOMEDRIVE"),
r"\RobotFramework\Extensions\AutoItLibrary"))
File "c:\python27\lib\ntpath.py", line 65, in join
result_drive, result_path = splitdrive(path)
File "c:\python27\lib\ntpath.py", line 115, in splitdrive
if len(p) > 1:
TypeError: object of type 'NoneType' has no len()
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in
c:\users\user-a~1\appdata\local\temp\pip-install-oro1ov\robotframework-
autoitlibrary\
My currently installed python packages and their versions are:
Pillow==5.3.0
Pygments==2.3.1
pypiwin32==223
Pypubsub==4.0.0
pywin32==224
robotframework==3.1
robotframework-ride==1.5.2.1
robotframework-selenium2library==3.0.0
robotframework-seleniumlibrary==3.3.0
selenium==3.141.0
six==1.12.0
typing==3.6.6
urllib3==1.24.1
wxPython==4.0.3
I already try this command:
pip install --upgrade setuptools
When input echo %HOMEDRIVE%, the output is:
C:\Users\cmpeixoto>echo %HOMEDRIVE%
C:
Thanks for your help,
The error looks like the environment variable HOMEDRIVE is not set, even though it has a value according to your test (the library installer uses it to copy some files).
Can you try this - manually set it, and straight after that run the pip - in the same Command Prompt (cmd) session:
set HOMEDRIVE=C:
pip install -U robotframework-autoitlibrary --no-cache-dir --pre

Installing awscli without internet

I am trying to install awscli on a RHEL machine.
Python 2.7.5 is installed, the machine does not have internet access.
I have installed setuptools 38.5.2 and setuptools_scm 1.15.7 from sources successfully.
Here is the command I have tried to run when installing:
sudo /usr/bin/python2.7 awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws sudo awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
Both are exiting with the following issue:
Running cmd: /usr/bin/python virtualenv.py --no-download --python /usr/bin/python /usr/local/aws
Running cmd: /usr/local/aws/bin/pip install --no-index --find-links file:///home/talendmaster/QlikSensePOC/awscli-bundle/packages awscli-1.14.54.tar.gz
Traceback (most recent call last):
File "awscli-bundle/install", line 143, in <module>
main()
File "awscli-bundle/install", line 132, in main
pip_install_packages(opts.install_dir)
File "awscli-bundle/install", line 100, in pip_install_packages
pip_script, PACKAGES_DIR, cli_tarball))
File "awscli-bundle/install", line 45, in run
p.returncode, cmd, stdout + stderr))
__main__.BadRCError: Bad rc (1) for cmd '/usr/local/aws/bin/pip install --no-index --find-links file:///home/talendmaster/QlikSensePOC/awscli-bundle/packages awscli-1.14.54.tar.gz': Processing ./awscli-1.14.54.tar.gz
Collecting botocore==1.9.7 (from awscli==1.14.54)
Collecting colorama<=0.3.7,>=0.2.5 (from awscli==1.14.54)
Collecting docutils>=0.10 (from awscli==1.14.54)
Collecting rsa<=3.5.0,>=3.1.2 (from awscli==1.14.54)
Collecting s3transfer<0.2.0,>=0.1.12 (from awscli==1.14.54)
Collecting PyYAML<=3.12,>=3.10 (from awscli==1.14.54)
Collecting jmespath<1.0.0,>=0.7.1 (from botocore==1.9.7->awscli==1.14.54)
Collecting python-dateutil<3.0.0,>=2.1 (from botocore==1.9.7->awscli==1.14.54)
Complete output from command python setup.py egg_info:
Download error on https://pypi.python.org/simple/setuptools_scm/: [Errno 101] Network is unreachable -- Some packages may not be found!
Download error on https://pypi.python.org/simple/setuptools-scm/: [Errno 101] Network is unreachable -- Some packages may not be found!
Couldn't find index page for 'setuptools_scm' (maybe misspelled?)
Download error on https://pypi.python.org/simple/: [Errno 101] Network is unreachable -- Some packages may not be found!
No local packages or working download links found for setuptools_scm
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-kh_Hg9/python-dateutil/setup.py", line 67, in <module>
"test": Unsupported
File "/usr/lib64/python2.7/distutils/core.py", line 112, in setup
_setup_distribution = dist = klass(attrs)
File "/usr/local/aws/lib/python2.7/site-packages/setuptools/dist.py", line 315, in __init__
self.fetch_build_eggs(attrs['setup_requires'])
File "/usr/local/aws/lib/python2.7/site-packages/setuptools/dist.py", line 361, in fetch_build_eggs
replace_conflicting=True,
File "/usr/local/aws/lib/python2.7/site-packages/pkg_resources/__init__.py", line 850, in resolve
dist = best[req.key] = env.best_match(req, ws, installer)
File "/usr/local/aws/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1122, in best_match
return self.obtain(req, installer)
File "/usr/local/aws/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1134, in obtain
return installer(requirement)
File "/usr/local/aws/lib/python2.7/site-packages/setuptools/dist.py", line 429, in fetch_build_egg
return cmd.easy_install(req)
File "/usr/local/aws/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 659, in easy_install
raise DistutilsError(msg)
distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('setuptools_scm')
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-kh_Hg9/python-dateutil/
It seems to be related to setuptools_scm but reinstallation did not change anything. The internet access shouldn't be a problem since I have successfully installed a local version of the package.
I have just finished installing AWS CLI tools on an old RHEL 5.10 machine, this works for me as on date.
$ curl -LO https://s3.amazonaws.com/aws-cli/awscli-bundle.zip
$ unzip awscli-bundle.zip
$ ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
Running cmd: /root/aws/bin/python virtualenv.py --no-download --python /root/aws/bin/python /usr/local/aws
Running cmd: /usr/local/aws/bin/pip install --no-index --find-links file:///root/awscli-bundle/packages/setup setuptools_scm-1.15.7.tar.gz
Running cmd: /usr/local/aws/bin/pip install --no-index --find-links file:///root/awscli-bundle/packages awscli-1.15.68.tar.gz
You can now run: /usr/local/bin/aws --version
$ aws --version
aws-cli/1.15.68 Python/2.6.8 Linux/2.6.18-363.el5 botocore/1.10.67
References:
https://medium.com/#vikas027/aws-cli-tools-in-rhel-centos-5-cd4b9beeb096 (my post)
https://docs.aws.amazon.com/cli/latest/userguide/awscli-install-bundle.html#install-bundle-other

Why gcloud command is slow to start?

Just typing gcloud for help take 5 secs.
$ gcloud
...
gcloud 0.30s user 0.13s system 7% cpu 5.508 total
$ gcloud version
Google Cloud SDK 128.0.0
alpha 2016.01.12
bq 2.0.24
bq-nix 2.0.24
core 2016.09.23
core-nix 2016.09.20
gcloud
gsutil 4.21
gsutil-nix 4.21
kubectl
kubectl-darwin-x86_64 1.3.7
$ uname -a
Darwin hiroshi-MacBook.local 16.0.0 Darwin Kernel Version 16.0.0: Mon Aug 29 17:56:20 PDT 2016; root:xnu-3789.1.32~3/RELEASE_X86_64 x86_64
EDIT 2017-03-31: Zachary said that gcloud 148.0.0 addressed this issue. So try gcloud components update. see https://stackoverflow.com/users/4922212/zachary-newman
tl;dr
It turns out that socket.gethostbyaddr(socket.gethostname()) is slow for .local hostname in macOS.
$ python -i
>>> socket.gethostname()
'hiroshi-MacBook.local'
>>> socket.gethostbyaddr(socket.gethostname()) # it takes about 5 seconds
('localhost', ['1.0.0.127.in-addr.arpa'], ['127.0.0.1'])
So, for a workaround, just added the hostname to the localhost line of /etc/hosts.
127.0.0.1 localhost hiroshi-Macbook.local
After that is return value is different, but it returns in an instant.
>>> socket.gethostbyaddr(socket.gethostname())
('localhost', ['1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa'], ['::1'])
How do I get there
Where gcloud command is:
$ which gcloud
/Users/hiroshi/google-cloud-sdk/bin/gcloud
Edit the endline of the shell script...
...
+ echo "$CLOUDSDK_PYTHON" $CLOUDSDK_PYTHON_ARGS "${CLOUDSDK_ROOT_DIR}/lib/gcloud.py" "$#"
"$CLOUDSDK_PYTHON" $CLOUDSDK_PYTHON_ARGS "${CLOUDSDK_ROOT_DIR}/lib/gcloud.py" "$#"
to echo where the gcloud.py is:
$ gcloud
python2.7 -S /Users/hiroshi/google-cloud-sdk/lib/gcloud.py
OK. Who take the 5 secs?
$ python2.7 -S -m cProfile -s time /Users/hiroshi/google-cloud-sdk/lib/gcloud.py
173315 function calls (168167 primitive calls) in 5.451 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
1 5.062 5.062 5.062 5.062 {_socket.gethostbyaddr}
...
_socket.gethostbyaddr is.
What is the argument of the function call and backtrace look like?
I added some lines before main() of gcloud.py
import traceback
def mygethostbyaddr(addr):
print addr
traceback.print_stack()
return addr
import socket
socket.gethostbyaddr = mygethostbyaddr
Execute gcloud again.
I got it is my .local name of my machine.
$ gcloud
hiroshi-MacBook.local
File "/Users/hiroshi/google-cloud-sdk/lib/gcloud.py", line 74, in <module>
main()
File "/Users/hiroshi/google-cloud-sdk/lib/gcloud.py", line 70, in main
sys.exit(googlecloudsdk.gcloud_main.main())
File "/Users/hiroshi/google-cloud-sdk/lib/googlecloudsdk/gcloud_main.py", line 121, in main
metrics.Started(START_TIME)
File "/Users/hiroshi/google-cloud-sdk/lib/googlecloudsdk/core/metrics.py", line 411, in Wrapper
return func(*args, **kwds)
File "/Users/hiroshi/google-cloud-sdk/lib/googlecloudsdk/core/metrics.py", line 554, in Started
collector = _MetricsCollector.GetCollector()
File "/Users/hiroshi/google-cloud-sdk/lib/googlecloudsdk/core/metrics.py", line 139, in GetCollector
_MetricsCollector._instance = _MetricsCollector()
File "/Users/hiroshi/google-cloud-sdk/lib/googlecloudsdk/core/metrics.py", line 197, in __init__
hostname = socket.getfqdn()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 141, in getfqdn
hostname, aliases, ipaddrs = gethostbyaddr(name)
File "/Users/hiroshi/google-cloud-sdk/lib/gcloud.py", line 32, in mygethostbyaddr
traceback.print_stack()
#hiroshi's answer solved the issue for me i.e. to run gcloud components update. However, since I had installed gcloud through their Cloud SDK using a package manager, I was stuck with the following error*:
ERROR: (gcloud.components.update) You cannot perform this action
because the Google Cloud CLI component manager is disabled for this
installation.
Hence, I had to explicitly mention the apt-get libraries to perform the update. The following command helped me to get it done in one go:
sudo apt-get update && sudo apt-get --only-upgrade install google-cloud-sdk-app-engine-go google-cloud-sdk-datastore-emulator google-cloud-sdk-datalab google-cloud-sdk-firestore-emulator google-cloud-sdk-kubectl-oidc google-cloud-sdk google-cloud-sdk-app-engine-python-extras google-cloud-sdk-cloud-build-local kubectl google-cloud-sdk-cbt google-cloud-sdk-minikube google-cloud-sdk-skaffold google-cloud-sdk-cloud-run-proxy google-cloud-sdk-pubsub-emulator google-cloud-sdk-config-connector google-cloud-sdk-gke-gcloud-auth-plugin google-cloud-sdk-kpt google-cloud-sdk-local-extract google-cloud-sdk-nomos google-cloud-sdk-app-engine-grpc google-cloud-sdk-bigtable-emulator google-cloud-sdk-app-engine-python google-cloud-sdk-terraform-validator google-cloud-sdk-anthos-auth google-cloud-sdk-spanner-emulator google-cloud-sdk-app-engine-java
*More details as to why the aforementioned error occurs and how to permanently solve it can be found here.

Mongo connector with neo4j not working

I'm running the following command:
mongo-connector -m localhost:27017 -t http://localhost:7474/db/data -d neo4j_doc_manager
But getting following error:
No handlers could be found for logger "mongo_connector.util"<br/>
Traceback (most recent call last):<br/>
File "/usr/local/bin/mongo-connector", line 11, in <module>
sys.exit(main())<br/>
File "/usr/local/lib/python2.7/site-packages/mongo_connector/util.py", line 85, in wrapped<br/>
func(*args, **kwargs)
File "/usr/local/lib/python2.7/site-<br/>packages/mongo_connector/connector.py", line 1041, in main
conf.parse_args()<br/>
File "/usr/local/lib/python2.7/site-packages/mongo_connector/config.py", line 118, in parse_args
option, dict((k, values.get(k)) for k in option.cli_names))
File "/usr/local/lib/python2.7/site-packages/mongo_connector/connector.py", line 824, in apply_doc_managers
module = import_dm_by_name(dm['docManager'])<br/>
File "/usr/local/lib/python2.7/site-packages/mongo_connector/connector.py", line 814, in import_dm_by_name
"vailable doc managers." % full_name)
mongo_connector.errors.InvalidConfiguration: Could not import mongo_connector.doc_managers.neo4j_doc_manager. It could be that this doc manager has been moved out of this project and is maintained elsewhere. Make sure that you have the doc manager installed alongside mongo-connector. Check the README for a list of available doc managers.
NOTE: I'm using neo4j 3.0, os: macosx, python: 2.7**
This appears to be an error caused by failing to pin the py2neo dependency to a specific version. This project was written using py2neo 2.0.7 but failed to pin that version, as py2neo 3.0 is now being pulled in a few things are breaking.
We will push an update for 3.0 soon, in the meantime you can get around this by uninstalling py2neo and installing version 2.0.7:
lyonwj#lyonwjs-MacBook-Pro-2 ~/n/mongo_demo> pip uninstall py2neo
Uninstalling py2neo-3
...
lyonwj#lyonwjs-MacBook-Pro-2 ~/n/mongo_demo> pip install py2neo==2.0.7
Collecting py2neo==2.0.7
Downloading py2neo-2.0.7.tar.gz (251kB)
100% |████████████████████████████████| 256kB 2.6MB/s
Installing collected packages: py2neo
Running setup.py install for py2neo ... done
Successfully installed py2neo-2.0.7
lyonwj#lyonwjs-MacBook-Pro-2 ~/n/mongo_demo>
mongo-connector -m localhost:27017 -t http://localhost:7474/db/data -d neo4j_doc_manager
Logging to mongo-connector.log.
See https://github.com/neo4j-contrib/neo4j_doc_manager/issues/60