当前位置: 首页>>代码示例>>Python>>正文


Python helpers.user_from_request函数代码示例

本文整理汇总了Python中mist.core.helpers.user_from_request函数的典型用法代码示例。如果您正苦于以下问题:Python user_from_request函数的具体用法?Python user_from_request怎么用?Python user_from_request使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了user_from_request函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_machine

def create_machine(request):
    """Creates a new virtual machine on the specified backend."""

    backend_id = request.matchdict['backend']

    try:
        key_id = request.json_body.get('key')
        machine_name = request.json_body['name']
        location_id = request.json_body.get('location', None)
        image_id = request.json_body['image']
        size_id = request.json_body['size']
        #deploy_script received as unicode, but ScriptDeployment wants str
        script = str(request.json_body.get('script', ''))
        # these are required only for Linode/GCE, passing them anyway
        image_extra = request.json_body.get('image_extra', None)
        disk = request.json_body.get('disk', None)
        image_name = request.json_body.get('image_name', None)
        size_name = request.json_body.get('size_name', None)
        location_name = request.json_body.get('location_name', None)
        ips = request.json_body.get('ips', None)
        monitoring = request.json_body.get('monitoring', False)
        networks = request.json_body.get('networks', [])
    except Exception as e:
        raise RequiredParameterMissingError(e)

    user = user_from_request(request)
    ret = methods.create_machine(user, backend_id, key_id, machine_name,
                                 location_id, image_id, size_id, script,
                                 image_extra, disk, image_name, size_name,
                                 location_name, ips, monitoring, networks)
    return ret
开发者ID:EzanLTD,项目名称:mist.io,代码行数:31,代码来源:views.py

示例2: get_stats

def get_stats(request):
    core_uri = config.CORE_URI
    user = user_from_request(request)
    params = request.params
    start = params.get('start')
    stop = params.get('stop')
    step = params.get('step')
    expression = params.get('expression')

    params = {
        'start': start,
        'stop': stop,
        'step': step,
        'expression': expression,
    }
    try:
        ret = requests.get(config.CORE_URI + request.path,
                           params=params,
                           headers={'Authorization': get_auth_header(user)},
                           verify=config.SSL_VERIFY)
    except requests.exceptions.SSLError as exc:
        log.error("%r", exc)
        raise SSLError()
    if ret.status_code == 200:
        return ret.json()
    else:
        log.error("Error getting stats %d:%s", ret.status_code, ret.text)
        raise ServiceUnavailableError()
开发者ID:AnyBucket,项目名称:mist.io,代码行数:28,代码来源:views.py

示例3: get_loadavg

def get_loadavg(request, action=None):
    """Get the loadavg png displayed in the machines list view."""
    params = request.params
    start = params.get('start', '')
    stop = params.get('stop', '')
    user = user_from_request(request)
    core_uri = config.CORE_URI
    payload = {
        'start': start,
        'stop': stop,
    }
    headers = {
        'Authorization': get_auth_header(user),
        'Content-type': 'image/png',
        'Accept': '*/*'
    }
    try:
        ret = requests.get(config.CORE_URI + request.path, params=payload,
                           headers=headers, verify=config.SSL_VERIFY)
    except requests.exceptions.SSLError as exc:
        log.error("%r", exc)
        raise SSLError()
    if ret.status_code != 200:
        log.error("Error getting loadavg %d:%s", ret.status_code, ret.text)
        raise ServiceUnavailableError()
    return Response(ret.content, content_type='image/png', request=request)
开发者ID:deanet,项目名称:mist.io,代码行数:26,代码来源:views.py

示例4: machine_actions

def machine_actions(request):
    # TODO: We shouldn't return list_machines, just 200. Save the API!
    backend_id = request.matchdict['backend']
    machine_id = request.matchdict['machine']
    user = user_from_request(request)
    params = request.json_body
    action = params.get('action', '')
    plan_id = params.get('plan_id', '')
    # plan_id is the id of the plan to resize
    name = params.get('name', '')

    if action in ('start', 'stop', 'reboot', 'destroy', 'resize', 'rename'):
        if action == 'start':
            methods.start_machine(user, backend_id, machine_id)
        elif action == 'stop':
            methods.stop_machine(user, backend_id, machine_id)
        elif action == 'reboot':
            methods.reboot_machine(user, backend_id, machine_id)
        elif action == 'destroy':
            methods.destroy_machine(user, backend_id, machine_id)
        elif action == 'resize':
            methods.resize_machine(user, backend_id, machine_id, plan_id)
        elif action == 'rename':
            methods.rename_machine(user, backend_id, machine_id, name)
        # return OK
        return methods.list_machines(user, backend_id)
    raise BadRequestError()
开发者ID:johnnyWalnut,项目名称:mist.io,代码行数:27,代码来源:views.py

示例5: star_image

def star_image(request):
    """Toggle image as starred."""

    backend_id = request.matchdict['backend']
    image_id = request.matchdict['image']
    user = user_from_request(request)
    return methods.star_image(user, backend_id, image_id)
开发者ID:johnnyWalnut,项目名称:mist.io,代码行数:7,代码来源:views.py

示例6: check_monitoring

def check_monitoring(request):
    """Ask the mist.io service if monitoring is enabled for this machine.

    """
    user = user_from_request(request)
    ret = methods.check_monitoring(user)
    return ret
开发者ID:johnnyWalnut,项目名称:mist.io,代码行数:7,代码来源:views.py

示例7: deploy_plugin

def deploy_plugin(request):
    user = user_from_request(request)
    backend_id = request.matchdict['backend']
    machine_id = request.matchdict['machine']
    plugin_id = request.matchdict['plugin']
    params = params_from_request(request)
    plugin_type = params.get('plugin_type')
    host = params.get('host')
    if plugin_type == 'python':
        ret = methods.deploy_python_plugin(
            user, backend_id, machine_id, plugin_id,
            value_type=params.get('value_type', 'gauge'),
            read_function=params.get('read_function'),
            host=host,
        )
        methods.update_metric(
            user,
            metric_id=ret['metric_id'],
            name=params.get('name'),
            unit=params.get('unit'),
            backend_id=backend_id,
            machine_id=machine_id,
        )
        return ret
    else:
        raise BadRequestError("Invalid plugin_type: '%s'" % plugin_type)
开发者ID:johnnyWalnut,项目名称:mist.io,代码行数:26,代码来源:views.py

示例8: update_user_settings

def update_user_settings(request):
    """try free plan, by communicating to the mist.core service"""

    params = request.json_body
    action = params.get('action', '').lower()
    plan = params.get('plan', '')
    name = params.get('name', '')
    company_name = params.get('company_name', '')
    country = params.get('country', '')
    number_of_servers = params.get('number_of_servers', '')
    number_of_people = params.get('number_of_people', '')

    user = user_from_request(request)

    payload = {'action': action,
               'plan': plan,
               'name': name,
               'company_name': company_name,
               'country': country,
               'number_of_servers': number_of_servers,
               'number_of_people': number_of_people}

    try:
        ret = requests.post(config.CORE_URI + '/account',
                            params=payload,
                            headers={'Authorization': get_auth_header(user)},
                            verify=config.SSL_VERIFY)
    except requests.exceptions.SSLError as exc:
        log.error("%r", exc)
        raise SSLError()
    if ret.status_code == 200:
        ret = json.loads(ret.content)
        return ret
    else:
        raise UnauthorizedError()
开发者ID:johnnyWalnut,项目名称:mist.io,代码行数:35,代码来源:views.py

示例9: check_auth

def check_auth(request):
    """Check on the mist.core service if authenticated"""

    params = request.json_body
    email = params.get('email', '').lower()
    password = params.get('password', '')

    payload = {'email': email, 'password': password}
    try:
        ret = requests.post(config.CORE_URI + '/auth', params=payload,
                            verify=config.SSL_VERIFY)
    except requests.exceptions.SSLError as exc:
        log.error("%r", exc)
        raise SSLError()
    if ret.status_code == 200:
        ret_dict = json.loads(ret.content)
        user = user_from_request(request)
        with user.lock_n_load():
            user.email = email
            user.mist_api_token = ret_dict.pop('mist_api_token', '')
            user.save()
        log.info("succesfully check_authed")
        return ret_dict
    else:
        log.error("Couldn't check_auth to mist.io: %r", ret)
        raise UnauthorizedError()
开发者ID:johnnyWalnut,项目名称:mist.io,代码行数:26,代码来源:views.py

示例10: __init__

 def __init__(self, *args, **kwargs):
     super(CustomNamespace, self).__init__(*args, **kwargs)
     self.user = user_from_request(self.request)
     self.session_id = uuid.uuid4().hex
     log.info("Initialized %s for user %s. Socket %s. Session %s",
              self.__class__.__name__, self.user.email,
              self.socket.sessid, self.session_id)
     self.init()
开发者ID:AVD087,项目名称:mist.io,代码行数:8,代码来源:sockio.py

示例11: get_public_key

def get_public_key(request):
    user = user_from_request(request)
    key_id = request.matchdict['key']
    if not key_id:
        raise RequiredParameterMissingError("key_id")
    if key_id not in user.keypairs:
        raise KeypairNotFoundError(key_id)
    return user.keypairs[key_id].public
开发者ID:johnnyWalnut,项目名称:mist.io,代码行数:8,代码来源:views.py

示例12: add_backend

def add_backend(request):
    """Adds a new backend."""

    params = request.json_body
    #remove spaces from start/end of string fields that are often included
    #when pasting keys, preventing thus succesfull connection with the
    #backend
    for key in params.keys():
        if type(params[key]) in [unicode, str]:
            params[key] = params[key].rstrip().lstrip()
    title = params.get('title', '')
    provider = params.get('provider', '')
    apikey = params.get('apikey', '')
    apisecret = params.get('apisecret', '')
    apiurl = params.get('apiurl') or ''  # fixes weird issue with none value
    tenant_name = params.get('tenant_name', '')
    # following params are for baremetal
    machine_hostname = params.get('machine_ip', '')
    machine_key = params.get('machine_key', '')
    machine_user = params.get('machine_user', '')
    remove_on_error = params.get('remove_on_error', True)
    try:
        docker_port = int(params.get('docker_port', 4243))
    except:
        docker_port = 4243
    try:
        ssh_port = int(params.get('machine_port', 22))
    except:
        ssh_port = 22
    region = params.get('region', '')
    compute_endpoint = params.get('compute_endpoint', '')
    # TODO: check if all necessary information was provided in the request

    user = user_from_request(request)
    backend_id = methods.add_backend(
        user, title, provider, apikey, apisecret, apiurl,
        tenant_name=tenant_name,
        machine_hostname=machine_hostname, machine_key=machine_key,
        machine_user=machine_user, region=region,
        compute_endpoint=compute_endpoint, port=ssh_port,
        docker_port=docker_port,
        remove_on_error=remove_on_error,
    )
    backend = user.backends[backend_id]
    return {
        'index': len(user.backends) - 1,
        'id': backend_id,
        'apikey': backend.apikey,
        'apiurl': backend.apiurl,
        'tenant_name': backend.tenant_name,
        'title': backend.title,
        'provider': backend.provider,
        'poll_interval': backend.poll_interval,
        'region': backend.region,
        'status': 'off',
        'enabled': backend.enabled,
    }
开发者ID:EzanLTD,项目名称:mist.io,代码行数:57,代码来源:views.py

示例13: get_stats

def get_stats(request):
    return methods.get_stats(
        user_from_request(request),
        request.matchdict['backend'],
        request.matchdict['machine'],
        request.params.get('start'),
        request.params.get('stop'),
        request.params.get('step')
    )
开发者ID:deanet,项目名称:mist.io,代码行数:9,代码来源:views.py

示例14: list_keys

def list_keys(request):
    """List keys.

    List all key pairs that are configured on this server. Only the public
    keys are returned.

    """
    user = user_from_request(request)
    return methods.list_keys(user)
开发者ID:johnnyWalnut,项目名称:mist.io,代码行数:9,代码来源:views.py

示例15: list_backends

def list_backends(request):
    """Gets the available backends.

    .. note:: Currently, this is only used by the backend controller in js.

    """

    user = user_from_request(request)
    return methods.list_backends(user)
开发者ID:johnnyWalnut,项目名称:mist.io,代码行数:9,代码来源:views.py


注:本文中的mist.core.helpers.user_from_request函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。