API¶
cli
¶
cli(context)
¶
Create and manage Google Cloud Workstation.
Source code in src/workstation/cli/__init__.py
21 22 23 24 25 |
|
crud
¶
crud module provides command-line interface (CLI) commands for managing workstations.
Include functionalities to create, delete, list, start, and stop workstations, as well as manage workstation configurations.
Functions:
Name | Description |
---|---|
get_gcloud_config |
Retrieve GCP configuration details including project, location, and account. |
common_options |
Apply common CLI options to commands. |
create |
Create a workstation. |
list_configs |
List workstation configurations. |
list |
List workstations. |
start |
Start workstation and optionally open it either locally with VSCode or through VSCode in a browser. |
stop |
Stop workstation. |
delete |
Delete workstation. |
sync |
Sync files to workstation. |
logs |
Open logs for the workstation. |
common_options(func)
¶
Apply common CLI options to commands.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
callable
|
The function to apply the options to. |
required |
Returns:
Type | Description |
---|---|
callable
|
The function with common options applied. |
Source code in src/workstation/cli/crud.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
|
create(context, cluster, config, location, name, project, proxy, no_proxy, envs, **kwargs)
¶
Create a workstation.
Source code in src/workstation/cli/crud.py
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 |
|
delete(context, **kwargs)
¶
Delete workstation.
Source code in src/workstation/cli/crud.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 |
|
get_gcloud_config(project, location)
¶
Retrieve GCP configuration details including project, location, and account.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project |
str
|
GCP project name. |
required |
location |
str
|
GCP location. |
required |
Returns:
Type | Description |
---|---|
tuple
|
A tuple containing project, location, and account details. |
Source code in src/workstation/cli/crud.py
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 |
|
list(context, project, location, all, user, export_json, cluster, **kwargs)
¶
List workstations.
Source code in src/workstation/cli/crud.py
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 |
|
list_configs(context, project, location, cluster, **kwargs)
¶
List workstation configurations.
Source code in src/workstation/cli/crud.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
|
logs(name, project, **kwargs)
¶
Open logs for the workstation.
Source code in src/workstation/cli/crud.py
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
|
start(context, name, code, browser, **kwargs)
¶
Start workstation and optionally open it either locally with VSCode or through VSCode in a browser.
Source code in src/workstation/cli/crud.py
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 |
|
stop(context, **kwargs)
¶
Stop workstation.
Source code in src/workstation/cli/crud.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
|
sync(context, name, **kwargs)
¶
Sync files to workstation.
Source code in src/workstation/cli/crud.py
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 493 494 495 496 497 498 499 500 501 |
|
config
¶
ConfigManager
¶
A class to manage Workstation configurations.
Attributes:
Name | Type | Description |
---|---|---|
workstation_data_dir |
Path
|
The directory where workstation data is stored. |
workstation_configs |
Path
|
The directory where individual workstation configurations are stored. |
Methods:
Name | Description |
---|---|
check_if_config_exists |
Checks if a configuration file with the given name exists. |
write_configuration |
Writes the configuration to a YAML file and returns the path to it. |
read_configuration |
Reads the configuration for the given name and returns it as a dictionary. |
delete_configuration |
Deletes the configuration file and its corresponding YAML file for the given name. |
write_ssh_config |
Writes the SSH configuration for the workstation. |
Source code in src/workstation/config.py
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 |
|
check_if_config_exists(name)
¶
Check if a configuration file with the given name exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the configuration to check. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the configuration exists, False otherwise. |
Source code in src/workstation/config.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
|
delete_configuration(name)
¶
Delete the configuration file and its corresponding YAML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the configuration to delete. |
required |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the configuration file does not exist. |
Source code in src/workstation/config.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
|
read_configuration(name)
¶
Read the configuration for the given name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the configuration to read. |
required |
Returns:
Type | Description |
---|---|
dict
|
The contents of the configuration file as a dictionary. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the configuration file does not exist. |
KeyError
|
If required keys are missing from the configuration file. |
Source code in src/workstation/config.py
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 |
|
write_configuration(project, name, location, cluster, config)
¶
Write the configuration to a YAML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project |
str
|
The project name. |
required |
name |
str
|
The name of the workstation. |
required |
location |
str
|
The location of the workstation. |
required |
cluster |
str
|
The cluster associated with the workstation. |
required |
config |
str
|
The specific configuration settings. |
required |
Returns:
Type | Description |
---|---|
Path
|
The path to the written YAML file. |
Raises:
Type | Description |
---|---|
Exception
|
If any error occurs during the writing process. |
Source code in src/workstation/config.py
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 |
|
write_ssh_config(name, user, project, cluster, config, region)
¶
Write the SSH configuration for the workstation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the workstation. |
required |
user |
str
|
The user for SSH connection. |
required |
project |
str
|
The project name. |
required |
cluster |
str
|
The cluster associated with the workstation. |
required |
config |
str
|
The specific configuration settings. |
required |
region |
str
|
The region where the workstation is deployed. |
required |
Raises:
Type | Description |
---|---|
NoPortFree
|
If no free port is found after checking 20 ports. |
Source code in src/workstation/config.py
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 |
|
WorkstationConfig
dataclass
¶
A class to represent a Workstation’s configuration.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the workstation. |
location |
str
|
The location where the workstation is deployed. |
cluster |
str
|
The cluster associated with the workstation. |
config |
str
|
The specific configuration settings of the workstation. |
project |
str
|
The project associated with the workstation. |
Methods:
Name | Description |
---|---|
generate_workstation_yml |
Generates a YAML configuration file for the workstation and saves it to the current directory. |
Source code in src/workstation/config.py
15 16 17 18 19 20 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 |
|
generate_workstation_yml()
¶
Generate a YAML configuration file for the workstation.
Returns:
Type | Description |
---|---|
Path
|
The path to the generated YAML file. |
Source code in src/workstation/config.py
44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
core
¶
create_workstation(project, location, cluster, config, name, account, user, proxy=None, no_proxy=None, envs=None)
¶
Create a new workstation with the specified configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project |
str
|
The Google Cloud project ID. |
required |
location |
str
|
The Google Cloud location. |
required |
cluster |
str
|
The workstation cluster name. |
required |
config |
str
|
The workstation configuration name. |
required |
name |
str
|
The name of the new workstation. |
required |
account |
str
|
The account associated with the workstation. |
required |
user |
str
|
The user associated with the workstation. |
required |
proxy |
Optional[str]
|
Proxy settings, by default None. |
None
|
no_proxy |
Optional[str]
|
No-proxy settings, by default None. |
None
|
envs |
Optional[Tuple[Tuple[str, str]]]
|
Additional environment variables to set, by default None. |
None
|
Returns:
Type | Description |
---|---|
Workstation
|
Response from the workstation creation request. |
Source code in src/workstation/core.py
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 |
|
delete_workstation(project, name, location, cluster, config)
¶
Delete an existing workstation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project |
str
|
The Google Cloud project ID. |
required |
name |
str
|
The name of the workstation. |
required |
location |
str
|
The Google Cloud location. |
required |
cluster |
str
|
The workstation cluster name. |
required |
config |
str
|
The workstation configuration name. |
required |
Returns:
Type | Description |
---|---|
Operation
|
Response from the workstation deletion request. |
Source code in src/workstation/core.py
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 |
|
list_workstation_clusters(project, location)
¶
List workstation clusters in a specific project and location.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project |
str
|
The Google Cloud project ID. |
required |
location |
str
|
The Google Cloud location. |
required |
Returns:
Type | Description |
---|---|
List[Dict]
|
A list of workstation cluster configurations. |
Source code in src/workstation/core.py
19 20 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 |
|
list_workstation_configs(project, location, cluster)
¶
List usable workstation configurations in a specific project, location, and cluster.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project |
str
|
The Google Cloud project ID. |
required |
location |
str
|
The Google Cloud location. |
required |
cluster |
str
|
The workstation cluster name. |
required |
Returns:
Type | Description |
---|---|
List[Dict]
|
A list of usable workstation configurations. |
Source code in src/workstation/core.py
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 |
|
list_workstations(project, location, cluster)
¶
List all workstations in a specific project, location, and cluster.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project |
str
|
The Google Cloud project ID. |
required |
location |
str
|
The Google Cloud location. |
required |
cluster |
str
|
The workstation cluster name. |
required |
Returns:
Type | Description |
---|---|
List[Dict]
|
A list of workstation configurations. |
Source code in src/workstation/core.py
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 |
|
start_workstation(project, name, location, cluster, config)
¶
Start an existing workstation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project |
str
|
The Google Cloud project ID. |
required |
name |
str
|
The name of the workstation. |
required |
location |
str
|
The Google Cloud location. |
required |
cluster |
str
|
The workstation cluster name. |
required |
config |
str
|
The workstation configuration name. |
required |
Returns:
Type | Description |
---|---|
Operation
|
Response from the workstation start request. |
Source code in src/workstation/core.py
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 |
|
stop_workstation(project, name, location, cluster, config)
¶
Stop an existing workstation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project |
str
|
The Google Cloud project ID. |
required |
name |
str
|
The name of the workstation. |
required |
location |
str
|
The Google Cloud location. |
required |
cluster |
str
|
The workstation cluster name. |
required |
config |
str
|
The workstation configuration name. |
required |
Returns:
Type | Description |
---|---|
Operation
|
Response from the workstation stop request. |
Source code in src/workstation/core.py
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 |
|
utils
¶
NoPortFree
¶
Bases: Exception
Exception raised when no free port is available for the SSH tunnel.
Source code in src/workstation/utils.py
220 221 222 223 |
|
check_gcloud_auth()
¶
Check if the current gcloud CLI is authenticated and refresh if necessary.
Returns:
Type | Description |
---|---|
bool
|
True if authentication is successful, False otherwise. |
Raises:
Type | Description |
---|---|
SystemExit
|
If reauthentication is needed. |
Source code in src/workstation/utils.py
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 |
|
check_socket(host, port)
¶
Check if a socket on the given host and port is available.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host |
str
|
The hostname or IP address. |
required |
port |
int
|
The port number. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the socket is available, False otherwise. |
Source code in src/workstation/utils.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
config_tree(configs)
¶
Generate a tree structure for displaying workstation configurations using Rich library.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
configs |
list
|
A list of workstation configurations. |
required |
Returns:
Type | Description |
---|---|
Tree
|
A Rich Tree object representing the configurations. |
Source code in src/workstation/utils.py
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 |
|
default_serializer(obj)
¶
Handle specific object types that are not serializable by default.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
Any
|
The object to serialize. |
required |
Returns:
Type | Description |
---|---|
Any
|
Serialized object (e.g., dictionary). |
Raises:
Type | Description |
---|---|
TypeError
|
If the object type is not serializable. |
Source code in src/workstation/utils.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 |
|
get_instance_assignment(project, name)
¶
Get the instance assignment log entries for a specific workstation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project |
str
|
The Google Cloud project ID. |
required |
name |
str
|
The name of the workstation. |
required |
Returns:
Type | Description |
---|---|
Dict
|
A dictionary of log entries related to the instance assignment. |
Source code in src/workstation/utils.py
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 |
|
get_logger()
¶
Set log level from LOG_LEVEL environment variable, default to INFO.
This is useful for debugging purpose. The value of LOG_LEVEL should be one of these: ‘DEBUG’, ‘INFO’, ‘WARNING’, ‘ERROR’, ‘CRITICAL’.
Source code in src/workstation/utils.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
|
process_entry(entry, project)
¶
Process a log entry to extract workstation information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entry |
A log entry object. |
required | |
project |
str
|
The Google Cloud project ID. |
required |
Returns:
Type | Description |
---|---|
Tuple[str, Dict]
|
Workstation ID and a dictionary with instance information. |
Source code in src/workstation/utils.py
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 |
|
read_gcloud_config()
¶
Read the default Google Cloud configuration.
Returns:
Type | Description |
---|---|
Tuple[str, str, str]
|
Default project ID, location, and account from gcloud configuration. |
Source code in src/workstation/utils.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
sync_files_workstation(project, name, location, cluster, config, source, destination)
¶
Synchronize files from the local system to the workstation using rsync over an SSH tunnel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project |
str
|
The Google Cloud project ID. |
required |
name |
str
|
The name of the workstation. |
required |
location |
str
|
The Google Cloud location. |
required |
cluster |
str
|
The workstation cluster name. |
required |
config |
str
|
The workstation configuration name. |
required |
source |
str
|
The source directory on the local system. |
required |
destination |
str
|
The destination directory on the workstation. |
required |
Returns:
Type | Description |
---|---|
CompletedProcess
|
The result of the rsync command. |
Source code in src/workstation/utils.py
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 |
|