'Build instances.'

def build_instances(self, ctxt, **kwargs):

    build_inst_kwargs = kwargs
    instances = build_inst_kwargs['instances']
    build_inst_kwargs['image'] = jsonutils.to_primitive(build_inst_kwargs['image'])
    version = '1.34'
    if self.client.can_send_version('1.34'):
        build_inst_kwargs.pop('legacy_bdm', None)
    else:
        bdm_p = objects_base.obj_to_primitive(build_inst_kwargs['block_device_mapping'])
        build_inst_kwargs['block_device_mapping'] = bdm_p
        version = '1.32'
    if (not self.client.can_send_version('1.32')):
        instances_p = [jsonutils.to_primitive(inst) for inst in instances]
        build_inst_kwargs['instances'] = instances_p
        version = '1.30'
    if (not self.client.can_send_version('1.30')):
        if ('filter_properties' in build_inst_kwargs):
            filter_properties = build_inst_kwargs['filter_properties']
            flavor = filter_properties['instance_type']
            flavor_p = objects_base.obj_to_primitive(flavor)
            filter_properties['instance_type'] = flavor_p
        version = '1.8'
    cctxt = self.client.prepare(version=version)
    cctxt.cast(ctxt, 'build_instances', build_inst_kwargs=build_inst_kwargs)
