连接从Python脚本创建的实例
我想自动创建客户端实例并在其上运行客户端python脚本。我可以创建一个客户端实例:
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials.get_application_default()
service = discovery.build('compute', 'beta', credentials=credentials)
project = 'my-project'
zone = 'us-central1-a'
instance_body = {
"name": "my-instance-name",
"sourceMachineImage": "projects/my-project/global/machineImages/my-image",
}
request = service.instances().insert(project=project, zone=zone, body=instance_body)
response = request.execute()
但是,响应对象似乎不包含新实例的任何身份验证详细信息。由于我有实例的名称,因此我可以从实例列表中获取其内部IP地址,但这还不足以连接到它。那么如何在新创建的实例上运行我的客户端Python脚本呢?
I would like to automatically create client instances and run client Python script on them. I can create a client instance as follows:
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials.get_application_default()
service = discovery.build('compute', 'beta', credentials=credentials)
project = 'my-project'
zone = 'us-central1-a'
instance_body = {
"name": "my-instance-name",
"sourceMachineImage": "projects/my-project/global/machineImages/my-image",
}
request = service.instances().insert(project=project, zone=zone, body=instance_body)
response = request.execute()
However, the response object does not seem to contain any authentication details for the new instance. Since I have the name of the instance, I can obtain its internal IP address from the list of instances, but that is not enough to connect to it. So how can run my client Python script on the newly created instance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Google的Compute Engine API用于为Google Cloud Platform编程“控制平面”,即它用于在Google Cloud Platform上创建,更新和删除计算引擎资源。
创建计算引擎实例(VM)后,您需要使用操作特定的工具远程访问操作系统。例如,如果您要创建Linux实例,则可以使用EG ssh 与VM进行交互。对于Windows,我认为该工具称为 rdp 。
Google提供凭证(适用于操作系统的所有口味)供您访问VM。使用Linux VM时,一种常见的方法是使用SSH和SSH键。如果您使用
gcloud Compute ssh
连接到一个实例,则gcloud
将为您使用本地生成的SSH键(Google> Google_compute_engine
)并自动化该过程。对于Windows,有一个不同的过程。因此,您将需要:
Google's Compute Engine API is used to program the "control plane" for Google Cloud Platform, i.e. it's used to create, update and delete Compute Engine resources on Google Cloud Platform.
Once you've created a Compute Engine instance (VM), you need to use operating-specific tools to access the operating system remotely. For example, if you're creating Linux instances then you can interact with the VM using e.g. SSH. For Windows, I think the tool is called RDP.
Google provides credentials (for all flavors of operating system) for you to access the VM. A common approach when using Linux VMs, is to use SSH and SSH keys. If you use
gcloud compute ssh
to connect to an instance,gcloud
will use locally-generated SSH keys for you (google_compute_engine
) and automate the process. For Windows there's a different process.So you will need to: