Host: actual setup ssh controlmaster
before we were not entering the context manager
This commit is contained in:
@@ -149,13 +149,14 @@ class Machine:
|
|||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def target_host(self) -> Iterator[Host]:
|
def target_host(self) -> Iterator[Host]:
|
||||||
yield parse_deployment_address(
|
with parse_deployment_address(
|
||||||
self.name,
|
self.name,
|
||||||
self.target_host_address,
|
self.target_host_address,
|
||||||
self.host_key_check,
|
self.host_key_check,
|
||||||
private_key=self.private_key,
|
private_key=self.private_key,
|
||||||
meta={"machine": self},
|
meta={"machine": self},
|
||||||
)
|
) as target_host:
|
||||||
|
yield target_host
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def build_host(self) -> Iterator[Host | None]:
|
def build_host(self) -> Iterator[Host | None]:
|
||||||
@@ -165,18 +166,18 @@ class Machine:
|
|||||||
"""
|
"""
|
||||||
build_host = self.override_build_host or self.deployment.get("buildHost")
|
build_host = self.override_build_host or self.deployment.get("buildHost")
|
||||||
if build_host is None:
|
if build_host is None:
|
||||||
with self.target_host() as target_host:
|
yield None
|
||||||
yield target_host
|
|
||||||
return
|
return
|
||||||
# enable ssh agent forwarding to allow the build host to access the target host
|
# enable ssh agent forwarding to allow the build host to access the target host
|
||||||
yield parse_deployment_address(
|
with parse_deployment_address(
|
||||||
self.name,
|
self.name,
|
||||||
build_host,
|
build_host,
|
||||||
self.host_key_check,
|
self.host_key_check,
|
||||||
forward_agent=True,
|
forward_agent=True,
|
||||||
private_key=self.private_key,
|
private_key=self.private_key,
|
||||||
meta={"machine": self},
|
meta={"machine": self},
|
||||||
)
|
) as build_host:
|
||||||
|
yield build_host
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def deploy_as_root(self) -> bool:
|
def deploy_as_root(self) -> bool:
|
||||||
|
|||||||
@@ -47,9 +47,10 @@ class Host:
|
|||||||
self.ssh_options["ControlPath"] = str(control_path / "clan-%h-%p-%r")
|
self.ssh_options["ControlPath"] = str(control_path / "clan-%h-%p-%r")
|
||||||
self.ssh_options["ControlPersist"] = "30m"
|
self.ssh_options["ControlPersist"] = "30m"
|
||||||
|
|
||||||
def __enter__(self) -> None:
|
def __enter__(self) -> "Host":
|
||||||
self._temp_dir = TemporaryDirectory(prefix="clan-ssh-")
|
self._temp_dir = TemporaryDirectory(prefix="clan-ssh-")
|
||||||
self.setup_control_master(Path(self._temp_dir.name))
|
self.setup_control_master(Path(self._temp_dir.name))
|
||||||
|
return self
|
||||||
|
|
||||||
def __exit__(
|
def __exit__(
|
||||||
self,
|
self,
|
||||||
|
|||||||
Reference in New Issue
Block a user