1. Renew slice fails in fablib

Renew slice fails in fablib

Home Forums FABRIC General Questions and Discussion Renew slice fails in fablib

Tagged: 

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #5044
    Nishanth Shyamkumar
    Participant

      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?`

      #5045

      Hello,

      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.

      #5046
      Nishanth Shyamkumar
      Participant

        I 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

        #5047
        Ilya Baldin
        Participant

          Without 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, 4 months ago by Ilya Baldin.
          #5048

          Oh 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}”)

          #5050
          Nishanth Shyamkumar
          Participant

            Hi, 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.

            #5051
            Ilya Baldin
            Participant

              If 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.

            Viewing 7 posts - 1 through 7 (of 7 total)
            • The topic ‘Renew slice fails in fablib’ is closed to new replies.