shell_utils
drunc.utils.shell_utils
Shell utilities for DRUNC.
Classes
CommandLike
Bases: Protocol
Protocol for command-like objects.
ControllerDriverProtocol
Bases: Protocol
Protocol for controller driver objects.
Methods:
describe_fsm()
Describe the FSM.
Returns:
| Name | Type | Description |
|---|---|---|
DescribeFSMReplyLike |
DescribeFSMReplyLike
|
The FSM description. |
DecodedResponse(name, token, flag, data=None, children=None)
Decoded response object.
Warning: This should be kept in sync with druncschema/request_response.proto/Response class
Initialize a DecodedResponse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the response. |
required |
token
|
Token
|
The token associated with the response. |
required |
flag
|
object
|
The response flag. |
required |
data
|
object | None
|
The response data. Defaults to None. |
None
|
children
|
list[DecodedResponse] | None
|
Child responses. Defaults to None. |
None
|
Source code in drunc/utils/shell_utils.py
Methods:
__str__()
Return string representation of the DecodedResponse.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The string representation. |
to_string(obj, prefix='')
staticmethod
Convert a DecodedResponse to a string representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
DecodedResponse
|
The DecodedResponse to convert. |
required |
prefix
|
str
|
A prefix to add to the string. Defaults to empty string. |
''
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The string representation of the response. |
Source code in drunc/utils/shell_utils.py
DescribeFSMReplyLike
Bases: Protocol
Protocol for describe FSM reply-like objects.
FSMDescriptionLike
Bases: Protocol
Protocol for FSM description-like objects.
InterruptedCommand(message='An error occurred in Drunc.', grpc_error_code=None, details=None, **detail_kwargs)
Bases: DruncShellException
Exception thrown to interrupt a shell command without a full stack trace.
Source code in drunc/exceptions.py
SequenceLike
Bases: Protocol
Protocol for sequence-like objects.
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_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_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(**kwargs)
abstractmethod
Reset the shell context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**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
StatusLike
Bases: Protocol
Protocol for status-like objects.
StatusReplyLike
Bases: Protocol
Protocol for status reply-like objects.
Functions:
add_traceback_flag()
Add a traceback flag to a command.
Returns:
| Name | Type | Description |
|---|---|---|
Callable |
Callable[[Callable[P, R]], Callable[P, R]]
|
A decorator that adds the traceback flag. |
Source code in drunc/utils/shell_utils.py
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. |