Add before_end_date and before_end parameters

This patch adds a before_end_date option to the lease-create command. It
also adds a before_end parameter to the physical_reservation option.

Partially Implements: blueprint on-end-options
Depends-On: I90fb90d9d53814791d863f4ce5dab28388d3688d
Change-Id: I2a6f3477509f5b549edbdc25cb2c6ac457c7c100
This commit is contained in:
Hiroaki Kobayashi 2017-08-08 14:11:51 +09:00 committed by Pierre Riteau
parent 9e0b7110f0
commit 5cb6ad8c2a
3 changed files with 39 additions and 8 deletions

View File

@ -32,6 +32,7 @@ class CreateLeaseTestCase(tests.TestCase):
args = argparse.Namespace(
start='2020-07-24 20:00',
end='2020-08-09 22:30',
before_end='2020-08-09 21:30',
events=[],
name='lease-test',
reservations=[],
@ -42,12 +43,14 @@ class CreateLeaseTestCase(tests.TestCase):
'["and", [">=", "$vcpus", "2"], '
'[">=", "$memory_mb", "2048"]],'
'resource_properties='
'["==", "$extra_key", "extra_value"]'
'["==", "$extra_key", "extra_value"],'
'before_end=default'
]
)
expected = {
'start': '2020-07-24 20:00',
'end': '2020-08-09 22:30',
'before_end': '2020-08-09 21:30',
'events': [],
'name': 'lease-test',
'reservations': [
@ -59,7 +62,8 @@ class CreateLeaseTestCase(tests.TestCase):
'[">=", "$memory_mb", "2048"]]',
'resource_properties':
'["==", "$extra_key", "extra_value"]',
'resource_type': 'physical:host'
'resource_type': 'physical:host',
'before_end': 'default'
}
]
}
@ -69,6 +73,7 @@ class CreateLeaseTestCase(tests.TestCase):
args = argparse.Namespace(
start='2020-07-24 20:00',
end='2020-08-09 22:30',
before_end='2020-08-09 21:30',
events=[],
name='lease-test',
reservations=[],
@ -91,6 +96,7 @@ class CreateLeaseTestCase(tests.TestCase):
args = argparse.Namespace(
start='2020-07-24 20:00',
end='2020-08-09 22:30',
before_end='2020-08-09 21:30',
events=[],
name='lease-test',
reservations=[],

View File

@ -23,10 +23,11 @@ from blazarclient import utils
class LeaseClientManager(base.BaseClientManager):
"""Manager for the lease connected requests."""
def create(self, name, start, end, reservations, events):
def create(self, name, start, end, reservations, events, before_end=None):
"""Creates lease from values passed."""
values = {'name': name, 'start_date': start, 'end_date': end,
'reservations': reservations, 'events': events}
'reservations': reservations, 'events': events,
'before_end_date': before_end}
return self._create('/leases', values, 'lease')

View File

@ -74,10 +74,17 @@ class CreateLease(command.CreateCommand):
'(default: 24h later)',
default=self.default_end
)
parser.add_argument(
'--before-end-date',
dest='before_end',
help='Time (YYYY-MM-DD HH:MM) UTC TZ for taking an action before '
'the end of the lease (default: depends on system default)',
default=None
)
parser.add_argument(
'--physical-reservation',
metavar="<min=int,max=int,hypervisor_properties=str,"
"resource_properties=str>",
"resource_properties=str,before_end=str>",
action='append',
dest='physical_reservations',
help='Create a reservation for physical compute hosts. '
@ -86,7 +93,8 @@ class CreateLease(command.CreateCommand):
'min: minimum number of hosts to reserve. '
'max: maximum number of hosts to reserve. '
'hypervisor_properties: JSON string, see doc. '
'resource_properties: JSON string, see doc. ',
'resource_properties: JSON string, see doc. '
'before_end: JSON string, see doc. ',
default=[]
)
parser.add_argument(
@ -129,6 +137,19 @@ class CreateLease(command.CreateCommand):
raise exception.IncorrectLease
if parsed_args.start > parsed_args.end:
raise exception.IncorrectLease
if parsed_args.before_end:
try:
parsed_args.before_end = datetime.datetime.strptime(
parsed_args.before_end, '%Y-%m-%d %H:%M')
except ValueError:
raise exception.IncorrectLease
if (parsed_args.before_end < parsed_args.start
or parsed_args.end < parsed_args.before_end):
raise exception.IncorrectLease
params['before_end'] = datetime.datetime.strftime(
parsed_args.before_end, '%Y-%m-%d %H:%M')
params['start'] = datetime.datetime.strftime(parsed_args.start,
'%Y-%m-%d %H:%M')
params['end'] = datetime.datetime.strftime(parsed_args.end,
@ -142,10 +163,11 @@ class CreateLease(command.CreateCommand):
err_msg = ("Invalid physical-reservation argument '%s'. "
"Reservation arguments must be of the "
"form --physical-reservation <min=int,max=int,"
"hypervisor_properties=str,resource_properties=str>"
"hypervisor_properties=str,resource_properties=str,"
"before_end=str>"
% phys_res_str)
phys_res_info = {"min": "", "max": "", "hypervisor_properties": "",
"resource_properties": ""}
"resource_properties": "", "before_end": None}
prog = re.compile('^(?:(.*),)?(%s)=(.*)$'
% "|".join(phys_res_info.keys()))
@ -188,6 +210,8 @@ class CreateLease(command.CreateCommand):
% phys_res_str)
raise exception.IncorrectLease(err_msg)
if phys_res_info['before_end'] is None:
phys_res_info.pop('before_end')
# NOTE(sbauza): The resource type should be conf-driven mapped with
# blazar.conf file but that's potentially on another
# host