From 0ba11368023c4a0796cf6bfd9c487b7199653609 Mon Sep 17 00:00:00 2001 From: Lars Kellogg-Stedman Date: Sun, 23 Mar 2025 11:03:41 -0400 Subject: [PATCH] Add --now option to esi offer list command The `--now` option filters offers to those that have availability start "right now". This supports the common use case of "I would like to lease a machine at this moment". --- esileapclient/osc/v1/offer.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/esileapclient/osc/v1/offer.py b/esileapclient/osc/v1/offer.py index ee0a8ed..fea16e6 100644 --- a/esileapclient/osc/v1/offer.py +++ b/esileapclient/osc/v1/offer.py @@ -10,6 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. +import datetime import logging import json @@ -20,6 +21,7 @@ from esileapclient.v1.offer import Offer as OFFER_RESOURCE from esileapclient.common import utils +END_OF_TIME = '9999-12-31T00:00:00' LOG = logging.getLogger(__name__) @@ -161,6 +163,16 @@ def get_parser(self, prog_name): "Can be specified multiple times. " f"Supported operators are: {', '.join(utils.OPS.keys())}", metavar='"key>=value"') + parser.add_argument( + '--now', + action='store_const', + dest='availability_range', + const=[ + datetime.datetime.now().isoformat(timespec='seconds'), + END_OF_TIME + ], + help='Only list offers that have availability right now', + ) return parser