def args2body(self, parsed_args):
        params = {}
        if parsed_args.name:
            params['name'] = parsed_args.name
        if not isinstance(parsed_args.start, datetime.datetime):
            try:
                parsed_args.start = datetime.datetime.strptime(
                    parsed_args.start, '%Y-%m-%d %H:%M')
            except ValueError:
                raise exception.IncorrectLease
        if not isinstance(parsed_args.end, datetime.datetime):
            try:
                parsed_args.end = datetime.datetime.strptime(
                    parsed_args.end, '%Y-%m-%d %H:%M')
            except __HOLE__:
                raise exception.IncorrectLease
        if parsed_args.start > parsed_args.end:
            raise exception.IncorrectLease
        params['start'] = datetime.datetime.strftime(parsed_args.start,
                                                     '%Y-%m-%d %H:%M')
        params['end'] = datetime.datetime.strftime(parsed_args.end,
                                                   '%Y-%m-%d %H:%M')

        params['reservations'] = []
        params['events'] = []

        physical_reservations = []
        for phys_res_str in parsed_args.physical_reservations:
            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>"
                       % phys_res_str)
            phys_res_info = {"min": "", "max": "", "hypervisor_properties": "",
                             "resource_properties": ""}
            prog = re.compile('^(\w+)=(\w+|\[[^]]+\])(?:,(.+))?$')

            def parse_params(params):
                match = prog.search(params)
                if match:
                    self.log.info("Matches: %s", match.groups())
                    k, v = match.group(1, 2)
                    if k in phys_res_info:
                        phys_res_info[k] = v
                    else:
                        raise exception.IncorrectLease(err_msg)
                    if len(match.groups()) == 3 and match.group(3) is not None:
                        parse_params(match.group(3))

            parse_params(phys_res_str)
            if not phys_res_info['min'] and not phys_res_info['max']:
                raise exception.IncorrectLease(err_msg)
            # NOTE(sbauza): The resource type should be conf-driven mapped with
            #               climate.conf file but that's potentially on another
            #               host
            phys_res_info['resource_type'] = 'physical:host'
            physical_reservations.append(phys_res_info)
        if physical_reservations:
            params['reservations'] += physical_reservations

        reservations = []
        for res_str in parsed_args.reservations:
            err_msg = ("Invalid reservation argument '%s'. "
                       "Reservation arguments must be of the "
                       "form --reservation <key=value>"
                       % res_str)
            res_info = {}
            for kv_str in res_str.split(","):
                try:
                    k, v = kv_str.split("=", 1)
                except ValueError:
                    raise exception.IncorrectLease(err_msg)
                res_info[k] = v
            reservations.append(res_info)
        if reservations:
            params['reservations'] += reservations

        if not params['reservations']:
            raise exception.IncorrectLease

        events = []
        for event_str in parsed_args.events:
            err_msg = ("Invalid event argument '%s'. "
                       "Event arguments must be of the "
                       "form --event <event_type=str,event_date=time>"
                       % event_str)
            event_info = {"event_type": "", "event_date": ""}
            for kv_str in event_str.split(","):
                try:
                    k, v = kv_str.split("=", 1)
                except ValueError:
                    raise exception.IncorrectLease(err_msg)
                if k in event_info:
                    event_info[k] = v
                else:
                    raise exception.IncorrectLease(err_msg)
            if not event_info['event_type'] and not event_info['event_date']:
                raise exception.IncorrectLease(err_msg)
            event_date = event_info['event_date']
            try:
                date = datetime.datetime.strptime(event_date, '%Y-%m-%d %H:%M')
                event_date = datetime.datetime.strftime(date, '%Y-%m-%d %H:%M')
                event_info['event_date'] = event_date
            except ValueError:
                raise exception.IncorrectLease
            events.append(event_info)
        if events:
            params['events'] = events

        return params
dataset/ETHPy150Open openstack/python-blazarclient/climateclient/v1/shell_commands/leases.py/CreateLease.args2body