我用的是
googleapiclient
paramiko
通过ssh连接到它。
我用
googleapiclient.discovery
GCE
应用程序编程接口
compute = googleapiclient.discovery.build('compute', 'v1')
我使用
start
req = compute.instances().start(project, zone, instance)
resp = request.execute()
while resp['status'] != 'DONE':
time.sleep(1)
resp = req.execute()
然后我执行一个
get
req = compute.instances().get(project, zone, instance)
info = req.execute()
ip_address = info['networkInterfaces'][0]['accessConfigs'][0]['natIP']
最后,我用
帕拉米科
连接到此ip地址。
ssh_client = paramiko.SSHClient()
ssh_client.connect(ip_address)
不确定地说
connect
.../lib/python3.6/site-packages/paramiko/client.py", line 362, in connect
raise NoValidConnectionsError(errors)
paramiko.ssh_exception.NoValidConnections Error:
[Errno None] Unable to connect to port 22 on xxx.xxx.xxx.xxx
time.sleep(5)
在
ssh_client.connect
我想这会给你足够的时间
sshd
开始接受联系,但我不确定。
NoValidConnections
例外情况)
-
开始
当虚拟机正在运行并且
我可以连接到吗?
-
有没有办法使用GCE api请求这些信息?
或者我看到
有一个
timeout
中的选项
打电话-我应该把我的5秒睡眠改为5秒超时吗?