本文整理汇总了Python中fabric.Connection方法的典型用法代码示例。如果您正苦于以下问题:Python fabric.Connection方法的具体用法?Python fabric.Connection怎么用?Python fabric.Connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fabric
的用法示例。
在下文中一共展示了fabric.Connection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ssh
# 需要导入模块: import fabric [as 别名]
# 或者: from fabric import Connection [as 别名]
def ssh(ip, name, pkey):
attempt = 0
while attempt < 12:
logging.info('connection attempt {}'.format(attempt))
connection = Connection(
host=ip,
user=name,
connect_kwargs={'key_filename': pkey,
'allow_agent': False,
'look_for_keys': False,
})
try:
connection.run('ls')
return connection
except Exception as ex:
logging.error(ex)
attempt += 1
time.sleep(10)
示例2: setup
# 需要导入模块: import fabric [as 别名]
# 或者: from fabric import Connection [as 别名]
def setup(c: Connection, commit=None, release=None):
print('== Setup ==')
if release is None:
c.release = timestamp(c)
else:
c.release = release
c.deploy_path = path.deploy_path(c)
c.repo_path = path.repo_path(c)
c.releases_path = path.releases_path(c)
c.current_path = path.current_path(c)
c.shared_path = path.shared_path(c)
c.release_path = path.release_path(c)
if commit is None:
c.commit = c.deploy.branch
else:
c.commit = commit
print('release: {}'.format(c.release))
print('commit: {}'.format(c.commit))
create_dirs(c)
if not path.file_exists(c, '{}/venv/bin/activate'.format(c.shared_path)):
create_venv(c)
示例3: __init__
# 需要导入模块: import fabric [as 别名]
# 或者: from fabric import Connection [as 别名]
def __init__(self, host_string="localhost:8822", user="root"):
"""Create a MenderDevice object-
Keyword arguments:
host_string -- Remote SSH host of the form host:port
user -- Remote SSH user
"""
self.host, self.port = host_string.split(":")
self.user = user
self._conn = Connection(
host=self.host,
user=self.user,
port=self.port,
connect_timeout=60,
connect_kwargs={"password": "", "banner_timeout": 60, "auth_timeout": 60},
)
self._conn.client.set_missing_host_key_policy(IgnorePolicy())
self._service_name = None
示例4: setup_master
# 需要导入模块: import fabric [as 别名]
# 或者: from fabric import Connection [as 别名]
def setup_master(master: str, passphrase: str, user: str) -> None:
connect_kwargs = {'passphrase': passphrase}
node = Connection(master, user=user, connect_kwargs=connect_kwargs)
home = get_home_path(node)[0]
# install(node) # Not calling because of Fabric bug
# redis conf
logfile = f'logfile "{home}/redis.log"'
node.put('redis_configs/redis.conf', 'redis-stable/redis.conf')
node.run(f'echo {logfile} >> redis-stable/redis.conf')
# sentinal conf
logfile = f'logfile "{home}/sentinel.log"'
sentinel_monitor = f'sentinel monitor mymaster {master} 6379 2'
node.put('redis_configs/sentinel.conf', 'redis-stable/sentinel.conf')
node.run(f'echo {logfile} >> redis-stable/sentinel.conf')
node.run(f"sed -i 's/placeholder-line/{sentinel_monitor}/g' redis-stable/sentinel.conf")
# bring_up_server(node) # Not calling because of Fabric bug
示例5: create_user
# 需要导入模块: import fabric [as 别名]
# 或者: from fabric import Connection [as 别名]
def create_user():
initial_user = 'ubuntu'
sudo_group = 'sudo'
with Connection(host=args.hostname, user=initial_user,
connect_kwargs={'key_filename': args.pkey}) as conn:
try:
if not exists(conn,
'/home/{}/.ssh_user_ensured'.format(initial_user)):
conn.sudo('useradd -m -G {1} -s /bin/bash {0}'
.format(args.os_user, sudo_group))
conn.sudo(
'bash -c \'echo "{} ALL = NOPASSWD:ALL" >> /etc/sudoers\''.format(args.os_user, initial_user))
conn.sudo('mkdir /home/{}/.ssh'.format(args.os_user))
conn.sudo('chown -R {0}:{0} /home/{1}/.ssh/'
.format(initial_user, args.os_user))
conn.sudo('cat /home/{0}/.ssh/authorized_keys > '
'/home/{1}/.ssh/authorized_keys'
.format(initial_user, args.os_user))
conn.sudo(
'chown -R {0}:{0} /home/{0}/.ssh/'.format(args.os_user))
conn.sudo('chmod 700 /home/{0}/.ssh'.format(args.os_user))
conn.sudo('chmod 600 /home/{0}/.ssh/authorized_keys'
.format(args.os_user))
conn.sudo(
'touch /home/{}/.ssh_user_ensured'.format(initial_user))
except Exception as err:
logging.error('Failed to create new os_user: ', str(err))
sys.exit(1)
示例6: init_dlab_connection
# 需要导入模块: import fabric [as 别名]
# 或者: from fabric import Connection [as 别名]
def init_dlab_connection(ip=None, user=None,
pkey=None):
global conn
if not ip:
ip = args.hostname
if not user:
user = args.os_user
if not pkey:
pkey = args.pkey
try:
conn = Connection(ip, user, connect_kwargs={'key_filename': pkey})
except Exception as err:
logging.error('Failed connect as dlab-user: ', str(err))
traceback.print_exc()
sys.exit(1)
示例7: ssh
# 需要导入模块: import fabric [as 别名]
# 或者: from fabric import Connection [as 别名]
def ssh(ip, name, pkey):
while True:
return Connection(host=ip,
user=name,
connect_kwargs={'key_filename': pkey,
'allow_agent': False,
'look_for_keys': False,
})
示例8: _connect_ec2_instance
# 需要导入模块: import fabric [as 别名]
# 或者: from fabric import Connection [as 别名]
def _connect_ec2_instance(ec2_instance):
public_ip_address = ec2_instance.public_ip_address
connected_instance = Connection(
host=public_ip_address,
port=22,
user="ec2-user",
connect_kwargs={"key_filename": [KEY_PATH]},
)
return connected_instance
示例9: exec_remote_cmd
# 需要导入模块: import fabric [as 别名]
# 或者: from fabric import Connection [as 别名]
def exec_remote_cmd(cls, conn: Connection, command: str, **kwargs):
return conn.run(command, **kwargs)
示例10: upload_remote_file
# 需要导入模块: import fabric [as 别名]
# 或者: from fabric import Connection [as 别名]
def upload_remote_file(cls, conn: Connection, source_file: str, remote_file: str):
return conn.put(source_file, remote_file)
示例11: gen_ssh_connection
# 需要导入模块: import fabric [as 别名]
# 或者: from fabric import Connection [as 别名]
def gen_ssh_connection(cls, private_key_path: str, addr: str):
return Connection(
addr,
connect_kwargs={
"key_filename": private_key_path,
},
)
示例12: check
# 需要导入模块: import fabric [as 别名]
# 或者: from fabric import Connection [as 别名]
def check(c: Connection):
return remote_reachable(c)
示例13: update
# 需要导入模块: import fabric [as 别名]
# 或者: from fabric import Connection [as 别名]
def update(c: Connection):
if repo_exists(c):
fetch(c)
else:
clone(c)
示例14: repo_exists
# 需要导入模块: import fabric [as 别名]
# 或者: from fabric import Connection [as 别名]
def repo_exists(c: Connection) -> bool:
return file_exists(c, "{}/HEAD".format(c.repo_path))
示例15: remote_reachable
# 需要导入模块: import fabric [as 别名]
# 或者: from fabric import Connection [as 别名]
def remote_reachable(c: Connection) -> bool:
with c.cd(c.repo_path):
return c.run("git ls-remote {} HEAD".format(c.deploy.repo_url), warn=True, echo=True).ok