Commit c9c26afd authored by Jenkins's avatar Jenkins Committed by Gerrit Code Review

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

parents dddc60b8 f5da632a
......@@ -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.')
......
......@@ -271,6 +271,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()
......@@ -284,6 +288,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
......@@ -295,10 +303,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