Fabric is a Python library that simplifies the use of SSH for system administration tasks by running remote commands on remote system. It can be used as well to run local commands on the system.
Example code below shows on how to use Fabric module to execute local commands.
Below is an example on how to use Fabric.
Sample output image:
In Python3 a warning might be shown about cryptography warning like the warning below:
/home/sirach/xx-python/pythonvenv/lib/python3.10/site-packages/paramiko/pkey.py:82: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from cryptography.hazmat.primitives.ciphers.algorithms in 48.0.0. "cipher": algorithms.TripleDES,
/home/sirach/xx-python/pythonvenv/lib/python3.10/site-packages/paramiko/transport.py:253: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from cryptography.hazmat.primitives.ciphers.algorithms in 48.0.0. "class": algorithms.TripleDES,
On my case to resolve the above error, upgrading Paramiko works well.
pip3 install --upgrade paramiko
By upgrading the Paramiko on the virtual environment, the warning did not display anymore.
Be careful though, in upgrading the Paramiko on a Production enviroment it might cause a Production issue if other files still referring to the older version or other projects has still dependencies on the lower version.
Refer to Fabric documentation before upgrading.
"Don't be proud; acknowledge God in all your ways. As John 15:5 says, 'I am the vine; you are the branches. If you remain in me and I in you, you will bear much fruit; apart from me you can do nothing.'"
Humility is of greater value than a proud and deceitful heart.
Example code below shows on how to use Fabric module to execute local commands.
Below is an example on how to use Fabric.
from fabric import Connection
# Create a connection to the localhost
connx = Connection('localhost')
# Run local commands
def run_local_commands():
print(f"Executing on {connx.host} as {connx.user}")
# Command 1: Get the system name
result_uname = connx.local("uname -s", hide=True)
print("Output of 'uname':")
print(result_uname.stdout)
# Command 2: Get memory on the system
result_mem = connx.local("free -h", hide=True)
print("Output of 'system memory':")
print(result_mem.stdout)
# Command 3: Display ip route
result_ipr = connx.local("ip r", hide=True)
print("Output of 'ip route':")
print(result_ipr.stdout)
# Execute/Call the function
run_local_commands()
Sample output image:
In Python3 a warning might be shown about cryptography warning like the warning below:
/home/sirach/xx-python/pythonvenv/lib/python3.10/site-packages/paramiko/pkey.py:82: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from cryptography.hazmat.primitives.ciphers.algorithms in 48.0.0. "cipher": algorithms.TripleDES,
/home/sirach/xx-python/pythonvenv/lib/python3.10/site-packages/paramiko/transport.py:253: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from cryptography.hazmat.primitives.ciphers.algorithms in 48.0.0. "class": algorithms.TripleDES,
On my case to resolve the above error, upgrading Paramiko works well.
pip3 install --upgrade paramiko
By upgrading the Paramiko on the virtual environment, the warning did not display anymore.
Be careful though, in upgrading the Paramiko on a Production enviroment it might cause a Production issue if other files still referring to the older version or other projects has still dependencies on the lower version.
Refer to Fabric documentation before upgrading.
"Don't be proud; acknowledge God in all your ways. As John 15:5 says, 'I am the vine; you are the branches. If you remain in me and I in you, you will bear much fruit; apart from me you can do nothing.'"
Humility is of greater value than a proud and deceitful heart.
Comments
Post a Comment