- This topic has 2 replies, 2 voices, and was last updated 2 years, 3 months ago by .
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.
Home › Forums › FABRIC General Questions and Discussion › issues with renew slice using 1.3
When trying to use example code from
end_date = (datetime.datetime.utcnow() + datetime.timedelta(days=6)).strftime(“%Y-%m-%d %H:%M:%S”)
slice.renew(end_date)
to renew a slice using 1.3 for fabrictestbed, fabrictestbed_extensions , I see an error
Exception: Failed to renew slice: Status.INVALID_ARGUMENTS, Lease End Time 2022-09-13 15:52:03 should be in format: %Y-%m-%d %H:%M:%S %z
Is there an updated code sample for renew slice ? Handling the time zone in python datetime looks like it takes some special treatment.
Thank you for let us know! We will work on fixing the example. Please use the snippet below to renew the slice.
Hope this helps!
import datetime
#Set end host to now plus 1 day
now = datetime.now(timezone.utc)
end_date = now + timedelta(days=6).strftime("%Y-%m-%d %H:%M:%S %z")
try:
slice = fablib.get_slice(name=slice_name)
slice.renew(end_date)
except Exception as e:
print(f"Exception: {e}")
Thanks; I was able to get the renew slice to work with snippets along those lines.
My scripting that worked looked something like
import datetime
from datetime import timedeltanow = datetime.datetime.now(datetime.timezone.utc)
end_date = (now + timedelta(days=6)).strftime(“%Y-%m-%d %H:%M:%S %z”)slice = fablib.get_slice(name=slice_name)
slice.renew(end_date)
where I imagine that can be cleaned up a bit.