Skip to content

Instantly share code, notes, and snippets.

@davidmerwin
Created November 24, 2023 01:28
Show Gist options
  • Save davidmerwin/61818b9fd8f5217c2be0706be21cab59 to your computer and use it in GitHub Desktop.
Save davidmerwin/61818b9fd8f5217c2be0706be21cab59 to your computer and use it in GitHub Desktop.

Python Snippet

Preview:
# Human-Readable Python Code:

The following code snippet is an asynchronous method named `cancel_reservation_async` that cancels a quantum reservation. It takes in three arguments: `project_id`, `processor_id`, and `reservation_id`, all of which are strings.

```python
async def cancel_reservation_async(
    self, project_id: str, processor_id: str, reservation_id: str
):
    """Cancels a quantum reservation.

    This action is only valid if the associated [QuantumProcessor]
    schedule not been frozen. Otherwise, delete_reservation should
    be used.

    The reservation will be truncated to end at the time when the request is
    serviced and any remaining time will be made available as an open swim
    period. This action will only succeed if the reservation has not yet
    ended and is within the processor's freeze window. If the reservation
    has already ended or is beyond the processor's freeze window, then the
    call will return an error.

    Args:
        project_id: A project_id of the parent Google Cloud Project.
        processor_id: The processor unique identifier.
        reservation_id: Unique ID of the reservation in the parent project,
    """
    # Create the reservation name using the project_id, processor_id,
    # and reservation_id
    name = _reservation_name_from_ids(project_id, processor_id, reservation_id)
    
    # Create a cancel reservation request object with the reservation name
    request = quantum.CancelQuantumReservationRequest(name=name)
    
    # Send the cancel reservation request asynchronously and return the response
    return await self._send_request_async(self.grpc_client.cancel_quantum_reservation, request)

Note: The code snippet provided does not include the definition of the _reservation_name_from_ids function.

| Associated Context                         |                                          |
| ------------------------------------------ | ---------------------------------------- |
| Type | Code Snippet  ( ***.py***  )  |
| Associated Tags | No Tags Associated |
| Description | 'No Description Provided' |
| Related Links | No Related Links |
| Related People | [David Merwin](mailto:davidmerwin1992@gmail.com) |
| Sensitive Information | No Sensitive Information Detected  |
| Shareable Link | https://davidmerwin.pieces.cloud/?p=fc1245a189  |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment