resync
What is resync
?
resync
is a tool for syncing configuration files with CDF.
Why resync
?
The problem resync
is solving is to have confidence through traceability and reproducibility of the configuration
files used to create the resources in CDF. The user interface is inspired by terraform
with init
, validate
, plan
, apply
, destroy
commands. The plan
command will compare CDF with the local configuration files and output the changes that will be
applied if the apply
command is run. The apply
command will apply the changes to CDF. resync
is intended to be
run in a CI/CD pipeline, but can also be run locally.
The alternative to using resync
is to manually create the resources in CDF, and/or have custom scripts
residing on different developers local computers. This is error prone and does not provide
traceability and reproducibility.
How does resync
work?
flowchart LR
A(.yaml-files) -->|Validation| B(Pydantic Config Models)
B -->|Combine| C(Resync Models)
C --> E(Compare)
D(CDF) --> F(Resync Models)
F --> E
E -->|Upload Diff| G(CDF)
Main resync
functions
cognite.powerops.resync.init(client, is_dev=False, dry_run=False, verbose=False)
This function will create the data models in CDF that are required for resync to work. It will not overwrite existing models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
PowerOpsClient | None
|
The PowerOpsClient to use. If not provided, a new client will be created. |
required |
is_dev
|
bool
|
Whether the deployment is for development environment. If true, the models views and data models will be deleted and recreated. |
False
|
dry_run
|
bool
|
Whether to run the command as a dry run, meaning no resources will be created. |
False
|
Source code in cognite/powerops/resync/core/main.py
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 |
|
cognite.powerops.resync.validate(config_dir, market)
cognite.powerops.resync.plan(config_dir, market, client, model_names=None, dump_folder=None)
Loads the local configuration files, transform them into Resync models, and compares them to the downloaded CDF Resync models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_dir
|
Path
|
Local path to the configuration files. Needs to follow a specific structure. See below. |
required |
market
|
str
|
The market to load the configuration for. |
required |
client
|
PowerOpsClient | None
|
The PowerOpsClient to use. If not provided, a new client will be created. |
required |
model_names
|
str | list[str] | None
|
The models to run the plan. |
None
|
dump_folder
|
Optional[Path]
|
If present, the local and CDF changes will be dumped to this directory. This is done so that you can use local tools (for example, PyCharm or VS Code) to compare the detailed changes between the local and CDF configuration. |
None
|
Returns:
Type | Description |
---|---|
ModelDifferences
|
A ModelDifferences object containing the differences between the local and CDF configuration. |
Configuration file structure:
📦config_dir
┣ 📂cogshop - The CogSHOP configuration
┣ 📂market - The Market configuration for DayAhead, RKOM, and benchmarking.
┣ 📂production - The physical assets configuration, Watercourse, PriceArea, Generator, Plant (SHOP centered)
┗ 📜settings.yaml - Settings for resync.
Source code in cognite/powerops/resync/core/main.py
cognite.powerops.resync.apply(config_dir, market, client=None, model_names=None, auto_yes=False)
Loads the local configuration files, transform them into Resync models, and uploads it to CDF. Any deviations of the existing CDF configuration will be overwritten.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_dir
|
Path
|
Local path to the configuration files. Needs to follow a specific structure. See below. |
required |
market
|
str
|
The market to load the configuration for. |
required |
client
|
PowerOpsClient | None
|
The PowerOpsClient to use. If not provided, a new client will be created. |
None
|
model_names
|
str | list[str] | None
|
The models to run the plan. |
None
|
auto_yes
|
bool
|
If true, all prompts will be auto confirmed. |
False
|
Returns:
Type | Description |
---|---|
ModelDifferences
|
A ModelDifferences object containing the differences between the local and CDF configuration which have been |
ModelDifferences
|
written to CDF. |
Configuration file structure:
📦config_dir
┣ 📂cogshop - The CogSHOP configuration
┣ 📂market - The Market configuration for DayAhead, RKOM, and benchmarking.
┣ 📂production - The physical assets configuration, Watercourse, PriceArea, Generator, Plant (SHOP centered)
┗ 📜settings.yaml - Settings for resync.
Source code in cognite/powerops/resync/core/main.py
cognite.powerops.resync.destroy(client, model_names=None, auto_yes=False, dry_run=False)
Destroys all resync models in CDF. This will also delete all data in the models.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client
|
PowerOpsClient | None
|
The PowerOpsClient to use. If not provided, a new client will be created. |
required |
model_names
|
str | list[str] | None
|
The models to destroy. |
None
|
auto_yes
|
bool
|
If true, all prompts will be auto confirmed. |
False
|
dry_run
|
bool
|
If true, the models will not be deleted, but the changes will be printed. |
False
|
Returns:
Type | Description |
---|---|
ModelDifferences
|
A ModelDifferences object containing the resources that has been destroyed. |
Source code in cognite/powerops/resync/core/main.py
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 |
|