Documentation Index
Fetch the complete documentation index at: https://docs.salad.com/llms.txt
Use this file to discover all available pages before exploring further.
Last Updated: October 15, 2024
We can use the IMDS to retrieve the current status of the replica from inside the workload. This can be achieved using
either the IMDS SDK, or the JSON request endpoint. In this example, we’ll create a Python script using the IMDS SDK to
check whether the container is ready, and start a bash script when it is.
Using the SDK to retrieve the status
We’ll start by using the IMDS SDK to retrieve the statuses of the currently running container.
from salad_cloud_imds_sdk import SaladCloudImdsSdk, Environment
sdk = SaladCloudImdsSdk( base_url=Environment.DEFAULT.value, timeout=10000 )
result = sdk.metadata.get_container_status()
print(result)
Now, if we run this on a container that has passed its
startup probe, but not completed its
readiness probe, we’ll see this:
{
"ready": false,
"started": true
}
Starting a script when its ready
Now we know the status of the container, we can use this to start a bash script when it reaches a ready state.
import json
from subprocess import call
from salad_cloud_imds_sdk import SaladCloudImdsSdk, Environment
sdk = SaladCloudImdsSdk(
base_url=Environment.DEFAULT.value,
timeout=10000
)
result = sdk.metadata.get_container_status()
#Get the ready status out of the JSON response
data = json.loads(result)
status = data['ready']
if status == True:
subprocess.call("exampleScript.sh")
else: print("Not Ready Yet!")