human
Give me a the Python code you requested given the following:
Complete the below
@require_context
def instance_create(context, values):

    ''''Create a new Instance record in the database.
    context - request context object
    values - dict containing column values.'
    '''
assistant
#Here is the Python code you requested.
    values = values.copy()
    values['metadata'] = _metadata_refs(values.get('metadata'), models.InstanceMetadata)
    values['system_metadata'] = _metadata_refs(values.get('system_metadata'), models.InstanceSystemMetadata)
    instance_ref = models.Instance()
    if (not values.get('uuid')):
        values['uuid'] = str(uuid.uuid4())
    instance_ref['info_cache'] = models.InstanceInfoCache()
    info_cache = values.pop('info_cache', None)
    if (info_cache is not None):
        instance_ref['info_cache'].update(info_cache)
    security_groups = values.pop('security_groups', [])
    instance_ref.update(values)
    def _get_sec_group_models(session, security_groups):
        models = []
        (_existed, default_group) = security_group_ensure_default(context, session=session)
        if ('default' in security_groups):
            models.append(default_group)
            security_groups = [x for x in security_groups if (x != 'default')]
        if security_groups:
            models.extend(_security_group_get_by_names(context, session, context.project_id, security_groups))
        return models
    session = get_session()
    with session.begin():
        if ('hostname' in values):
            _validate_unique_server_name(context, session, values['hostname'])
        instance_ref.security_groups = _get_sec_group_models(session, security_groups)
        instance_ref.save(session=session)
    ec2_instance_create(context, instance_ref['uuid'])
    return instance_ref