Convert integer style parameters to integer values

python-blazarclient sends all request parameters in the request body as
strings even though the blazar service only accepts integer values for
some parameters.

For instance, the instance reservation feature accepts an integer for
the 'vcpus' parameter, but the blazar client sends a string value for
the parameter with the --reservation vcpus=1 option.

This patch enables the --reservation option to convert integer style
parameters to integer values.

Closes-Bug: #1707552
Change-Id: Ife1124e14adc0183fe5d4680031bc00ca3647ed5
This commit is contained in:
Masahito Muroi 2017-07-31 11:47:20 +09:00 committed by Pierre Riteau
parent 2cdb0682ea
commit b2fa6bf534
1 changed files with 9 additions and 4 deletions

View File

@ -18,6 +18,8 @@ import datetime
import logging
import re
from oslo_utils import strutils
from blazarclient import command
from blazarclient import exception
@ -162,12 +164,13 @@ class CreateLease(command.CreateCommand):
if not (phys_res_info['min'] and phys_res_info['max']):
raise exception.IncorrectLease(err_msg)
try:
min_host = int(phys_res_info['min'])
max_host = int(phys_res_info['max'])
except Exception:
if not (strutils.is_int_like(phys_res_str['min']) and
strutils.is_int_like(phys_res_str['max'])):
raise exception.IncorrectLease(err_msg)
min_host = int(phys_res_info['min'])
max_host = int(phys_res_info['max'])
if min_host > max_host:
err_msg = ("Invalid physical-reservation argument '%s'. "
"Reservation argument min value must be "
@ -202,6 +205,8 @@ class CreateLease(command.CreateCommand):
k, v = kv_str.split("=", 1)
except ValueError:
raise exception.IncorrectLease(err_msg)
if strutils.is_int_like(v):
v = int(v)
res_info[k] = v
reservations.append(res_info)
if reservations: