shell_utils
drunc.utils.shell_utils
Shell utilities for DRUNC.
Classes
InterruptedCommand(message='An error occurred in Drunc.', grpc_error_code=None, details=None, reason=None, domain=None, **detail_kwargs)
Bases: DruncShellException
Exception thrown to interrupt a shell command without a full stack trace.
Source code in drunc/exceptions.py
ShellContext(*args, **kwargs)
Base class for shell contexts.
Initialize the shell context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
object
|
Additional positional arguments. |
()
|
**kwargs
|
object
|
Additional keyword arguments. |
{}
|
Source code in drunc/utils/shell_utils.py
Methods:
create_drivers(**kwargs)
abstractmethod
Create drivers for the context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
object
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
MutableMapping[str, object]
|
MutableMapping[str, object]: A mapping of driver names to driver objects. |
Source code in drunc/utils/shell_utils.py
create_token(**kwargs)
abstractmethod
Create a token for the context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
object
|
Additional keyword arguments. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Token |
Token
|
A token object. |
delete_driver(name)
Delete a driver from the context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the driver to delete. |
required |
Source code in drunc/utils/shell_utils.py
get_controller_driver(quiet_fail=False)
Get the root controller driver from the context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quiet_fail
|
bool
|
If True, return None on failure instead of raising an exception. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
ControllerDriver |
ControllerDriver
|
The process manager driver. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the process manager driver is not initialized. |
Source code in drunc/utils/shell_utils.py
get_driver(name=None, quiet_fail=False)
Get a driver from the context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
The name of the driver. If None, returns the only driver if there is exactly one. |
None
|
quiet_fail
|
bool
|
If True, return None on failure instead of raising an exception. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
object |
object
|
The driver object, or None if quiet_fail is True and the driver is not found. |
Raises:
| Type | Description |
|---|---|
DruncShellException
|
If there are multiple drivers and no name is specified. |
SystemExit
|
If the driver is not found and quiet_fail is False. |
Source code in drunc/utils/shell_utils.py
get_pm_driver(quiet_fail=False)
Get the process manager driver from the context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quiet_fail
|
bool
|
If True, return None on failure instead of raising an exception. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
ProcessManagerDriver |
ProcessManagerDriver
|
The process manager driver. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the process manager driver is not initialized. |
Source code in drunc/utils/shell_utils.py
get_shell_id()
Get the shell ID.
This is primarily used by the superclasses of the ShellContext to identify the type of shell (e.g., PM shell, Unified shell) for logging purposes.
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The shell ID, or None if not set. |
Source code in drunc/utils/shell_utils.py
get_token()
has_driver(name)
Check if a driver exists in the context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the driver. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the driver exists, False otherwise. |
print(*args, **kwargs)
Print to the console.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
object
|
Positional arguments to pass to the console. |
()
|
**kwargs
|
object
|
Keyword arguments to pass to the console. |
{}
|
Source code in drunc/utils/shell_utils.py
print_status_summary()
Print a summary of the FSM status and available transitions.
Source code in drunc/utils/shell_utils.py
reset(*args, **kwargs)
abstractmethod
Reset the shell context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
object
|
Additional positional arguments. |
()
|
**kwargs
|
object
|
Additional keyword arguments. |
{}
|
rule(*args, **kwargs)
Print a rule to the console.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
object
|
Positional arguments to pass to the console. |
()
|
**kwargs
|
object
|
Keyword arguments to pass to the console. |
{}
|
Source code in drunc/utils/shell_utils.py
set_driver(name, driver)
Set a driver in the context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the driver. |
required |
driver
|
object
|
The driver object. |
required |
Raises:
| Type | Description |
|---|---|
DruncShellException
|
If a driver with the same name already exists. |
Source code in drunc/utils/shell_utils.py
Functions:
create_dummy_token_from_uname()
Create a dummy token from the current username.
Returns:
| Name | Type | Description |
|---|---|---|
Token |
Token
|
A dummy token with the current username. |
Source code in drunc/utils/shell_utils.py
log_pm_cmd(obj)
Log a process-manager shell command with only explicitly provided arguments.
The current Click command context is inspected and only parameters whose source is
COMMANDLINE are included in the log message. This keeps defaulted values out
of the message while still recording the command name, optional session name, and
shell identity.
These are sent over via so that it can be displayed in the process manager shell
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
ShellContext
|
Active shell context used to send the log message. |
required |