本文整理汇总了Python中pyrax.utils.get_id函数的典型用法代码示例。如果您正苦于以下问题:Python get_id函数的具体用法?Python get_id怎么用?Python get_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_id函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_check
def delete_check(self, entity, check):
"""
Deletes the specified check from the entity.
"""
uri = "/%s/%s/checks/%s" % (self.uri_base, utils.get_id(entity),
utils.get_id(check))
resp, resp_body = self.api.method_delete(uri)
示例2: update_check
def update_check(self, check, label=None, name=None, disabled=None,
metadata=None, monitoring_zones_poll=None, timeout=None,
period=None, target_alias=None, target_hostname=None,
target_receiver=None):
if monitoring_zones_poll:
monitoring_zones_poll = utils.coerce_string_to_list(
monitoring_zones_poll)
monitoring_zones_poll = [utils.get_id(mzp)
for mzp in monitoring_zones_poll]
body = {}
local_dict = locals()
label = label or name
params = ("label", "disabled", "metadata", "monitoring_zones_poll",
"timeout", "period", "target_alias", "target_hostname",
"target_receiver")
body = _params_to_dict(params, body, locals())
entity = check.entity
uri = "/%s/%s/checks/%s" % (self.uri_base, utils.get_id(entity),
utils.get_id(check))
try:
resp, resp_body = self.api.method_put(uri, body=body)
except exc.BadRequest as e:
msg = e.message
dtls = e.details
if msg.startswith("Validation error"):
raise exc.InvalidMonitoringCheckUpdate("The update failed "
"validation: %s: %s" % (msg, dtls))
else:
# Some other issue.
raise
return resp_body
示例3: update_policy
def update_policy(self, scaling_group, policy, name=None, policy_type=None,
cooldown=None, change=None, is_percent=False,
desired_capacity=None, args=None):
"""
Updates the specified policy. One or more of the parameters may be
specified.
"""
uri = "/%s/%s/policies/%s" % (self.uri_base,
utils.get_id(scaling_group), utils.get_id(policy))
if not isinstance(policy, AutoScalePolicy):
# Received an ID
policy = self.get_policy(scaling_group, policy)
body = {"name": name or policy.name,
"type": policy_type or policy.type,
"cooldown": cooldown or policy.cooldown,
}
if desired_capacity is not None:
body["desiredCapacity"] = desired_capacity
elif change is not None:
if is_percent:
body["changePercent"] = change
else:
body["change"] = change
else:
if getattr(policy, "changePercent", None) is not None:
body["changePercent"] = policy.changePercent
elif getattr(policy, "change", None) is not None:
body["change"] = policy.change
elif getattr(policy, "desiredCapacity", None) is not None:
body["desiredCapacity"] = policy.desiredCapacity
args = args or getattr(policy, "args", None)
if args is not None:
body["args"] = args
resp, resp_body = self.api.method_put(uri, body=body)
return None
示例4: create_alarm
def create_alarm(self, entity, check, notification_plan, criteria=None,
disabled=False, label=None, name=None, metadata=None):
"""
Creates an alarm that binds the check on the given entity with a
notification plan.
Note that the 'criteria' parameter, if supplied, should be a string
representing the DSL for describing alerting conditions and their
output states. Pyrax does not do any validation of these criteria
statements; it is up to you as the developer to understand the language
and correctly form the statement. This alarm language is documented
online in the Cloud Monitoring section of http://docs.rackspace.com.
"""
uri = "/%s/%s/alarms" % (self.uri_base, utils.get_id(entity))
body = {"check_id": utils.get_id(check),
"notification_plan_id": utils.get_id(notification_plan),
}
if criteria:
body["criteria"] = criteria
if disabled is not None:
body["disabled"] = disabled
label_name = label or name
if label_name:
body["label"] = label_name
if metadata:
body["metadata"] = metadata
resp, resp_body = self.api.method_post(uri, body=body)
if resp.status_code == 201:
alarm_id = resp.headers["x-object-id"]
return self.get_alarm(entity, alarm_id)
示例5: delete_alarm
def delete_alarm(self, entity, alarm):
"""
Deletes the specified alarm.
"""
uri = "/%s/%s/alarms/%s" % (self.uri_base, utils.get_id(entity),
utils.get_id(alarm))
resp, resp_body = self.api.method_delete(uri)
示例6: delete_policy
def delete_policy(self, scaling_group, policy):
"""
Deletes the specified policy from the scaling group.
"""
uri = "/%s/%s/policies/%s" % (self.uri_base,
utils.get_id(scaling_group), utils.get_id(policy))
resp, resp_body = self.api.method_delete(uri)
示例7: _get_node_base_uri
def _get_node_base_uri(self, pool, node=None):
if node is not None:
template = "/%s/%s/nodes/%s"
params = (self.uri_base, utils.get_id(pool), utils.get_id(node))
else:
template = "/%s/%s/nodes"
params = (self.uri_base, utils.get_id(pool))
return template % params
示例8: get_check
def get_check(self, entity, check):
"""
Returns the current version of the check for the entity.
"""
uri = "/%s/%s/checks/%s" % (self.uri_base, utils.get_id(entity),
utils.get_id(check))
resp, resp_body = self.api.method_get(uri)
return CloudMonitorCheck(self, resp_body, entity)
示例9: execute_policy
def execute_policy(self, scaling_group, policy):
"""
Executes the specified policy for this scaling group.
"""
uri = "/%s/%s/policies/%s/execute" % (self.uri_base,
utils.get_id(scaling_group), utils.get_id(policy))
resp, resp_body = self.api.method_post(uri)
return None
示例10: get_record
def get_record(self, domain, record):
"""
Gets the full information for an existing record for this domain.
"""
rec_id = utils.get_id(record)
uri = "/domains/%s/records/%s" % (utils.get_id(domain), rec_id)
resp, ret_body = self.api.method_get(uri)
return ret_body
示例11: delete_record
def delete_record(self, domain, record):
"""
Deletes an existing record for a domain.
"""
uri = "/domains/%s/records/%s" % (utils.get_id(domain), utils.get_id(record))
resp, ret_body = self._async_call(uri, method="DELETE",
error_class=exc.DomainRecordDeletionFailed, has_response=False)
return ret_body
示例12: test_get_id
def test_get_id(self):
target = "test_id"
class Obj_with_id(object):
id = target
obj = Obj_with_id()
self.assertEqual(utils.get_id(obj), target)
self.assertEqual(utils.get_id(obj), target)
self.assertEqual(utils.get_id(obj.id), target)
示例13: get_metric_data_points
def get_metric_data_points(self, entity, check, metric, start, end,
points=None, resolution=None, stats=None):
"""
Returns the data points for a given metric for the given period. The
'start' and 'end' times must be specified; they can be be either Python
date/datetime values, a string representing a date/datetime in either
of 'YYYY-MM-DD HH:MM:SS' or 'YYYY-MM-DD' formats, or a Unix timestamp:
The 'points' parameter represents the number of points to return. The
'resolution' parameter represents the granularity of the data. You must
specify either 'points' or 'resolution', but not both. The allowed
values for resolution are: 'FULL', 'MIN5', 'MIN20', 'MIN60', 'MIN240',
and 'MIN1440'.
Finally, the 'stats' parameter specifies the stats you want returned.
By default only the 'average' is returned. You omit this parameter,
pass in a single value, or pass in a list of values. The allowed values
are: 'average', 'variance', 'min', and 'max'
"""
allowed_resolutions = ("FULL", "MIN5", "MIN20", "MIN60", "MIN240",
"MIN1440")
if not (points or resolution):
raise exc.MissingMonitoringCheckGranularity("You must specify "
"either the 'points' or 'resolution' parameter when "
"fetching metrics.")
if resolution:
if resolution.upper() not in allowed_resolutions:
raise exc.InvalidMonitoringMetricsResolution("The specified "
"resolution '%s' is not valid. The valid values are: "
"%s." % (resolution, str(allowed_resolutions)))
start_tm = utils.to_timestamp(start)
end_tm = utils.to_timestamp(end)
qparms = []
# Timestamps with fractional seconds currently cause a 408 (timeout)
qparms.append("from=%s" % int(start_tm))
qparms.append("to=%s" % int(end_tm))
if points:
qparms.append("points=%s" % points)
if resolution:
qparms.append("resolution=%s" % resolution.upper())
if stats:
stats = utils.coerce_string_to_list(stats)
for stat in stats:
qparms.append("select=%s" % stat)
qparm = "&".join(qparms)
uri = "/%s/%s/checks/%s/metrics/%s/plot?%s" % (self.uri_base,
utils.get_id(entity), utils.get_id(check), metric, qparm)
try:
resp, resp_body = self.api.method_get(uri)
except exc.BadRequest as e:
msg = e.message
dtls = e.details
if msg.startswith("Validation error"):
raise exc.InvalidMonitoringMetricsRequest("Your request was "
"invalid: '%s'" % dtls)
else:
raise
return resp_body["values"]
示例14: _make_pool_node_body
def _make_pool_node_body(self, pool, server):
return {
'cloud_server': {
'id': utils.get_id(server)
},
'load_balancer_pool': {
'id': utils.get_id(pool),
}
}
示例15: delete_webhook
def delete_webhook(self, scaling_group, policy, webhook):
"""
Deletes the specified webhook from the specified policy.
"""
uri = "/%s/%s/policies/%s/webhooks/%s" % (self.uri_base,
utils.get_id(scaling_group), utils.get_id(policy),
utils.get_id(webhook))
resp, resp_body = self.api.method_delete(uri)
return None