ntermqt 0.1.6__py3-none-any.whl → 0.1.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nterm/parser/tfsm_fire_tester.py +561 -731
- nterm/scripting/api.py +96 -44
- nterm/scripting/repl.py +6 -2
- {ntermqt-0.1.6.dist-info → ntermqt-0.1.7.dist-info}/METADATA +1 -1
- {ntermqt-0.1.6.dist-info → ntermqt-0.1.7.dist-info}/RECORD +8 -8
- {ntermqt-0.1.6.dist-info → ntermqt-0.1.7.dist-info}/WHEEL +0 -0
- {ntermqt-0.1.6.dist-info → ntermqt-0.1.7.dist-info}/entry_points.txt +0 -0
- {ntermqt-0.1.6.dist-info → ntermqt-0.1.7.dist-info}/top_level.txt +0 -0
nterm/scripting/api.py
CHANGED
|
@@ -835,21 +835,25 @@ class NTermAPI:
|
|
|
835
835
|
|
|
836
836
|
return '\n'.join(cleaned_lines).strip()
|
|
837
837
|
|
|
838
|
-
def connect(self, device: str, credential: str = None) -> ActiveSession:
|
|
838
|
+
def connect(self, device: str, credential: str = None, debug: bool = False) -> ActiveSession:
|
|
839
839
|
"""
|
|
840
840
|
Connect to a device and detect platform.
|
|
841
841
|
|
|
842
842
|
Args:
|
|
843
843
|
device: Device name (from saved sessions) or hostname
|
|
844
844
|
credential: Optional credential name (auto-resolved if not specified)
|
|
845
|
+
debug: Enable verbose connection debugging
|
|
845
846
|
|
|
846
847
|
Returns:
|
|
847
848
|
ActiveSession handle for sending commands
|
|
848
|
-
|
|
849
|
-
Examples:
|
|
850
|
-
session = api.connect("spine1")
|
|
851
|
-
session = api.connect("192.168.1.1", credential="lab-admin")
|
|
852
849
|
"""
|
|
850
|
+
debug_log = []
|
|
851
|
+
|
|
852
|
+
def _debug(msg):
|
|
853
|
+
if debug:
|
|
854
|
+
debug_log.append(msg)
|
|
855
|
+
print(f"[DEBUG] {msg}")
|
|
856
|
+
|
|
853
857
|
# Look up device from saved sessions first
|
|
854
858
|
device_info = self.device(device)
|
|
855
859
|
|
|
@@ -859,21 +863,21 @@ class NTermAPI:
|
|
|
859
863
|
device_name = device_info.name
|
|
860
864
|
saved_cred = device_info.credential
|
|
861
865
|
else:
|
|
862
|
-
# Treat as hostname directly
|
|
863
866
|
hostname = device
|
|
864
867
|
port = 22
|
|
865
868
|
device_name = device
|
|
866
869
|
saved_cred = None
|
|
867
870
|
|
|
871
|
+
_debug(f"Target: {hostname}:{port}")
|
|
872
|
+
|
|
868
873
|
# Resolve credentials
|
|
869
874
|
if not self.vault_unlocked:
|
|
870
875
|
raise RuntimeError("Vault is locked. Call api.unlock(password) first.")
|
|
871
876
|
|
|
872
|
-
# Get credential - either specified or from saved session or auto-resolve
|
|
873
877
|
cred_name = credential or saved_cred
|
|
878
|
+
_debug(f"Credential: {cred_name or '(auto-resolve)'}")
|
|
874
879
|
|
|
875
880
|
if cred_name:
|
|
876
|
-
# User specified a credential name - use resolver's method
|
|
877
881
|
try:
|
|
878
882
|
profile = self._resolver.create_profile_for_credential(
|
|
879
883
|
credential_name=cred_name,
|
|
@@ -883,7 +887,6 @@ class NTermAPI:
|
|
|
883
887
|
except Exception as e:
|
|
884
888
|
raise ValueError(f"Failed to get credential '{cred_name}': {e}")
|
|
885
889
|
else:
|
|
886
|
-
# Auto-resolve based on hostname patterns
|
|
887
890
|
try:
|
|
888
891
|
profile = self._resolver.resolve_for_device(hostname, port=port)
|
|
889
892
|
except Exception as e:
|
|
@@ -892,10 +895,6 @@ class NTermAPI:
|
|
|
892
895
|
if not profile:
|
|
893
896
|
raise ValueError(f"No credentials available for {hostname}")
|
|
894
897
|
|
|
895
|
-
# Create SSH client
|
|
896
|
-
client = paramiko.SSHClient()
|
|
897
|
-
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
898
|
-
|
|
899
898
|
# Apply legacy algorithm support
|
|
900
899
|
_apply_global_transport_settings()
|
|
901
900
|
|
|
@@ -909,24 +908,27 @@ class NTermAPI:
|
|
|
909
908
|
}
|
|
910
909
|
|
|
911
910
|
# Add authentication from profile
|
|
912
|
-
|
|
911
|
+
auth_method_used = None
|
|
913
912
|
if profile.auth_methods:
|
|
914
913
|
first_auth = profile.auth_methods[0]
|
|
915
914
|
connect_kwargs['username'] = first_auth.username
|
|
915
|
+
_debug(f"Username: {first_auth.username}")
|
|
916
916
|
|
|
917
|
-
# Try each auth method in order
|
|
918
917
|
for auth in profile.auth_methods:
|
|
919
918
|
if auth.method == AuthMethod.PASSWORD:
|
|
920
919
|
connect_kwargs['password'] = auth.password
|
|
920
|
+
auth_method_used = "password"
|
|
921
|
+
_debug("Auth method: password")
|
|
921
922
|
break
|
|
922
923
|
elif auth.method == AuthMethod.KEY_FILE:
|
|
923
|
-
connect_kwargs['key_filename'] = auth.
|
|
924
|
+
connect_kwargs['key_filename'] = auth.key_path
|
|
925
|
+
if auth.key_passphrase:
|
|
926
|
+
connect_kwargs['passphrase'] = auth.key_passphrase
|
|
927
|
+
auth_method_used = f"key_file:{auth.key_path}"
|
|
928
|
+
_debug(f"Auth method: key_file ({auth.key_path})")
|
|
924
929
|
break
|
|
925
930
|
elif auth.method == AuthMethod.KEY_STORED:
|
|
926
|
-
# KEY_STORED has key data as string, need to write to temp file
|
|
927
931
|
import tempfile
|
|
928
|
-
from io import StringIO
|
|
929
|
-
|
|
930
932
|
key_file = tempfile.NamedTemporaryFile(
|
|
931
933
|
mode='w',
|
|
932
934
|
delete=False,
|
|
@@ -934,42 +936,93 @@ class NTermAPI:
|
|
|
934
936
|
)
|
|
935
937
|
key_file.write(auth.key_data)
|
|
936
938
|
key_file.close()
|
|
937
|
-
|
|
938
939
|
connect_kwargs['key_filename'] = key_file.name
|
|
939
940
|
if auth.key_passphrase:
|
|
940
941
|
connect_kwargs['passphrase'] = auth.key_passphrase
|
|
942
|
+
auth_method_used = "key_stored"
|
|
943
|
+
_debug(f"Auth method: key_stored (temp: {key_file.name})")
|
|
941
944
|
break
|
|
942
945
|
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
946
|
+
# Detect key type if using key auth
|
|
947
|
+
if 'key_filename' in connect_kwargs:
|
|
948
|
+
key_path = connect_kwargs['key_filename']
|
|
949
|
+
key_type = "unknown"
|
|
950
|
+
key_bits = None
|
|
951
|
+
try:
|
|
952
|
+
key = paramiko.RSAKey.from_private_key_file(key_path)
|
|
953
|
+
key_type = "RSA"
|
|
954
|
+
key_bits = key.get_bits()
|
|
955
|
+
except:
|
|
956
|
+
try:
|
|
957
|
+
key = paramiko.Ed25519Key.from_private_key_file(key_path)
|
|
958
|
+
key_type = "Ed25519"
|
|
959
|
+
except:
|
|
960
|
+
try:
|
|
961
|
+
key = paramiko.ECDSAKey.from_private_key_file(key_path)
|
|
962
|
+
key_type = "ECDSA"
|
|
963
|
+
except:
|
|
964
|
+
pass
|
|
965
|
+
_debug(f"Key type: {key_type}" + (f" ({key_bits} bits)" if key_bits else ""))
|
|
966
|
+
|
|
967
|
+
# Connection attempt sequence
|
|
968
|
+
attempts = [
|
|
969
|
+
("modern", None),
|
|
970
|
+
("rsa-sha1", RSA_SHA1_DISABLED_ALGORITHMS),
|
|
971
|
+
]
|
|
952
972
|
|
|
953
|
-
|
|
973
|
+
last_error = None
|
|
974
|
+
connected = False
|
|
975
|
+
client = None
|
|
976
|
+
|
|
977
|
+
for attempt_name, disabled_algs in attempts:
|
|
978
|
+
client = paramiko.SSHClient()
|
|
979
|
+
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
980
|
+
|
|
981
|
+
_debug(f"Attempt: {attempt_name}")
|
|
982
|
+
|
|
983
|
+
attempt_kwargs = connect_kwargs.copy()
|
|
984
|
+
if disabled_algs:
|
|
985
|
+
attempt_kwargs['disabled_algorithms'] = disabled_algs
|
|
986
|
+
_debug(f" disabled_algorithms: {disabled_algs}")
|
|
987
|
+
|
|
988
|
+
try:
|
|
989
|
+
client.connect(**attempt_kwargs)
|
|
990
|
+
connected = True
|
|
991
|
+
|
|
992
|
+
# Log successful negotiation
|
|
954
993
|
transport = client.get_transport()
|
|
955
994
|
if transport:
|
|
956
|
-
transport.
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
)
|
|
995
|
+
_debug(f" SUCCESS - cipher: {transport.remote_cipher}, mac: {transport.remote_mac}")
|
|
996
|
+
_debug(f" host_key_type: {transport.host_key_type}")
|
|
997
|
+
break
|
|
960
998
|
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
999
|
+
except paramiko.AuthenticationException as e:
|
|
1000
|
+
_debug(f" FAILED (auth): {e}")
|
|
1001
|
+
last_error = str(e)
|
|
1002
|
+
client.close()
|
|
1003
|
+
except paramiko.SSHException as e:
|
|
1004
|
+
_debug(f" FAILED (ssh): {e}")
|
|
1005
|
+
last_error = str(e)
|
|
1006
|
+
client.close()
|
|
1007
|
+
except Exception as e:
|
|
1008
|
+
_debug(f" FAILED (other): {e}")
|
|
1009
|
+
last_error = str(e)
|
|
1010
|
+
client.close()
|
|
1011
|
+
|
|
1012
|
+
if not connected:
|
|
1013
|
+
# Build detailed error message
|
|
1014
|
+
error_detail = f"Connection failed: {last_error}"
|
|
1015
|
+
if debug:
|
|
1016
|
+
error_detail += f"\n\nDebug log:\n" + "\n".join(debug_log)
|
|
1017
|
+
raise paramiko.AuthenticationException(error_detail)
|
|
964
1018
|
|
|
965
1019
|
# Open interactive shell
|
|
966
1020
|
shell = client.invoke_shell(width=200, height=50)
|
|
967
1021
|
shell.settimeout(0.5)
|
|
968
1022
|
|
|
969
|
-
# Wait for initial prompt
|
|
970
1023
|
prompt = self._wait_for_prompt(shell)
|
|
1024
|
+
_debug(f"Prompt detected: {prompt}")
|
|
971
1025
|
|
|
972
|
-
# Create session object
|
|
973
1026
|
session = ActiveSession(
|
|
974
1027
|
device_name=device_name,
|
|
975
1028
|
hostname=hostname,
|
|
@@ -984,10 +1037,11 @@ class NTermAPI:
|
|
|
984
1037
|
version_output = self._send_command(shell, "show version", prompt)
|
|
985
1038
|
platform = self._detect_platform(version_output)
|
|
986
1039
|
session.platform = platform
|
|
1040
|
+
_debug(f"Platform detected: {platform}")
|
|
987
1041
|
except Exception as e:
|
|
988
|
-
|
|
1042
|
+
_debug(f"Platform detection failed: {e}")
|
|
989
1043
|
|
|
990
|
-
# Disable terminal paging
|
|
1044
|
+
# Disable terminal paging
|
|
991
1045
|
try:
|
|
992
1046
|
if session.platform and 'cisco' in session.platform:
|
|
993
1047
|
self._send_command(shell, "terminal length 0", prompt, timeout=5)
|
|
@@ -996,11 +1050,9 @@ class NTermAPI:
|
|
|
996
1050
|
elif session.platform == 'arista_eos':
|
|
997
1051
|
self._send_command(shell, "terminal length 0", prompt, timeout=5)
|
|
998
1052
|
except Exception as e:
|
|
999
|
-
|
|
1053
|
+
_debug(f"Failed to disable paging: {e}")
|
|
1000
1054
|
|
|
1001
|
-
# Track active session
|
|
1002
1055
|
self._active_sessions[device_name] = session
|
|
1003
|
-
|
|
1004
1056
|
return session
|
|
1005
1057
|
|
|
1006
1058
|
def send(
|
nterm/scripting/repl.py
CHANGED
|
@@ -219,12 +219,16 @@ class NTermREPL:
|
|
|
219
219
|
if not self.state.api.vault_unlocked:
|
|
220
220
|
return self._err("Vault is locked. Run :unlock <password> first.")
|
|
221
221
|
|
|
222
|
-
# Single active session policy by default
|
|
223
222
|
if self.state.session:
|
|
224
223
|
self._safe_disconnect()
|
|
225
224
|
|
|
226
225
|
try:
|
|
227
|
-
|
|
226
|
+
# Pass debug flag from REPL state
|
|
227
|
+
sess = self.state.api.connect(
|
|
228
|
+
device,
|
|
229
|
+
credential=cred,
|
|
230
|
+
debug=self.state.debug_mode # <-- This line
|
|
231
|
+
)
|
|
228
232
|
self.state.session = sess
|
|
229
233
|
self.state.connected_device = sess.device_name
|
|
230
234
|
|
|
@@ -18,11 +18,11 @@ nterm/parser/api_help_dialog.py,sha256=qcmgNKjge8xwVNZeKZFu47Zn0SxZjyzE7cv9h91XG
|
|
|
18
18
|
nterm/parser/ntc_download_dialog.py,sha256=TGaMCxKBTIOhGNUoLEJLnD0uAnwYWdbHdb9PRZEY604,14151
|
|
19
19
|
nterm/parser/tfsm_engine.py,sha256=6p4wrNa9tQRuCmWgsR4E3rZTprpLmii5PNjoGpCQBCw,7954
|
|
20
20
|
nterm/parser/tfsm_fire.py,sha256=AHbN6p4HlgcYDjLWb67CF9YfMSTk-3aetMswmEZyRVc,9222
|
|
21
|
-
nterm/parser/tfsm_fire_tester.py,sha256=
|
|
21
|
+
nterm/parser/tfsm_fire_tester.py,sha256=h2CAqTS6ZNHMUr4di2DBRHAWbBGiUTliOvm5jVG4ltI,79146
|
|
22
22
|
nterm/scripting/__init__.py,sha256=vxbODaXR0IPneja3BuDHmjsHzQg03tFWtHO4Rc6vCTk,1099
|
|
23
|
-
nterm/scripting/api.py,sha256=
|
|
23
|
+
nterm/scripting/api.py,sha256=9Gnxyscu3ZYNagYWGn_-5zX6O0-j8UJ_gM6PEbdHuEA,48540
|
|
24
24
|
nterm/scripting/cli.py,sha256=W2DK4ZnuutaArye_to7CBchg0ogClURxVbGsMdnj1y0,9187
|
|
25
|
-
nterm/scripting/repl.py,sha256=
|
|
25
|
+
nterm/scripting/repl.py,sha256=VebSJu6dML7Ef0J4wLL8szdPESvsS2G8T5moyuF7nnU,14335
|
|
26
26
|
nterm/scripting/repl_interactive.py,sha256=adpwRsbSfALS_0bwZPFayKUCyQefgvnO5uZwIWqKNFY,14880
|
|
27
27
|
nterm/session/__init__.py,sha256=FkgHF1WPz78JBOWHSC7LLynG2NqoR6aanNTRlEzsO6I,1612
|
|
28
28
|
nterm/session/askpass_ssh.py,sha256=U-frmLBIXwE2L5ZCEtai91G1dVRSWKLCtxn88t_PqGs,14083
|
|
@@ -61,8 +61,8 @@ nterm/vault/manager_ui.py,sha256=qle-W40j6L_pOR0AaOCeyU8myizFTRkISNrloCn0H_Y,345
|
|
|
61
61
|
nterm/vault/profile.py,sha256=qM9TJf68RKdjtxo-sJehO7wS4iTi2G26BKbmlmHLA5M,6246
|
|
62
62
|
nterm/vault/resolver.py,sha256=GWB2YR9H1MH98RGQBKvitIsjWT_-wSMLuddZNz4wbns,7800
|
|
63
63
|
nterm/vault/store.py,sha256=_0Lfe0WKjm3uSAtxgn9qAPlpBOLCuq9SVgzqsE_qaGQ,21199
|
|
64
|
-
ntermqt-0.1.
|
|
65
|
-
ntermqt-0.1.
|
|
66
|
-
ntermqt-0.1.
|
|
67
|
-
ntermqt-0.1.
|
|
68
|
-
ntermqt-0.1.
|
|
64
|
+
ntermqt-0.1.7.dist-info/METADATA,sha256=Q1Dz7d9n2AEzMW048T195_Zp062eYKSicxtqH1e1n9o,13624
|
|
65
|
+
ntermqt-0.1.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
66
|
+
ntermqt-0.1.7.dist-info/entry_points.txt,sha256=Gunr-_3w-aSpfqoMuGKM2PJSCRo9hZ7K1BksUtp1yd8,130
|
|
67
|
+
ntermqt-0.1.7.dist-info/top_level.txt,sha256=bZdnNLTHNRNqo9jsOQGUWF7h5st0xW_thH0n2QOxWUo,6
|
|
68
|
+
ntermqt-0.1.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|