No project description provided
Project description
gqylpy-ssh
本源代码使用了 paramiko 库,这个库是基于 LGPL 协议发布的。
在远程服务器执行命令并得到命令结果,它是对 paramiko 库的二次封装。通过
Command
对象,你可以得到这条命令的执行结果,状态等信息。
pip3 install gqylpy_ssh
首先初始化 GqylpySSH
实例:
import gqylpy_ssh as gssh
gssh.__init__(
hostname='192.168.1.7',
username='gqylpy',
password=...
)
通过 cmd
函数在远程服务器执行命令,它返回一个 Command
对象:
c = gssh.cmd('hostname')
若命令执行失败,调用此方法将抛出异常:
c.raise_if_error()
获得命令状态或输出:
status: bool = c.status
output: str = c.output
status, output = c.status_output
获得命令输出,若命令执行错误,将抛出异常
output: str = c.output_else_raise
获得命令输出,若命令执行错误,将返回 "define value":
output: str = c.output_else_define('define value')
检查命令输出是否包含某个字符串,得到一个布尔值:
x: bool = c.contain_string('string')
获得命令输出,如果输出包含某个字符串,否则抛出异常:
output: str = c.output_if_contain_string_else_raise('string')
这个方法可将带有标题的输出转为字典:
it = c.output2dict('kubectl get nodes')
如果你需要创建多个 GqylpySSH
实例:
from gqylpy_ssh import GqylpySSH, Command
ssh = GqylpySSH('192.168.1.7', **params)
c: Command = ssh.cmd('hostname')
output: str = c.output_else_raise
import gqylpy_ssh as gssh
gssh.__init__('192.168.1.7', **params, gname='1.7')
gssh.__init__('192.168.1.9', **params, gname='1.9')
output: str = gssh.cmd('hostname', gname='1.7').output_else_raise
output: str = gssh.cmd('hostname', gname='1.9').output_else_raise
gssh.cmd('hostname').output == gssh.cmd('hostname', gname='1.7').output
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
gqylpy_ssh-1.0.1-py3-none-any.whl
(18.7 kB
view hashes)
Close
Hashes for gqylpy_ssh-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d3d779bc87fb974cfd7a478f8313f0bb22d72f55170f55279ed11013194f22f |
|
MD5 | 644b23f5b9cc079f7c6a709b286ea742 |
|
BLAKE2b-256 | fbc4227a02209968941f54810c2346056390f70150706f3c93c004931397f3c5 |