【问题标题】:Hetzner hcloud Python create Server with SSH-KeysHetzner hcloud Python 使用 SSH 密钥创建服务器
【发布时间】:2019-09-16 18:25:19
【问题描述】:

我想用 Hetzner hcloud Python 库创建一个服务器。 https://github.com/hetznercloud/hcloud-python

如何注入 SSH-Key?我已经创建了一个名为“SSH-Key”的 SSH-Key。

from hcloud import Client
from hcloud.images.domain import Image
from hcloud.server_types.domain import ServerType

client = Client(token="I7................I")  # Please paste your API token here between the quotes
response = client.servers.create(name="my-server", server_type=ServerType("cx11"), image=Image(name="ubuntu-18.04"), ssh_keys=ssh_keys(name=(["SSH-Key"])))
server = response.server
print(server)

我找不到如何使用 SSH 密钥进行这项工作的示例。

【问题讨论】:

    标签: python api ssh-keys hcloud


    【解决方案1】:

    您需要传递一个 ssh 密钥列表,即。 client.ssh_keys.get_list()

    2021-01-30 的完整工作示例:

        from hcloud import Client
        from hcloud.images.domain import Image
        from hcloud.locations.domain import Location
        from hcloud.server_types.domain import ServerType
        
        
        client = Client("your_api_key_here")
        ssh = client.ssh_keys.get_by_name("ssh_key_name_set_on_hetzner")
        
        response = client.servers.create(
            name="example-server-name",
            location=Location(name="nbg1"),
            server_type=ServerType("cx11"),
            image=Image(name="debian-10"),
            ssh_keys=[ssh],
        )
    

    【讨论】:

      猜你喜欢
      • 2021-10-04
      • 2021-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-15
      • 1970-01-01
      • 2016-12-28
      • 1970-01-01
      相关资源
      最近更新 更多