本文整理汇总了Python中appscale.tools.local_state.LocalState.get_all_public_ips方法的典型用法代码示例。如果您正苦于以下问题:Python LocalState.get_all_public_ips方法的具体用法?Python LocalState.get_all_public_ips怎么用?Python LocalState.get_all_public_ips使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类appscale.tools.local_state.LocalState
的用法示例。
在下文中一共展示了LocalState.get_all_public_ips方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: valid_ssh_key
# 需要导入模块: from appscale.tools.local_state import LocalState [as 别名]
# 或者: from appscale.tools.local_state.LocalState import get_all_public_ips [as 别名]
def valid_ssh_key(self, config, run_instances_opts):
""" Checks if the tools can log into the head node with the current key.
Args:
config: A dictionary that includes the IPs layout (which itself is a dict
mapping role names to IPs) and, optionally, the keyname to use.
run_instances_opts: The arguments parsed from the appscale-run-instances
command.
Returns:
A bool indicating whether or not the specified keyname can be used to log
into the head node.
Raises:
BadConfigurationException: If the IPs layout was not a dictionary.
"""
keyname = config['keyname']
verbose = config.get('verbose', False)
if not isinstance(config['ips_layout'], dict) and \
not isinstance(config['ips_layout'], list):
raise BadConfigurationException(
'ips_layout should be a dictionary or list. Please fix it and try '
'again.')
ssh_key_location = self.APPSCALE_DIRECTORY + keyname + ".key"
if not os.path.exists(ssh_key_location):
return False
try:
all_ips = LocalState.get_all_public_ips(keyname)
except BadConfigurationException:
# If this is an upgrade from 3.1.0, there may not be a locations JSON.
all_ips = self.get_ips_from_options(run_instances_opts.ips)
# If a login node is defined, use that to communicate with other nodes.
node_layout = NodeLayout(run_instances_opts)
head_node = node_layout.head_node()
if head_node is not None:
remote_key = '{}/ssh.key'.format(RemoteHelper.CONFIG_DIR)
try:
RemoteHelper.scp(
head_node.public_ip, keyname, ssh_key_location, remote_key, verbose)
except ShellException:
return False
for ip in all_ips:
ssh_to_ip = 'ssh -i {key} -o StrictHostkeyChecking=no [email protected]{ip} true'\
.format(key=remote_key, ip=ip)
try:
RemoteHelper.ssh(
head_node.public_ip, keyname, ssh_to_ip, verbose, user='root')
except ShellException:
return False
return True
for ip in all_ips:
if not self.can_ssh_to_ip(ip, keyname, verbose):
return False
return True