Home › Forums › FABRIC General Questions and Discussion › Renew slice fails in fablib
Tagged: slice renewal
- This topic has 6 replies, 3 voices, and was last updated 1 year, 3 months ago by Ilya Baldin.
-
AuthorPosts
-
August 15, 2023 at 6:31 pm #5044
I created a slice and by default it gives a 1 day lease period. I tried to extend it to 30 days using the following code, so that I don’t lose my work:
********
import datetime
try:
slice = fablib.get_slice(name=slice_name)
end_date = (datetime.datetime.now() + datetime.timedelta(days=30)).strftime(“%Y-%m-%d %H:%M:%S %z”)
slice.renew(end_date)
except Exception as e:
print(f”Exception: {e}”)*******
Exception: Failed to renew slice: Status.INVALID_ARGUMENTS, Lease End Time 2023-09-14 20:31:49 should be in format: %Y-%m-%d %H:%M:%S %z
*******The exception says that the date format is wrong, but I don’t see what the problem is exactly.
Also, is there a way to set the lease duration while creating the slice?`August 15, 2023 at 6:40 pm #5045Hello,
I believe the max time you can renew a slice for is 7 days.
Try with 7 or less in the days parameter. You can rerun this code in the future to extend the slice further.August 15, 2023 at 7:57 pm #5046I tried with less than 7 days, but it fails with the same error.
For example, the exception when I try to extend it by 1 day:
Exception: Failed to renew slice: Status.INVALID_ARGUMENTS, Lease End Time 2023-08-16 23:54:38 should be in format: %Y-%m-%d %H:%M:%S %z
August 15, 2023 at 8:44 pm #5047Without Slice.NoLimitLifetime you can only renew in increments of two weeks (14 days). See this article: https://learn.fabric-testbed.net/knowledge-base/fabric-user-roles-and-project-permissions/ for more on project permission structure.
Please let us know:
1. Which container you are using if you are using Jupyter Hub (there are 4 to choose from).
2. What is the version of fablib you are using:
pip freeze | grep fabrictestbed
- This reply was modified 1 year, 3 months ago by Ilya Baldin.
August 15, 2023 at 8:48 pm #5048Oh I see!
In my scripts I’m using a slightly different command. Here’s a full snippet.
from datetime import datetime, timedelta
from dateutil import tz
end_date = (datetime.now(tz=tz.tzutc()) + timedelta(days=7)).strftime(“%Y-%m-%d %H:%M:%S %z”)
try:
fabric_slice = fablib.get_slice(name=slice_name)
fabric_slice = fabric_slice.renew(end_date)fabric_slice = fablib.get_slice(name=slice_name)
print(f’New lease end time: {fabric_slice.get_lease_end()}’)
except Exception as e:
print(f”Fail: {e}”)August 15, 2023 at 9:15 pm #5050Hi, with Georgios’ code snippet, the renewal was successfully extended. What was missing was the ‘tz.tzutc()’ when using datetime.now(), which needs to be explicitly defined as the %z argument.
August 15, 2023 at 10:16 pm #5051If you can remember where you got the code snippet you were trying to use @Nishanth please point it to us – it is likely from an older version of the API and we should correct it.
-
AuthorPosts
- The topic ‘Renew slice fails in fablib’ is closed to new replies.