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

View File

@ -23,10 +23,11 @@ from blazarclient import utils
class LeaseClientManager(base.BaseClientManager): class LeaseClientManager(base.BaseClientManager):
"""Manager for the lease connected requests.""" """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.""" """Creates lease from values passed."""
values = {'name': name, 'start_date': start, 'end_date': end, 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') return self._create('/leases', values, 'lease')

View File

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