cloudmesh-ai-ssh API Reference
This page provides the API reference for the cloudmesh-ai-ssh library.
API Documentation
Attributes
Classes
SSHConfig
Bases: SSHBase
Managing the SSH config file (usually ~/.ssh/config).
Source code in src/cloudmesh/ai/ssh/ssh_config.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 | |
Methods:
__str__
The string representation of the config as JSON.
Source code in src/cloudmesh/ai/ssh/ssh_config.py
check
Check the SSH config file for malformed entries.
Returns:
| Type | Description |
|---|---|
List[Dict]
|
List[Dict]: A list of errors found. Each error contains 'line' and 'message'. |
Source code in src/cloudmesh/ai/ssh/ssh_config.py
delete
Removes a host entry from the SSH config file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
the name of the host to remove. |
required |
Source code in src/cloudmesh/ai/ssh/ssh_config.py
execute
Execute the command on the named host.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
the name of the host in config. |
required |
command
|
str
|
the command to be executed. |
required |
use_pty
|
bool
|
whether to allocate a pseudo-terminal. |
False
|
Returns:
| Type | Description |
|---|---|
Union[CommandResult, str]
|
Union[CommandResult, str]: CommandResult for remote, stdout for local. |
Source code in src/cloudmesh/ai/ssh/ssh_config.py
execute_parallel
Execute the same command on multiple hosts in parallel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hosts
|
List[str]
|
list of host names. |
required |
command
|
str
|
the command to execute. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, CommandResult]
|
Dict[str, CommandResult]: mapping of host to its result. |
Source code in src/cloudmesh/ai/ssh/ssh_config.py
generate
Adds a host to the config file with given parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
the alias for the host. |
required |
hostname
|
str
|
the actual hostname or IP. |
required |
identity
|
Optional[str]
|
the path to the identity file. |
None
|
user
|
Optional[str]
|
the username for the host. |
None
|
verbose
|
bool
|
prints debug messages. |
False
|
Source code in src/cloudmesh/ai/ssh/ssh_config.py
get_content
Return the raw content of the SSH config file.
Source code in src/cloudmesh/ai/ssh/ssh_config.py
get_options
Get configuration options for a host that are explicitly defined in the config file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
the host name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
comma-separated string of options. |
Source code in src/cloudmesh/ai/ssh/ssh_config.py
get_tunnels
Extract all tunnel forwards (LocalForward, RemoteForward) from the config.
Returns:
| Type | Description |
|---|---|
List[Dict]
|
List[Dict]: A list of tunnel definitions. |
Source code in src/cloudmesh/ai/ssh/ssh_config.py
hostname
Returns the actual HostName for the given host.
list
List the hosts defined in the config file.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: list of host names. |
Source code in src/cloudmesh/ai/ssh/ssh_config.py
load
Parse the SSH config file using sshconf.
local
Execute the command on the localhost.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
the command to execute. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
the output of the command. |
login
Login to the host defined in .ssh/config by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
the name of the host as defined in the config file. |
required |
Source code in src/cloudmesh/ai/ssh/ssh_config.py
names
sudo_execute
Execute the command on the named host with sudo.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
the name of the host in config. |
required |
command
|
str
|
the command to be executed. |
required |
use_pty
|
bool
|
whether to allocate a pseudo-terminal. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
CommandResult |
CommandResult
|
structured result of the execution. |
Source code in src/cloudmesh/ai/ssh/ssh_config.py
username
Returns the username for a given host, falling back to local user.
Source code in src/cloudmesh/ai/ssh/ssh_config.py
yaml
Returns the parsed SSH configuration in YAML format.
Returns:
| Type | Description |
|---|---|
str
|
A YAML string representation of the parsed hosts dictionary. |
Source code in src/cloudmesh/ai/ssh/ssh_config.py
SSHTunnelError
Telemetry
Handles structured telemetry emission for AI commands. Supports multiple backends for flexible data export.
Source code in cloudmesh/ai/common/telemetry.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
Methods:
__init__
Initialize the Telemetry collector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command_name
|
str
|
Name of the command emitting telemetry. |
required |
telemetry_file
|
Optional[Union[str, Path]]
|
Backward compatibility: path to a JSONL file. |
None
|
backends
|
Optional[List[TelemetryBackend]]
|
List of TelemetryBackend implementations to use. |
None
|
Source code in cloudmesh/ai/common/telemetry.py
complete
Helper to emit a 'completed' status with final metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
Optional[Dict[str, Any]]
|
A dictionary of final KPIs and measurements. |
None
|
message
|
Optional[str]
|
An optional human-readable message. |
'Command completed successfully'
|
**kwargs
|
Any
|
Additional metrics to include in the record. |
{}
|
Source code in cloudmesh/ai/common/telemetry.py
emit
Emits a structured telemetry record to all configured backends.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
str
|
The current status of the command (e.g., 'started', 'completed', 'failed'). |
required |
metrics
|
Optional[Dict[str, Any]]
|
A dictionary of KPIs and measurements. |
None
|
message
|
Optional[str]
|
An optional human-readable message. |
None
|
stdout
|
bool
|
If True, prints the JSON record to stdout. |
False
|
Source code in cloudmesh/ai/common/telemetry.py
fail
Helper to emit a 'failed' status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error
|
str
|
The error message to record. |
required |
metrics
|
Optional[Dict[str, Any]]
|
A dictionary of KPIs at the time of failure. |
None
|
**kwargs
|
Any
|
Additional metrics to include in the record. |
{}
|
Source code in cloudmesh/ai/common/telemetry.py
start
Helper to emit a 'started' status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
Optional[str]
|
Optional message for the start event. |
None
|
**kwargs
|
Any
|
Additional metrics to include in the record. |
{}
|
Source code in cloudmesh/ai/common/telemetry.py
track
Context manager to automatically track the start and completion of a task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
Optional[str]
|
Optional message for the start event. |
None
|
metrics
|
Optional[Dict[str, Any]]
|
Initial metrics to include. |
None
|
Source code in cloudmesh/ai/common/telemetry.py
Tunnel
Bases: SSHBase
Manages an SSH tunnel for port forwarding.
Source code in src/cloudmesh/ai/ssh/tunnel.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
Methods:
__enter__
__exit__
force_stop
Forcefully terminates any process bound to the local port using lsof.
This is useful for cleaning up zombie tunnels that were not started by this specific Tunnel instance.
Source code in src/cloudmesh/ai/ssh/tunnel.py
is_active
Checks if the tunnel process is still running and port is open.
start
Starts the SSH tunnel in the background.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
int
|
seconds to wait for the port to open. |
10
|
Source code in src/cloudmesh/ai/ssh/tunnel.py
stop
Stops the SSH tunnel process.
Source code in src/cloudmesh/ai/ssh/tunnel.py
Functions:
_render_table
Helper to render a list of dictionaries as a rich table.
Source code in src/cloudmesh/ai/command/ssh.py
_save_fallback
check_ai
Gather diagnostic data and submit it to the vLLM server for repair.
Source code in src/cloudmesh/ai/command/ssh.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
check_basic
Run basic SSH config validation.
Source code in src/cloudmesh/ai/command/ssh.py
check_group
Check the SSH config file for malformed entries.
get_contextual_logger
Factory function to create a ContextualLogger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the logger. |
required |
initial_context
|
Optional[Dict[str, Any]]
|
Initial context to associate with the logger. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ContextualLogger |
ContextualLogger
|
A logger adapter with the specified context. |
Source code in cloudmesh/ai/common/logging_utils.py
hosts_cmd
List all hosts defined in the SSH config file.
Source code in src/cloudmesh/ai/command/ssh.py
list_group
List SSH configurations and active tunnels.
load_llm_config
Load LLM configuration from ~/.config/cloudmesh/ai/llm.yaml, creating it if missing.
Source code in src/cloudmesh/ai/command/ssh.py
path_expand
register
run_cmd
ssh_group
test_path_cmd
Example command showing path expansion.
tunnel_cmd
Create an SSH tunnel.
Target should be in the format HOST:PORT (e.g., my-server:8000).
Source code in src/cloudmesh/ai/command/ssh.py
tunnel_list_cmd
List all tunnels defined in config and their active status.