Lso client
The LSO client, which interacts with LSO running externally.
LSO is responsible for executing Ansible playbooks, that deploy subscriptions.
_LSOState
Bases: TypedDict
An expanded state that must contain at least the required keys for the execution of an Ansible playbook.
Source code in gso/services/lso_client.py
_send_request(parameters, callback_route)
Send a request to LSO. The callback address is derived using the process ID provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parameters
|
dict
|
JSON body for the request, which will almost always at least consist of a subscription object, and a boolean value to indicate a dry run. |
required |
callback_route
|
str
|
The callback route that should be used to resume the workflow. |
required |
Raises:
Type | Description |
---|---|
HTTPError
|
When receiving a non-successful status code from LSO. |
Source code in gso/services/lso_client.py
_execute_playbook(playbook_name, callback_route, inventory, extra_vars)
Execute a playbook remotely through the provisioning proxy.
When providing this method with an inventory, the format should be compatible with the Ansible YAML-based format. For example, an inventory consisting of two hosts, which each a unique host variable assigned to them looks as follows:
"inventory": {
"all": {
"hosts": {
"host1.local": {
"foo": "bar"
},
"host2.local": {
"key": "value"
},
"host3.local": None
}
}
}
Danger
Note the fact that the collection of all hosts is a dictionary, and not a list of strings. Ansible expects each
host to be a key-value pair. The key is the FQDN of a host, and the value always null
.
The extra vars can be a simple dict consisting of key-value pairs, for example:
Parameters:
Name | Type | Description | Default |
---|---|---|---|
playbook_name
|
str
|
Filename of the playbook that is to be executed. It must be present on the remote system running the provisioning proxy, otherwise it will return an error. |
required |
callback_route
|
str
|
The endpoint at which GSO expects a callback to continue the workflow executing this step. |
required |
inventory
|
dict[str, Any]
|
An inventory of machines at which the playbook is targeted. Must be in YAML-compatible format. |
required |
extra_vars
|
dict[str, Any]
|
Any extra variables that the playbook relies on. This can include a subscription object, a boolean value indicating a dry run, a commit comment, etc. All unicode character values are decoded to prevent sending special characters to remote machines that don't support this. |
required |
Source code in gso/services/lso_client.py
validate_inventory_is_set(state)
Validate whether the passed Ansible inventory is empty.
If the inventory is empty, which can happen in select cases, there should be no playbook run. This conditional will prevent from calling out to LSO with an empty playbook, which would cause the Ansible runner process to hang. This in turn will result in a workflow step that is never called back to.
Source code in gso/services/lso_client.py
lso_interaction(provisioning_step)
Interact with the provisioning proxy LSO using a callback step.
An asynchronous interaction with the provisioning proxy. This is an external system that executes Ansible playbooks to provision service subscriptions. If the playbook fails, this step will also fail, allowing for the user to retry provisioning from the UI.
Optionally, the keys lso_result_title
and lso_result_extra_label
can be added to the state before running
this interaction. They will be used to customise the input step that shows the outcome of the LSO
interaction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provisioning_step
|
Step
|
A workflow step that performs an operation remotely using the provisioning proxy. |
required |
Returns:
Type | Description |
---|---|
StepList
|
A list of steps that is executed as part of the workflow. |
Source code in gso/services/lso_client.py
indifferent_lso_interaction(provisioning_step)
Interact with the provisioning proxy LSO using a callback step.
This interaction is identical from the one described in lso_interaction()
, with one functional difference.
Whereas the lso_interaction()
will make the workflow step fail on unsuccessful interaction, this step will not.
It is therefore indifferent about the outcome of the Ansible playbook that is executed.
Danger
Using this interaction requires the operator to manually evaluate the outcome of a playbook. If a playbook fails, this will not cause the workflow to fail.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provisioning_step
|
Step
|
A workflow step that performs an operation remotely using the provisioning proxy. |
required |
Returns:
Type | Description |
---|---|
StepList
|
A list of steps that is executed as part of the workflow. |
Source code in gso/services/lso_client.py
anonymous_lso_interaction(provisioning_step, validation_step=_evaluate_results)
Interact with the provisioning proxy LSO without any user input.
Similar to the indifferent LSO interaction, there also is the anonymous interaction. Output is not ignored
but no input step is created to display the results.
A custom validation step may be given as input. This validation step should look inside the callback_result
key
in the current state. By default, only the return code of the playbook execution is evaluated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provisioning_step
|
Step
|
A workflow step to remotely provision a subscription. |
required |
validation_step
|
Step
|
An optional validation step which defaults to a step that evaluates the return code. |
_evaluate_results
|
Source code in gso/services/lso_client.py
anonymous_indifferent_lso_interaction(provisioning_step)
Interact with the provisioning proxy LSO without any user input.
Similar to the anonymous LSO interaction, but indifferent about the outcome of the Ansible playbook that is executed
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provisioning_step
|
Step
|
A workflow step to remotely provision a subscription. |
required |