本文整理汇总了Python中monasca_api.v2.reference.helpers.add_links_to_resource函数的典型用法代码示例。如果您正苦于以下问题:Python add_links_to_resource函数的具体用法?Python add_links_to_resource怎么用?Python add_links_to_resource使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_links_to_resource函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: on_post
def on_post(self, req, res):
helpers.validate_authorization(req, self._default_authorized_roles)
alarm_definition = helpers.read_json_msg_body(req)
self._validate_alarm_definition(alarm_definition)
tenant_id = helpers.get_tenant_id(req)
name = get_query_alarm_definition_name(alarm_definition)
expression = get_query_alarm_definition_expression(alarm_definition)
description = get_query_alarm_definition_description(alarm_definition)
severity = get_query_alarm_definition_severity(alarm_definition)
match_by = get_query_alarm_definition_match_by(alarm_definition)
alarm_actions = get_query_alarm_definition_alarm_actions(
alarm_definition)
undetermined_actions = get_query_alarm_definition_undetermined_actions(
alarm_definition)
ok_actions = get_query_ok_actions(alarm_definition)
result = self._alarm_definition_create(tenant_id, name, expression,
description, severity, match_by,
alarm_actions,
undetermined_actions,
ok_actions)
helpers.add_links_to_resource(result, req.uri)
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_201
开发者ID:nilwyh,项目名称:monasca-api,代码行数:28,代码来源:alarm_definitions.py
示例2: on_get
def on_get(self, req, res, alarm_definition_id=None):
if alarm_definition_id is None:
helpers.validate_authorization(req, self._default_authorized_roles)
tenant_id = helpers.get_tenant_id(req)
name = helpers.get_query_name(req)
dimensions = helpers.get_query_dimensions(req)
offset = helpers.get_query_param(req, 'offset')
limit = helpers.get_limit(req)
result = self._alarm_definition_list(tenant_id, name, dimensions,
req.uri, offset, limit)
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
else:
helpers.validate_authorization(req, self._default_authorized_roles)
tenant_id = helpers.get_tenant_id(req)
result = self._alarm_definition_show(tenant_id,
alarm_definition_id)
helpers.add_links_to_resource(result,
re.sub('/' + alarm_definition_id, '',
req.uri))
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
开发者ID:nilwyh,项目名称:monasca-api,代码行数:27,代码来源:alarm_definitions.py
示例3: on_post
def on_post(self, req, res):
helpers.validate_authorization(req, ['api:alarms:definition:post'])
alarm_definition = helpers.from_json(req)
self._validate_alarm_definition(alarm_definition)
name = get_query_alarm_definition_name(alarm_definition)
expression = get_query_alarm_definition_expression(alarm_definition)
description = get_query_alarm_definition_description(alarm_definition)
severity = get_query_alarm_definition_severity(alarm_definition)
match_by = get_query_alarm_definition_match_by(alarm_definition)
alarm_actions = get_query_alarm_definition_alarm_actions(
alarm_definition)
undetermined_actions = get_query_alarm_definition_undetermined_actions(
alarm_definition)
ok_actions = get_query_ok_actions(alarm_definition)
result = self._alarm_definition_create(req.project_id, name, expression,
description, severity, match_by,
alarm_actions,
undetermined_actions,
ok_actions)
helpers.add_links_to_resource(result, req.uri)
res.body = helpers.to_json(result)
res.status = falcon.HTTP_201
开发者ID:openstack,项目名称:monasca-api,代码行数:27,代码来源:alarm_definitions.py
示例4: _alarm_list
def _alarm_list(self, req_uri, tenant_id, query_parms, offset, limit):
alarm_rows = self._alarms_repo.get_alarms(tenant_id, query_parms,
offset, limit)
result = []
if not alarm_rows:
return result
# Forward declaration
alarm = {}
prev_alarm_id = None
for alarm_row in alarm_rows:
if prev_alarm_id != alarm_row['alarm_id']:
if prev_alarm_id is not None:
result.append(alarm)
ad = {u'id': alarm_row['alarm_definition_id'],
u'name': alarm_row['alarm_definition_name'],
u'severity': alarm_row['severity'], }
helpers.add_links_to_resource(ad,
re.sub('alarms',
'alarm-definitions',
req_uri))
metrics = []
alarm = {u'id': alarm_row['alarm_id'], u'metrics': metrics,
u'state': alarm_row['state'],
u'lifecycle_state': alarm_row['lifecycle_state'],
u'link': alarm_row['link'],
u'state_updated_timestamp':
alarm_row['state_updated_timestamp'].isoformat() +
'Z',
u'updated_timestamp':
alarm_row['updated_timestamp'].isoformat() + 'Z',
u'created_timestamp':
alarm_row['created_timestamp'].isoformat() + 'Z',
u'alarm_definition': ad}
helpers.add_links_to_resource(alarm, req_uri)
prev_alarm_id = alarm_row['alarm_id']
dimensions = {}
metric = {u'name': alarm_row['metric_name'],
u'dimensions': dimensions}
if alarm_row['metric_dimensions']:
for dimension in alarm_row['metric_dimensions'].split(','):
parsed_dimension = dimension.split('=')
dimensions[parsed_dimension[0]] = parsed_dimension[1]
metrics.append(metric)
result.append(alarm)
return helpers.paginate(result, req_uri, limit)
开发者ID:kamil-khamidullin,项目名称:monasca-api,代码行数:57,代码来源:alarms.py
示例5: _alarm_list
def _alarm_list(self, req_uri, tenant_id, query_parms, offset, limit):
alarm_rows = self._alarms_repo.get_alarms(tenant_id, query_parms, offset, limit)
result = []
if not alarm_rows:
return helpers.paginate_alarming(result, req_uri, limit)
# Forward declaration
alarm = {}
prev_alarm_id = None
for alarm_row in alarm_rows:
if prev_alarm_id != alarm_row["alarm_id"]:
if prev_alarm_id is not None:
Alarms._render_alarm(alarm)
result.append(alarm)
ad = {
u"id": alarm_row["alarm_definition_id"],
u"name": alarm_row["alarm_definition_name"],
u"description": alarm_row["alarm_definition_description"],
u"severity": alarm_row["severity"],
}
helpers.add_links_to_resource(ad, re.sub("alarms", "alarm-definitions", req_uri))
metrics = []
alarm = {
u"id": alarm_row["alarm_id"],
u"metrics": metrics,
u"state": alarm_row["state"],
u"lifecycle_state": alarm_row["lifecycle_state"],
u"link": alarm_row["link"],
u"state_updated_timestamp": alarm_row["state_updated_timestamp"].isoformat() + "Z",
u"updated_timestamp": alarm_row["updated_timestamp"].isoformat() + "Z",
u"created_timestamp": alarm_row["created_timestamp"].isoformat() + "Z",
u"alarm_definition": ad,
}
helpers.add_links_to_resource(alarm, req_uri)
prev_alarm_id = alarm_row["alarm_id"]
dimensions = {}
metric = {u"name": alarm_row["metric_name"], u"dimensions": dimensions}
if alarm_row["metric_dimensions"]:
for dimension in alarm_row["metric_dimensions"].split(","):
parsed_dimension = dimension.split("=")
dimensions[parsed_dimension[0]] = parsed_dimension[1]
metrics.append(metric)
Alarms._render_alarm(alarm)
result.append(alarm)
return helpers.paginate_alarming(result, req_uri, limit)
开发者ID:sapcc,项目名称:monasca-api,代码行数:56,代码来源:alarms.py
示例6: _build_notification_result
def _build_notification_result(self, notification_row, uri):
result = {
u'id': notification_row['id'],
u'name': notification_row['name'],
u'type': notification_row['type'],
u'address': notification_row['address']
}
helpers.add_links_to_resource(result, uri)
return result
开发者ID:Missxiaoguo,项目名称:monasca-api,代码行数:12,代码来源:notifications.py
示例7: _build_notification_result
def _build_notification_result(self, notification_row, uri):
result = {
u"id": notification_row["id"],
u"name": notification_row["name"],
u"type": notification_row["type"],
u"address": notification_row["address"],
}
helpers.add_links_to_resource(result, uri)
return result
开发者ID:nilwyh,项目名称:monasca-api,代码行数:12,代码来源:notifications.py
示例8: on_put
def on_put(self, req, res, alarm_definition_id):
helpers.validate_authorization(req, self._default_authorized_roles)
alarm_definition = helpers.read_json_msg_body(req)
self._validate_alarm_definition(alarm_definition)
tenant_id = helpers.get_tenant_id(req)
# Mandatory positional args
name = get_query_alarm_definition_name(alarm_definition)
expression = get_query_alarm_definition_expression(alarm_definition)
actions_enabled = (
get_query_alarm_definition_actions_enabled(alarm_definition,
required=True))
# Validator makes actions_enabled optional. So, check it here.
if not actions_enabled:
raise falcon.HTTPBadRequest('Bad request', 'Missing '
'actions_enabled')
# Optional args
description = get_query_alarm_definition_description(alarm_definition,
return_none=True)
alarm_actions = get_query_alarm_definition_alarm_actions(
alarm_definition, return_none=True)
ok_actions = get_query_ok_actions(alarm_definition, return_none=True)
undetermined_actions = get_query_alarm_definition_undetermined_actions(
alarm_definition, return_none=True)
match_by = get_query_alarm_definition_match_by(alarm_definition,
return_none=True)
severity = get_query_alarm_definition_severity(alarm_definition,
return_none=True)
result = self._alarm_definition_update_or_patch(tenant_id,
alarm_definition_id,
name,
expression,
actions_enabled,
description,
alarm_actions,
ok_actions,
undetermined_actions,
match_by,
severity,
patch=False)
helpers.add_links_to_resource(result, req.uri)
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
开发者ID:nilwyh,项目名称:monasca-api,代码行数:51,代码来源:alarm_definitions.py
示例9: on_patch
def on_patch(self, req, res, alarm_definition_id=None):
if not alarm_definition_id:
raise HTTPBadRequestError('Bad Request', 'Alarm definition ID not provided')
helpers.validate_authorization(req, ['api:alarms:definition:patch'])
alarm_definition = helpers.from_json(req)
# Optional args
name = get_query_alarm_definition_name(alarm_definition,
return_none=True)
expression = get_query_alarm_definition_expression(alarm_definition,
return_none=True)
actions_enabled = (
get_query_alarm_definition_actions_enabled(alarm_definition,
return_none=True))
description = get_query_alarm_definition_description(alarm_definition,
return_none=True)
alarm_actions = get_query_alarm_definition_alarm_actions(
alarm_definition, return_none=True)
ok_actions = get_query_ok_actions(alarm_definition, return_none=True)
undetermined_actions = get_query_alarm_definition_undetermined_actions(
alarm_definition, return_none=True)
match_by = get_query_alarm_definition_match_by(alarm_definition,
return_none=True)
severity = get_query_alarm_definition_severity(alarm_definition,
return_none=True)
result = self._alarm_definition_update_or_patch(req.project_id,
alarm_definition_id,
name,
expression,
actions_enabled,
description,
alarm_actions,
ok_actions,
undetermined_actions,
match_by,
severity,
patch=True)
helpers.add_links_to_resource(
result, re.sub('/' + alarm_definition_id, '', req.uri))
res.body = helpers.to_json(result)
res.status = falcon.HTTP_200
开发者ID:openstack,项目名称:monasca-api,代码行数:47,代码来源:alarm_definitions.py
示例10: on_get
def on_get(self, req, res, alarm_definition_id=None):
if alarm_definition_id is None:
helpers.validate_authorization(req, self._default_authorized_roles)
tenant_id = helpers.get_tenant_id(req)
name = helpers.get_query_name(req)
dimensions = helpers.get_query_dimensions(req)
severity = helpers.get_query_param(req, "severity", default_val=None)
if severity is not None:
validation.validate_severity_query(severity)
sort_by = helpers.get_query_param(req, 'sort_by', default_val=None)
if sort_by is not None:
if isinstance(sort_by, basestring):
sort_by = sort_by.split(',')
allowed_sort_by = {'id', 'name', 'severity',
'updated_at', 'created_at'}
validation.validate_sort_by(sort_by, allowed_sort_by)
offset = helpers.get_query_param(req, 'offset')
if offset is not None and not isinstance(offset, int):
try:
offset = int(offset)
except Exception:
raise HTTPUnprocessableEntityError('Unprocessable Entity',
'Offset value {} must be an integer'.format(offset))
limit = helpers.get_limit(req)
result = self._alarm_definition_list(tenant_id, name, dimensions, severity,
req.uri, sort_by, offset, limit)
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
else:
helpers.validate_authorization(req, self._default_authorized_roles)
tenant_id = helpers.get_tenant_id(req)
result = self._alarm_definition_show(tenant_id,
alarm_definition_id)
helpers.add_links_to_resource(result,
re.sub('/' + alarm_definition_id, '',
req.uri))
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
开发者ID:bigluster,项目名称:monasca-api,代码行数:46,代码来源:alarm_definitions.py
示例11: _alarm_show
def _alarm_show(self, req_uri, tenant_id, alarm_id):
alarm_rows = self._alarms_repo.get_alarm(tenant_id, alarm_id)
req_uri_no_id = req_uri.replace('/' + alarm_id, "")
first_row = True
for alarm_row in alarm_rows:
if first_row:
ad = {u'id': alarm_row['alarm_definition_id'],
u'name': alarm_row['alarm_definition_name'],
u'severity': alarm_row['severity'], }
helpers.add_links_to_resource(ad,
re.sub('alarms',
'alarm-definitions',
req_uri_no_id))
metrics = []
alarm = {u'id': alarm_row['alarm_id'], u'metrics': metrics,
u'state': alarm_row['state'],
u'lifecycle_state': alarm_row['lifecycle_state'],
u'link': alarm_row['link'],
u'state_updated_timestamp':
alarm_row['state_updated_timestamp'].isoformat() +
'Z',
u'updated_timestamp':
alarm_row['updated_timestamp'].isoformat() + 'Z',
u'created_timestamp':
alarm_row['created_timestamp'].isoformat() + 'Z',
u'alarm_definition': ad}
helpers.add_links_to_resource(alarm, req_uri_no_id)
first_row = False
dimensions = {}
metric = {u'name': alarm_row['metric_name'],
u'dimensions': dimensions}
if alarm_row['metric_dimensions']:
for dimension in alarm_row['metric_dimensions'].split(','):
parsed_dimension = dimension.split('=')
dimensions[parsed_dimension[0]] = parsed_dimension[1]
metrics.append(metric)
return alarm
开发者ID:Missxiaoguo,项目名称:monasca-api,代码行数:45,代码来源:alarms.py
示例12: on_patch
def on_patch(self, req, res, alarm_definition_id):
helpers.validate_authorization(req, self._default_authorized_roles)
alarm_definition = helpers.read_json_msg_body(req)
tenant_id = helpers.get_tenant_id(req)
# Optional args
name = get_query_alarm_definition_name(alarm_definition,
return_none=True)
expression = get_query_alarm_definition_expression(alarm_definition,
return_none=True)
actions_enabled = (
get_query_alarm_definition_actions_enabled(alarm_definition,
return_none=True))
description = get_query_alarm_definition_description(alarm_definition,
return_none=True)
alarm_actions = get_query_alarm_definition_alarm_actions(
alarm_definition, return_none=True)
ok_actions = get_query_ok_actions(alarm_definition, return_none=True)
undetermined_actions = get_query_alarm_definition_undetermined_actions(
alarm_definition, return_none=True)
match_by = get_query_alarm_definition_match_by(alarm_definition,
return_none=True)
severity = get_query_alarm_definition_severity(alarm_definition,
return_none=True)
result = self._alarm_definition_update_or_patch(tenant_id,
alarm_definition_id,
name,
expression,
actions_enabled,
description,
alarm_actions,
ok_actions,
undetermined_actions,
match_by,
severity,
patch=True)
helpers.add_links_to_resource(result, req.uri)
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
开发者ID:nilwyh,项目名称:monasca-api,代码行数:45,代码来源:alarm_definitions.py
示例13: _alarm_show
def _alarm_show(self, req_uri, tenant_id, alarm_id):
alarm_rows = self._alarms_repo.get_alarm(tenant_id, alarm_id)
req_uri_no_id = req_uri.replace("/" + alarm_id, "")
first_row = True
for alarm_row in alarm_rows:
if first_row:
ad = {
u"id": alarm_row["alarm_definition_id"],
u"name": alarm_row["alarm_definition_name"],
u"description": alarm_row["alarm_definition_description"],
u"severity": alarm_row["severity"],
}
helpers.add_links_to_resource(ad, re.sub("alarms", "alarm-definitions", req_uri_no_id))
metrics = []
alarm = {
u"id": alarm_row["alarm_id"],
u"metrics": metrics,
u"state": alarm_row["state"],
u"lifecycle_state": alarm_row["lifecycle_state"],
u"link": alarm_row["link"],
u"state_updated_timestamp": alarm_row["state_updated_timestamp"].isoformat() + "Z",
u"updated_timestamp": alarm_row["updated_timestamp"].isoformat() + "Z",
u"created_timestamp": alarm_row["created_timestamp"].isoformat() + "Z",
u"alarm_definition": ad,
}
helpers.add_links_to_resource(alarm, req_uri_no_id)
first_row = False
dimensions = {}
metric = {u"name": alarm_row["metric_name"], u"dimensions": dimensions}
if alarm_row["metric_dimensions"]:
for dimension in alarm_row["metric_dimensions"].split(","):
parsed_dimension = dimension.split("=")
dimensions[parsed_dimension[0]] = parsed_dimension[1]
metrics.append(metric)
Alarms._render_alarm(alarm)
return alarm
开发者ID:sapcc,项目名称:monasca-api,代码行数:45,代码来源:alarms.py
示例14: _alarm_definition_list
def _alarm_definition_list(self, tenant_id, name, dimensions, severity, req_uri, sort_by,
offset, limit):
alarm_definition_rows = (
self._alarm_definitions_repo.get_alarm_definitions(tenant_id, name,
dimensions, severity, sort_by,
offset, limit))
result = []
for alarm_definition_row in alarm_definition_rows:
match_by = get_comma_separated_str_as_list(
alarm_definition_row['match_by'])
alarm_actions_list = get_comma_separated_str_as_list(
alarm_definition_row['alarm_actions'])
ok_actions_list = get_comma_separated_str_as_list(
alarm_definition_row['ok_actions'])
undetermined_actions_list = get_comma_separated_str_as_list(
alarm_definition_row['undetermined_actions'])
expression = alarm_definition_row['expression']
is_deterministic = is_definition_deterministic(expression)
ad = {u'id': alarm_definition_row['id'],
u'name': alarm_definition_row['name'],
u'description': alarm_definition_row['description'] if (
alarm_definition_row['description']) else u'',
u'expression': alarm_definition_row['expression'],
u'deterministic': is_deterministic,
u'match_by': match_by,
u'severity': alarm_definition_row['severity'].upper(),
u'actions_enabled':
alarm_definition_row['actions_enabled'] == 1,
u'alarm_actions': alarm_actions_list,
u'ok_actions': ok_actions_list,
u'undetermined_actions': undetermined_actions_list}
helpers.add_links_to_resource(ad, req_uri)
result.append(ad)
result = helpers.paginate_alarming(result, req_uri, limit)
return result
开发者ID:bigluster,项目名称:monasca-api,代码行数:44,代码来源:alarm_definitions.py
示例15: _create_notification_response
def _create_notification_response(self, id, name, type,
address, uri):
response = {
'id': id,
'name': name,
'type': type,
'address': address
}
return helpers.add_links_to_resource(response, uri)
开发者ID:Missxiaoguo,项目名称:monasca-api,代码行数:11,代码来源:notifications.py
示例16: on_put
def on_put(self, req, res, alarm_definition_id):
helpers.validate_authorization(req, self._default_authorized_roles)
alarm_definition = helpers.read_json_msg_body(req)
self._validate_alarm_definition(alarm_definition, require_all=True)
name = get_query_alarm_definition_name(alarm_definition)
expression = get_query_alarm_definition_expression(alarm_definition)
actions_enabled = (
get_query_alarm_definition_actions_enabled(alarm_definition))
description = get_query_alarm_definition_description(alarm_definition)
alarm_actions = get_query_alarm_definition_alarm_actions(alarm_definition)
ok_actions = get_query_ok_actions(alarm_definition)
undetermined_actions = get_query_alarm_definition_undetermined_actions(
alarm_definition)
match_by = get_query_alarm_definition_match_by(alarm_definition)
severity = get_query_alarm_definition_severity(alarm_definition)
result = self._alarm_definition_update_or_patch(req.project_id,
alarm_definition_id,
name,
expression,
actions_enabled,
description,
alarm_actions,
ok_actions,
undetermined_actions,
match_by,
severity,
patch=False)
helpers.add_links_to_resource(result, req.uri)
res.body = helpers.dumpit_utf8(result)
res.status = falcon.HTTP_200
开发者ID:jobrs,项目名称:monasca-api,代码行数:36,代码来源:alarm_definitions.py
示例17: _create_notification_response
def _create_notification_response(self, id, name, type, address, period, uri):
response = {"id": id, "name": name, "type": type, "address": address, "period": period}
return helpers.add_links_to_resource(response, uri)
开发者ID:sapcc,项目名称:monasca-api,代码行数:5,代码来源:notifications.py
注:本文中的monasca_api.v2.reference.helpers.add_links_to_resource函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论