configure ControlMaster and ControlPath for SSH connections
This should speed up deployments by not having to reconnect to the server on each command
This commit is contained in:
@@ -41,6 +41,22 @@ class Host:
|
||||
self.command_prefix = self.host
|
||||
if not self.user:
|
||||
self.user = "root"
|
||||
home = Path.home()
|
||||
if home.exists() and os.access(home, os.W_OK):
|
||||
control_path = home / ".ssh"
|
||||
if not control_path.exists():
|
||||
try:
|
||||
control_path.mkdir(exist_ok=True)
|
||||
except OSError:
|
||||
pass
|
||||
else:
|
||||
self.ssh_options["ControlMaster"] = "auto"
|
||||
# Can we make this a temporary directory?
|
||||
self.ssh_options["ControlPath"] = str(
|
||||
control_path / "clan-%h-%p-%r"
|
||||
)
|
||||
# We use a short ttl because we want to mainly re-use the connection during the cli run
|
||||
self.ssh_options["ControlPersist"] = "1m"
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.target
|
||||
|
||||
@@ -117,7 +117,9 @@ def test_parse_deployment_address(
|
||||
assert result.user == expected_user or (
|
||||
expected_user == "" and result.user == "root"
|
||||
)
|
||||
assert result.ssh_options == expected_options
|
||||
|
||||
for key, value in expected_options.items():
|
||||
assert result.ssh_options[key] == value
|
||||
|
||||
|
||||
def test_parse_ssh_options() -> None:
|
||||
|
||||
Reference in New Issue
Block a user