Exemplo n.º 1
0
def get_test_driver_instance(Driver, *args, **kwarrgs):
    if Driver.__name__ not in DRIVERS_PATCHES:
        raise NotImplementedError('Unknown driver %s' % (Driver.__name__))
    Driver_copy = copy.deepcopy(Driver)
    driver_patch = DRIVERS_PATCHES[Driver_copy.__name__]
    driver_patch.pre_process(Driver_copy)
    driver_instance = get_driver_instance(Driver_copy, *args, **kwarrgs)
    driver_patch.post_process(driver_instance)
    return driver_instance
Exemplo n.º 2
0
def get_driver_instance_by_request(providers, request):
    provider_name = request.args.get('provider')
    headers = request.headers
    api_data = parse_request_headers(headers)
    Driver = get_driver_by_provider_name(
        providers.DRIVERS, providers.Provider, provider_name)
    if TEST_QUERY_STRING in request.query_string and DEBUG:
        driver_instance = get_test_driver_instance(Driver, api_data)
    else:
        driver_instance = get_driver_instance(Driver, api_data)
    return driver_instance
Exemplo n.º 3
0
def invoke_method(providers, method_name, request, status_code=httplib.OK,
                  data=None, file_result=False):
    """
    Invoke method and return response with result represented as json.

    @param file_result: If True wraps result
    """
    if data is None:
        data = request.data
    driver = get_driver_instance(providers, request)
    driver_method = DriverMethod(driver, method_name)
    try:
        result = driver_method.invoke(data)
    except Exception, e:
        if e.__class__ in INTERNAL_LIBCLOUD_ERRORS_MAP:
            raise INTERNAL_LIBCLOUD_ERRORS_MAP[e.__class__]()
        if isinstance(e, common_types.LibcloudError):
            raise LibcloudError(detail=str(e))
        raise
Exemplo n.º 4
0
def invoke_method(providers,
                  method_name,
                  request,
                  status_code=httplib.OK,
                  data=None,
                  file_result=False):
    """
    Invoke method and return response with result represented as json.

    @param file_result: If True wraps result
    """
    if data is None:
        data = request.data
    driver = get_driver_instance(providers, request)
    driver_method = DriverMethod(driver, method_name)
    try:
        result = driver_method.invoke(data)
    except Exception, e:
        if e.__class__ in INTERNAL_LIBCLOUD_ERRORS_MAP:
            raise INTERNAL_LIBCLOUD_ERRORS_MAP[e.__class__]()
        if isinstance(e, common_types.LibcloudError):
            raise LibcloudError(detail=str(e))
        raise