Commit f5da632a authored by Masahito Muroi's avatar Masahito Muroi

Enable lease-update to update start/end time with date

lease-update CLI only accepts time delta to update start_time
or end_time of leases. It's hard for users to specify a specific
date as its argument since users need to caluclate the time delta
between the previous start/end time and the new date.

This patch enables users to update leases with date format
like --end-date "2017-06-05 17:15".

Change-Id: I5044213656a22ffa99d96f3d2f3f92752da1b6e9
parent 55c6300f
......@@ -37,28 +37,39 @@ class LeaseClientManager(base.BaseClientManager):
return self._get('/leases/%s' % lease_id, 'lease')
def update(self, lease_id, name=None, prolong_for=None, reduce_by=None,
advance_by=None, defer_by=None):
end_date=None, advance_by=None, defer_by=None, start_date=None):
"""Update attributes of the lease."""
values = {}
if name:
values['name'] = name
lease_end_date_change = prolong_for or reduce_by
lease_start_date_change = defer_by or advance_by
lease_end_date_change = prolong_for or reduce_by or end_date
lease_start_date_change = defer_by or advance_by or start_date
lease = None
if lease_end_date_change:
lease = self.get(lease_id)
self._add_lease_date(values, lease, 'end_date',
lease_end_date_change,
prolong_for is not None)
if end_date:
date = timeutils.parse_strtime(end_date, utils.API_DATE_FORMAT)
values['end_date'] = timeutils.strtime(date,
utils.API_DATE_FORMAT)
else:
self._add_lease_date(values, lease, 'end_date',
lease_end_date_change,
prolong_for is not None)
if lease_start_date_change:
if lease is None:
lease = self.get(lease_id)
self._add_lease_date(values, lease, 'start_date',
lease_start_date_change,
defer_by is not None)
if start_date:
date = timeutils.parse_strtime(start_date,
utils.API_DATE_FORMAT)
values['start_date'] = timeutils.strtime(date,
utils.API_DATE_FORMAT)
else:
self._add_lease_date(values, lease, 'start_date',
lease_start_date_change,
defer_by is not None)
if not values:
return _('No values to update passed.')
......
......@@ -250,6 +250,10 @@ class UpdateLease(command.UpdateCommand):
help='Time to reduce lease by',
default=None
)
group.add_argument(
'--end-date',
help='end date of the lease',
default=None)
#defer-by and a 'future' advance-by are mutually exclusive
group = parser.add_mutually_exclusive_group()
......@@ -263,6 +267,10 @@ class UpdateLease(command.UpdateCommand):
help='Time to advance the lease start',
default=None
)
group.add_argument(
'--start-date',
help='start date of the lease',
default=None)
return parser
......@@ -274,10 +282,14 @@ class UpdateLease(command.UpdateCommand):
params['prolong_for'] = parsed_args.prolong_for
if parsed_args.reduce_by:
params['reduce_by'] = parsed_args.reduce_by
if parsed_args.end_date:
params['end_date'] = parsed_args.end_date
if parsed_args.defer_by:
params['defer_by'] = parsed_args.defer_by
if parsed_args.advance_by:
params['advance_by'] = parsed_args.advance_by
if parsed_args.start_date:
params['start_date'] = parsed_args.start_date
return params
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment