common commands, like create lease, create container, are not idempotent.
It is common for users to run these multiple times, and then be confused when errors occur.
We should make "ensure_" commands available, since this more often matches user intent.
Example:
from chi import lease
def ensure_lease(lease_name, reservations=[]):
"""
Ensure that a lease with the name or ID exists, and is active.
Returns the lease object.
"""
bad_lease_status = ["Terminated", "Error"]
try:
lease_obj = lease.get_lease(lease_name)
assert(lease_obj["status"] not in bad_lease_status )
except Exception as ex:
print(ex)
print("trying to create new lease")
try:
lease_obj = lease.create_lease(lease_name, reservations=reservations)
except Exception as ex:
print(ex)
finally:
return lease_obj
common commands, like create lease, create container, are not idempotent. It is common for users to run these multiple times, and then be confused when errors occur.
We should make "ensure_" commands available, since this more often matches user intent.
Example: