コード例 #1
0
ファイル: views.py プロジェクト: fabiopedrosa/mist.io
def update_monitoring(request):
    """Enable/disable monitoring for this machine using the hosted mist.io
    service.

    """
    user = user_from_request(request)
    cloud_id = request.matchdict['cloud']
    machine_id = request.matchdict['machine']
    params = params_from_request(request)
    if not user.mist_api_token:
        log.info("trying to authenticate to service first")
        email = params.get('email')
        password = params.get('password')
        if not email or not password:
            raise UnauthorizedError("You need to authenticate to mist.io.")
        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)
            with user.lock_n_load():
                user.email = email
                user.mist_api_token = ret_dict.pop('token', '')
                user.save()
            log.info("succesfully check_authed")
        elif ret.status_code in [400, 401]:
            with user.lock_n_load():
                user.email = ""
                user.mist_api_token = ""
                user.save()
            raise UnauthorizedError("You need to authenticate to mist.io.")
        else:
            raise UnauthorizedError("You need to authenticate to mist.io.")

    action = params.get('action') or 'enable'
    name = params.get('name', '')
    public_ips = params.get('public_ips', [])
    dns_name = params.get('dns_name', '')
    no_ssh = bool(params.get('no_ssh', False))
    dry = bool(params.get('dry', False))

    if action == 'enable':
        ret_dict = methods.enable_monitoring(
            user, cloud_id, machine_id, name, dns_name, public_ips,
            no_ssh=no_ssh, dry=dry
        )
    elif action == 'disable':
        methods.disable_monitoring(user, cloud_id, machine_id, no_ssh=no_ssh)
        ret_dict = {}
    else:
        raise BadRequestError()

    return ret_dict
コード例 #2
0
ファイル: views.py プロジェクト: carlcdavid/mist.io
def update_monitoring(request):
    """Enable/disable monitoring for this machine using the hosted mist.io
    service.

    """
    user = user_from_request(request)
    cloud_id = request.matchdict['cloud']
    machine_id = request.matchdict['machine']
    params = params_from_request(request)
    if not user.mist_api_token:
        log.info("trying to authenticate to service first")
        email = params.get('email')
        password = params.get('password')
        if not email or not password:
            raise UnauthorizedError("You need to authenticate to mist.io.")
        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)
            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")
        else:
            raise UnauthorizedError("You need to authenticate to mist.io.")

    action = params.get('action') or 'enable'
    name = params.get('name', '')
    public_ips = params.get('public_ips', [])
    dns_name = params.get('dns_name', '')
    no_ssh = bool(params.get('no_ssh', False))
    dry = bool(params.get('dry', False))

    if action == 'enable':
        ret_dict = methods.enable_monitoring(user,
                                             cloud_id,
                                             machine_id,
                                             name,
                                             dns_name,
                                             public_ips,
                                             no_ssh=no_ssh,
                                             dry=dry)
    elif action == 'disable':
        methods.disable_monitoring(user, cloud_id, machine_id, no_ssh=no_ssh)
        ret_dict = {}
    else:
        raise BadRequestError()

    return ret_dict
コード例 #3
0
ファイル: views.py プロジェクト: smeverts/mist.io
def update_monitoring(request):
    """Enable/disable monitoring for this machine using the hosted mist.io
    service.

    """
    user = user_from_request(request)
    backend_id = request.matchdict['backend']
    machine_id = request.matchdict['machine']
    if not user.mist_api_token:
        log.info("trying to authenticate to service first")
        email = request.json_body.get('email')
        password = request.json_body.get('password')
        if not email or not password:
            raise UnauthorizedError("You need to authenticate to mist.io.")
        payload = {'email': email, 'password': password}
        ret = requests.post(config.CORE_URI + '/auth', params=payload, verify=False)
        if ret.status_code == 200:
            ret_dict = json.loads(ret.content)
            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")
        else:
            raise UnauthorizedError("You need to authenticate to mist.io.")

    action = request.json_body['action'] or 'enable'
    name = request.json_body.get('name', '')
    public_ips = request.json_body.get('public_ips', [])
    dns_name = request.json_body.get('dns_name', '')

    payload = {
        'action': action,
        'name': name,
        'public_ips': ",".join(public_ips),
        'dns_name': dns_name,
        # tells core not to try to run ssh command to (un)deploy collectd
        'no_ssh': True,
    }

    if action == 'enable':
        stdout = methods.enable_monitoring(
            user, backend_id, machine_id, name, dns_name, public_ips
        )
    elif action == 'disable':
        stdout = methods.disable_monitoring(user, backend_id, machine_id)
    else:
        raise BadRequestError()

    return {'cmd_output': stdout}
コード例 #4
0
def update_monitoring(request):
    """Enable/disable monitoring for this machine using the hosted mist.io
    service.

    """
    user = user_from_request(request)
    backend_id = request.matchdict['backend']
    machine_id = request.matchdict['machine']
    if not user.mist_api_token:
        log.info("trying to authenticate to service first")
        email = request.json_body.get('email')
        password = request.json_body.get('password')
        if not email or not password:
            raise UnauthorizedError("You need to authenticate to mist.io.")
        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)
            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")
        else:
            raise UnauthorizedError("You need to authenticate to mist.io.")

    action = request.json_body['action'] or 'enable'
    name = request.json_body.get('name', '')
    public_ips = request.json_body.get('public_ips', [])
    dns_name = request.json_body.get('dns_name', '')
    no_ssh = bool(request.json_body.get('no_ssh', False))
    dry = bool(request.json_body.get('dry', False))

    payload = {
        'action': action,
        'name': name,
        'public_ips': ",".join(public_ips),
        'dns_name': dns_name,
        # tells core not to try to run ssh command to (un)deploy collectd
        'no_ssh': True,
        'dry': dry,
    }

    if action == 'enable':
        ret_dict = methods.enable_monitoring(user,
                                             backend_id,
                                             machine_id,
                                             name,
                                             dns_name,
                                             public_ips,
                                             no_ssh=no_ssh,
                                             dry=dry)
    elif action == 'disable':
        stdout = methods.disable_monitoring(user,
                                            backend_id,
                                            machine_id,
                                            no_ssh=no_ssh)
        ret_dict = {'cmd_output': stdout}
    else:
        raise BadRequestError()

    return ret_dict