简体   繁体   English

发出编写python脚本以打开另一台AWS EC2计算机的问题

[英]Issue writing python script to turn on another AWS EC2 machine

I am trying to set up a process on my jenkins EC2 that turns on another EC2 machine at a given time. 我试图在我的jenkins EC2上设置一个进程,该进程在给定时间打开另一台EC2机器。

I started by writing a simple python script as follows to turn on the other EC2 machine: 我首先编写了一个简单的python脚本,如下所示以打开另一台EC2机器:

import boto.ec2
conn = boto.ec2.connect_to_region("us-east-1")
conn.run_instances(
    'ami-...',
    key_name='my_key_name',
    instance_type='my_instance_type',
    security_groups=['my_security_group']
)

But this errors with: 但这与以下错误:

[SSH] Exception:java.net.NoRouteToHostException: No route to host
com.jcraft.jsch.JSchException: java.net.NoRouteToHostException: No route to host
        at com.jcraft.jsch.Util.createSocket(Util.java:341)
        at com.jcraft.jsch.Session.connect(Session.java:182)
        at com.jcraft.jsch.Session.connect(Session.java:150)
        at org.jvnet.hudson.plugins.SSHSite.createSession(SSHSite.java:141)
        at org.jvnet.hudson.plugins.SSHSite.executeCommand(SSHSite.java:151)
        at org.jvnet.hudson.plugins.SSHBuildWrapper.executePreBuildScript(SSHBuildWrapper.java:75)
        at org.jvnet.hudson.plugins.SSHBuildWrapper.setUp(SSHBuildWrapper.java:59)
        at hudson.model.Build$BuildExecution.doRun(Build.java:156)
        at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:537)
        at hudson.model.Run.execute(Run.java:1741)
        at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
        at hudson.model.ResourceController.execute(ResourceController.java:98)
        at hudson.model.Executor.run(Executor.java:408)
Caused by: java.net.NoRouteToHostException: No route to host
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:579)
        at java.net.Socket.connect(Socket.java:528)
        at java.net.Socket.<init>(Socket.java:425)
        at java.net.Socket.<init>(Socket.java:208)
        at com.jcraft.jsch.Util.createSocket(Util.java:335)
        ... 12 more

If I'm reading the error correctly it is saying that it can't connect to the other EC2 machine, most likely because it is switched off :) 如果我正确读取该错误,则表示它无法连接到另一台EC2计算机,这很可能是因为它已关闭:)

This is where I'm getting stuck and I'm hoping that someone can help to narrow down the issue - am I using a wrong approach to turn on another EC2 machine? 这是我遇到的困难,希望有人可以帮助缩小问题的范围-我是否使用错误的方法打开了另一台EC2计算机? / any suggestions to help narrow down the issue would be appreciated? /有什么建议可以帮助缩小问题的范围?

I have checked the security groups of both EC2 machines, and have checked that when the other EC2 machine is on I am able to ping it from the jenkins machine. 我已经检查了两台EC2机器的安全组,并检查了当另一台EC2机器开启时我是否可以从jenkins机器ping它。

Are you trying to connect to the new instance immediately after launching it? 您是否要在启动后立即连接到新实例? It will take a few minutes for the new instance to boot and be ready for network connections. 新实例将启动并准备好进行网络连接需要几分钟。 You could have the Python code that launches the instance loop and poll for the state of the instance to become running . 您可能拥有启动实例循环并轮询实例状态以开始running的Python代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM