Skip to content

Commit

Permalink
Fix AiidaComputerSetup widget. (#305)
Browse files Browse the repository at this point in the history
The widget wasn't working correctly as during the computer configuration
the value for the ssh port was of type "str". The issue is fixed by converting
the value type to "int".

Additionally, the `_configure_computer` function got slightly simplified by using
the `Computer.configure()` method provided by AiiDA.
  • Loading branch information
yakutovicha authored Apr 19, 2022
1 parent ed1627a commit 7d56d78
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions aiidalab_widgets_base/computational_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,22 +697,26 @@ def __init__(self, **kwargs):

super().__init__(children, **kwargs)

def _configure_computer(self):
"""Create AuthInfo."""
def _configure_computer(self, computer):
"""Configure the computer"""
sshcfg = parse_sshconfig(self.hostname.value)
authparams = {
"compress": True,
"port": int(sshcfg.get("port", 22)),
"look_for_keys": True,
"key_filename": os.path.expanduser(
sshcfg.get("identityfile", ["~/.ssh/id_rsa"])[0]
),
"timeout": 60,
"allow_agent": True,
"proxy_jump": "",
"proxy_command": "",
"compress": True,
"gss_auth": False,
"gss_kex": False,
"gss_deleg_creds": False,
"gss_host": self.hostname.value,
"gss_kex": False,
"key_policy": "WarningPolicy",
"load_system_host_keys": True,
"port": sshcfg.get("port", 22),
"timeout": 60,
"key_policy": "WarningPolicy",
"use_login_shell": self.use_login_shell.value,
"safe_interval": self.safe_interval.value,
}
Expand All @@ -728,13 +732,8 @@ def _configure_computer(self):
authparams["proxy_command"] = sshcfg["proxycommand"]
elif "proxyjump" in sshcfg:
authparams["proxy_jump"] = sshcfg["proxyjump"]
aiidauser = orm.User.objects.get_default()

authinfo = orm.AuthInfo(
computer=orm.Computer.objects.get(label=self.label.value), user=aiidauser
)
authinfo.set_auth_params(authparams)
authinfo.store()
computer.configure(**authparams)
return True

def on_setup_computer(self, _=None, on_success=None):
Expand Down Expand Up @@ -785,7 +784,7 @@ def on_setup_computer(self, _=None, on_success=None):
print(f"Unable to store the computer: {err}.")
return

if self._configure_computer():
if self._configure_computer(computer):
if on_success:
on_success()
print(f"Computer<{computer.pk}> {computer.label} created")
Expand Down

0 comments on commit 7d56d78

Please sign in to comment.