本文整理汇总了Python中mist.io.helpers.params_from_request函数的典型用法代码示例。如果您正苦于以下问题:Python params_from_request函数的具体用法?Python params_from_request怎么用?Python params_from_request使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了params_from_request函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_auth
def check_auth(request):
"""Check on the mist.core service if authenticated"""
params = params_from_request(request)
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()
示例2: 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)
示例3: update_user_settings
def update_user_settings(request):
"""try free plan, by communicating to the mist.core service"""
params = params_from_request(request)
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()
示例4: machine_actions
def machine_actions(request):
# TODO: We shouldn't return list_machines, just 200. Save the API!
cloud_id = request.matchdict['cloud']
machine_id = request.matchdict['machine']
user = user_from_request(request)
params = params_from_request(request)
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', 'undefine', 'suspend', 'resume'):
if action == 'start':
methods.start_machine(user, cloud_id, machine_id)
elif action == 'stop':
methods.stop_machine(user, cloud_id, machine_id)
elif action == 'reboot':
methods.reboot_machine(user, cloud_id, machine_id)
elif action == 'destroy':
methods.destroy_machine(user, cloud_id, machine_id)
elif action == 'resize':
methods.resize_machine(user, cloud_id, machine_id, plan_id)
elif action == 'rename':
methods.rename_machine(user, cloud_id, machine_id, name)
elif action == 'undefine':
methods.undefine_machine(user, cloud_id, machine_id)
elif action == 'resume':
methods.resume_machine(user, cloud_id, machine_id)
elif action == 'suspend':
methods.suspend_machine(user, cloud_id, machine_id)
# return OK
return methods.list_machines(user, cloud_id)
raise BadRequestError()
示例5: update_monitoring
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
示例6: disassoc_metric
def disassoc_metric(request):
user = user_from_request(request)
backend_id = request.matchdict['backend']
machine_id = request.matchdict['machine']
params = params_from_request(request)
metric_id = params.get('metric_id')
if not metric_id:
raise RequiredParameterMissingError('metric_id')
methods.disassoc_metric(user, backend_id, machine_id, metric_id)
return {}
示例7: edit_key
def edit_key(request):
old_id = request.matchdict['key']
params = params_from_request(request)
new_id = params.get('new_id')
if not new_id:
raise RequiredParameterMissingError("new_id")
user = user_from_request(request)
methods.edit_key(user, new_id, old_id)
return {'new_id': new_id}
示例8: rename_cloud
def rename_cloud(request):
"""Renames a cloud."""
cloud_id = request.matchdict['cloud']
params = params_from_request(request)
new_name = params.get('new_name', '')
if not new_name:
raise RequiredParameterMissingError('new_name')
user = user_from_request(request)
methods.rename_cloud(user, cloud_id, new_name)
return OK
示例9: add_key
def add_key(request):
params = params_from_request(request)
key_id = params.get('id', '')
private_key = params.get('priv', '')
user = user_from_request(request)
key_id = methods.add_key(user, key_id, private_key)
keypair = user.keypairs[key_id]
return {'id': key_id,
'machines': keypair.machines,
'isDefault': keypair.default}
示例10: update_metric
def update_metric(request):
user = user_from_request(request)
metric_id = request.matchdict['metric']
params = params_from_request(request)
methods.update_metric(
user,
metric_id,
name=params.get('name'),
unit=params.get('unit'),
backend_id=params.get('backend_id'),
machine_id=params.get('machine_id'),
)
return {}
示例11: undeploy_plugin
def undeploy_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.undeploy_python_plugin(user, backend_id,
machine_id, plugin_id, host)
return ret
else:
raise BadRequestError("Invalid plugin_type: '%s'" % plugin_type)
示例12: associate_ip
def associate_ip(request):
cloud_id = request.matchdict['cloud']
network_id = request.matchdict['network']
params = params_from_request(request)
ip = params.get('ip')
machine = params.get('machine')
assign = params.get('assign', True)
user = user_from_request(request)
ret = methods.associate_ip(user, cloud_id, network_id, ip, machine,
assign)
if ret:
return OK
else:
return Response("Bad Request", 400)
示例13: toggle_cloud
def toggle_cloud(request):
cloud_id = request.matchdict['cloud']
params = params_from_request(request)
new_state = params.get('new_state', '')
if not new_state:
raise RequiredParameterMissingError('new_state')
if new_state != "1" and new_state != "0":
raise BadRequestError('Invalid cloud state')
user = user_from_request(request)
if cloud_id not in user.clouds:
raise CloudNotFoundError()
with user.lock_n_load():
user.clouds[cloud_id].enabled = bool(int(new_state))
user.save()
trigger_session_update(user.email, ['clouds'])
return OK
示例14: probe
def probe(request):
"""Probes a machine using ping and ssh to collect metrics.
.. note:: Used for getting uptime and a list of deployed keys.
"""
machine_id = request.matchdict['machine']
cloud_id = request.matchdict['cloud']
params = params_from_request(request)
host = params.get('host', None)
key_id = params.get('key', None)
ssh_user = params.get('ssh_user', '')
# FIXME: simply don't pass a key parameter
if key_id == 'undefined':
key_id = ''
user = user_from_request(request)
ret = methods.probe(user, cloud_id, machine_id, host, key_id, ssh_user)
return ret
示例15: associate_key
def associate_key(request):
key_id = request.matchdict['key']
cloud_id = request.matchdict['cloud']
machine_id = request.matchdict['machine']
params = params_from_request(request)
ssh_user = params.get('user', None)
try:
ssh_port = int(request.json_body.get('port', 22))
except:
ssh_port = 22
try:
host = request.json_body.get('host')
except:
host = None
if not host:
raise RequiredParameterMissingError('host')
user = user_from_request(request)
methods.associate_key(user, key_id, cloud_id, machine_id, host,
username=ssh_user, port=ssh_port)
return user.keypairs[key_id].machines