gufo.thor.state¶
Persistent state management for Gufo Thor installations.
Attributes:
| Name | Type | Description |
|---|---|---|
state |
Current persistent state of the Gufo Thor installation. |
State
dataclass
¶
Persistent state of a Gufo Thor installation.
Attributes:
| Name | Type | Description |
|---|---|---|
noc_version |
str | None
|
NOC version associated with the current installation state. |
mongo_fcv |
str | None
|
MongoDB Feature Compatibility Version (FCV) associated with the current installation state. |
apply(other)
¶
Apply values from another state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
State
|
State to copy values from. |
required |
from_file(path)
classmethod
¶
Load installation state from a file.
If the file does not exist, an empty state is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the state file. |
required |
Returns:
| Type | Description |
|---|---|
State
|
Loaded installation state. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the state file does not contain a JSON object. |
save()
¶
Save the current installation state to the state file.
The state is written to a temporary file and atomically moved to the target path to avoid leaving a partially written state file.
with_state(new_state=None)
¶
Temporarily replace the global installation state.
Changes to the global state and state file are isolated to the context. The original state and state file path are restored when leaving the context, including when an exception is raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_state
|
State | None
|
State to use inside the context. If not specified, an empty state is used. |
None
|
Yields:
| Type | Description |
|---|---|
Generator[State]
|
The temporary installation state. |