本文整理汇总了Python中appscale.tools.local_state.LocalState.get_secret_key方法的典型用法代码示例。如果您正苦于以下问题:Python LocalState.get_secret_key方法的具体用法?Python LocalState.get_secret_key怎么用?Python LocalState.get_secret_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类appscale.tools.local_state.LocalState
的用法示例。
在下文中一共展示了LocalState.get_secret_key方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_stats
# 需要导入模块: from appscale.tools.local_state import LocalState [as 别名]
# 或者: from appscale.tools.local_state.LocalState import get_secret_key [as 别名]
def _get_stats(keyname, stats_kind, include_lists):
"""
Returns statistics from Hermes.
Args:
keyname: A string representing an identifier from AppScaleFile.
stats_kind: A string representing a kind of statistics.
include_lists: A dict representing desired fields.
Returns:
A dict of statistics.
A dict of failures.
"""
load_balancer_ip = LocalState.get_host_with_role(keyname, 'load_balancer')
secret = LocalState.get_secret_key(keyname=keyname)
administration_port = "17441"
stats_path = "/stats/cluster/{stats_kind}".format(stats_kind=stats_kind)
headers = {'Appscale-Secret': secret}
data = {'include_lists': include_lists}
url = "https://{ip}:{port}{path}".format(
ip=load_balancer_ip,
port=administration_port,
path=stats_path
)
try:
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
resp = requests.get(
url=url,
headers=headers,
json=data,
verify=False
)
resp.raise_for_status()
except requests.HTTPError as err:
AppScaleLogger.warn(
"Failed to get {stats_kind} stats ({err})"
.format(stats_kind=stats_kind, err=err)
)
return {}, {}
json_body = resp.json()
return json_body["stats"], json_body["failures"]
示例2: get_roles
# 需要导入模块: from appscale.tools.local_state import LocalState [as 别名]
# 或者: from appscale.tools.local_state.LocalState import get_secret_key [as 别名]
def get_roles(keyname):
"""
Obtains roles for each ip from AppControllerClient.
Args:
keyname: A string representing an identifier from AppScaleFile.
Returns:
A dict in which each key is an ip and value is a role list.
"""
load_balancer_ip = LocalState.get_host_with_role(keyname, 'load_balancer')
acc = AppControllerClient(
host=load_balancer_ip,
secret=LocalState.get_secret_key(keyname)
)
cluster_stats = acc.get_cluster_stats()
roles_data = {
node["private_ip"]: (node["roles"] if len(node["roles"]) > 0 else ["?"])
for node in cluster_stats
}
return roles_data