Skip to content

Commit 8f6856b

Browse files
authored
SIMPLE-6967 - add pubkey for user create and update, add testbed key_… (#151)
* SIMPLE-6967 - add pubkey for user create and update, add testbed key_path setting
1 parent 661ab05 commit 8f6856b

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

virl2_client/models/cl_pyats.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from __future__ import annotations
2222

2323
import io
24+
from pathlib import Path
2425
from typing import TYPE_CHECKING, Any
2526

2627
try:
@@ -116,10 +117,23 @@ def sync_testbed(self, username: str, password: str) -> None:
116117
"""
117118
self._check_pyats_installed()
118119
testbed_yaml = self._lab.get_pyats_testbed(self._hostname)
119-
testbed = self._load_pyats_testbed(testbed_yaml)
120-
testbed.devices.terminal_server.credentials.default.username = username
121-
testbed.devices.terminal_server.credentials.default.password = password
122-
self._testbed = testbed
120+
self._testbed = self._load_pyats_testbed(testbed_yaml)
121+
self.set_termserv_credentials(username, password)
122+
123+
def set_termserv_credentials(
124+
self,
125+
username: str | None = None,
126+
password: str | None = None,
127+
key_path: Path | str | None = None,
128+
) -> None:
129+
terminal = self._testbed.devices.terminal_server
130+
if username is not None:
131+
terminal.credentials.default.username = username
132+
if password is not None:
133+
terminal.credentials.default.password = password
134+
if key_path is not None:
135+
ssh_options = f"-o IdentitiesOnly=yes -o IdentityFile={key_path}"
136+
terminal.connections.cli.ssh_options = ssh_options
123137

124138
def _prepare_params(
125139
self,

virl2_client/models/user.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def create_user(self, username: str, pwd: str, **kwargs: Any) -> dict:
9494
- resource_pool: Resource pool to which the user should be added.
9595
- opt_in: Whether the user has seen the initial contact dialog.
9696
- tour_version: The version of the Workbench tour the user has completed.
97+
- pubkey: An SSH public key for terminal server. Empty string to clear.
9798
9899
:returns: User object.
99100
"""
@@ -120,6 +121,7 @@ def update_user(self, user_id: str, **kwargs: Any) -> dict:
120121
- resource_pool: Resource pool to which the user should be added.
121122
- opt_in: Whether the user has seen the initial contact dialog.
122123
- tour_version: The version of the Workbench tour the user has completed.
124+
- pubkey: An SSH public key for terminal server. Empty string to clear.
123125
124126
:returns: User object.
125127
"""
@@ -138,6 +140,7 @@ def _prepare_body(
138140
associations: list[dict[str, list[str]]] | None = None,
139141
admin: bool | None = None,
140142
password_dict: dict[str, str] | None = None,
143+
pubkey: str | None = None,
141144
resource_pool: str | None | _Sentinel = UNCHANGED,
142145
opt_in: bool | None | _Sentinel = UNCHANGED,
143146
tour_version: str | None = None,
@@ -150,6 +153,7 @@ def _prepare_body(
150153
"groups": groups,
151154
"associations": associations,
152155
"password": password_dict,
156+
"pubkey": pubkey,
153157
"tour_version": tour_version,
154158
}
155159
sentinel_data = {

0 commit comments

Comments
 (0)