当前位置: 首页>>代码示例>>Python>>正文


Python LocalState.get_host_with_role方法代码示例

本文整理汇总了Python中appscale.tools.local_state.LocalState.get_host_with_role方法的典型用法代码示例。如果您正苦于以下问题:Python LocalState.get_host_with_role方法的具体用法?Python LocalState.get_host_with_role怎么用?Python LocalState.get_host_with_role使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在appscale.tools.local_state.LocalState的用法示例。


在下文中一共展示了LocalState.get_host_with_role方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ssh

# 需要导入模块: from appscale.tools.local_state import LocalState [as 别名]
# 或者: from appscale.tools.local_state.LocalState import get_host_with_role [as 别名]
  def ssh(self, node):
    """ 'ssh' provides a simple way to log into virtual machines in an AppScale
    deployment, using the SSH key provided in the user's AppScalefile.

    Args:
      node: An int that represents the node to SSH to. The value is used as an
        index into the list of nodes running in the AppScale deployment,
        starting with zero.
    Raises:
      AppScalefileException: If there is no AppScalefile in the current
        directory.
      TypeError: If the user does not provide an integer for 'node'.
    """
    contents = self.read_appscalefile()
    contents_as_yaml = yaml.safe_load(contents)

    if 'keyname' in contents_as_yaml:
      keyname = contents_as_yaml['keyname']
    else:
      keyname = "appscale"

    if node is None:
      node = "shadow"

    try:
      index = int(node)
      nodes = self.get_nodes(keyname)
      # make sure there is a node at position 'index'
      ip = nodes[index]['public_ip']
    except IndexError:
      raise AppScaleException("Cannot ssh to node at index " +
                              ", as there are only " + str(len(nodes)) +
                              " in the currently running AppScale deployment.")
    except ValueError:
      try:
        ip = LocalState.get_host_with_role(keyname, node.lower())
      except AppScaleException:
        raise AppScaleException("No role exists by that name. "
                                "Valid roles are {}"
                                .format(NodeLayout.ADVANCED_FORMAT_KEYS))

    # construct the ssh command to exec with that IP address
    command = ["ssh", "-o", "StrictHostkeyChecking=no", "-i",
      self.get_key_location(keyname), "[email protected]" + ip]

    # exec the ssh command
    try:
      subprocess.check_call(command)
    except subprocess.CalledProcessError:
      raise AppScaleException("Unable to ssh to the machine at "
                              "{}. Please make sure this machine is reachable, "
                              "has a public ip, or that the role is in use by "
                              "the deployment.".format(ip))
开发者ID:tmarballi,项目名称:appscale-tools,代码行数:55,代码来源:appscale.py

示例2: _get_stats

# 需要导入模块: from appscale.tools.local_state import LocalState [as 别名]
# 或者: from appscale.tools.local_state.LocalState import get_host_with_role [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"]
开发者ID:AppScale,项目名称:appscale-tools,代码行数:46,代码来源:appscale_stats.py

示例3: get_roles

# 需要导入模块: from appscale.tools.local_state import LocalState [as 别名]
# 或者: from appscale.tools.local_state.LocalState import get_host_with_role [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
开发者ID:AppScale,项目名称:appscale-tools,代码行数:25,代码来源:appscale_stats.py


注:本文中的appscale.tools.local_state.LocalState.get_host_with_role方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。