跳转到主要内容

Hetzner Cloud的Molecule驱动程序

项目描述

Molecule Hetzner Cloud驱动程序

PyPI Package Codecov License

适用于Hetzner CloudMolecule的驱动程序。

此插件允许您在Molecule集成测试中使用按需Hetzner Cloud服务器。

安装

$ pip install molecule-hetznercloud

升级

本项目遵循语义化版本控制

$ pip install --upgrade molecule-hetznercloud

升级到v2

  • 在您的molecule.yml文件中,将驱动程序名称(driver.name)重命名为molecule_hetznercloud
 driver:
-  name: hetznercloud
+  name: molecule_hetznercloud
  • 在您的molecule.yml文件中,现在要求指定卷名称(platforms[].volumes[].name)字段。如果该字段缺失,您必须添加它
 platforms:
   - name: instance-1
     image: debian-12
     volumes:
-     - size: 20
+     - name: volume-1
+       size: 20
  • 每个资源(服务器、卷、网络)名称都以前缀哈希(32个字符)开头,该哈希基于角色和场景路径。这意味着您可以在场景之间重用相同的名称(例如,instance-1)。资源名称的长度必须不超过其最大长度,例如,服务器名称的最大长度为63个字符,加上前缀,您只剩31个字符用于名称。

  • 在您的molecule.yml文件中,平台服务器类型(platforms[].server_type)字段现在默认为cx22。如果您已经使用默认值,您可以删除该字段

 platforms:
   - name: instance-1
     image: debian-12
-    server_type: cx22

用法

为了与Hetzner Cloud API通信,您需要公开一个HCLOUD_TOKEN环境变量。有关如何获取Hetzner Cloud API令牌的更多信息,请参阅认证文档

$ export HCLOUD_TOKEN="set_the_hcloud_token_here"

然后使用驱动程序插件设置一个新的Molecule场景。

$ molecule init scenario --driver-name molecule_hetznercloud

[!WARNING] 从Molecule 6开始,molecule init scenario命令不再支持由驱动程序提供的配置。如果您正在使用Molecule >=6,请复制下面的示例并将其粘贴到您的场景molecule.yml文件中。有关详细信息,请参阅此提交

然后您的molecule/default/molecule.yml应如下所示。

---
driver:
  name: molecule_hetznercloud
platforms:
  - # Name of the Server to create (must be unique per Project and a valid hostname as per RFC 1123).
    # required
    name: instance-1
    # Name of the Image the Server is created from.
    # required
    image: debian-12
    # Name of the Server type this Server should be created with.
    # default: cx22
    server_type: cx22
    # Name of Location to create Server in (must not be used together with datacenter).
    # default: omit
    location: hel1
    # Name of Datacenter to create Server in (must not be used together with location).
    # default: omit
    datacenter: null
    # Cloud-Init user data to use during Server creation. This field is limited to 32KiB.
    # default: omit
    user_data: null

    # List of volumes to attach to the server.
    volumes:
      - # Name of the volume.
        # required
        name: volume-1
        # Size of the Volume in GB.
        # default: 10
        size: 10

    # Dictionary of private networks the server should be attached to.
    networks:
      # Name of the network
      network-1:
        # IP range of the whole network which must span all included subnets. Must be one of the private IPv4 ranges of RFC1918.
        # If multiple hosts using the same network, you may only define it once.
        # required
        ip_range: 10.0.0.0/16
        subnet:
          # IP to assign to the server.
          # required
          ip: 10.0.0.1/24
          # Type of subnetwork.
          # default: cloud
          type: cloud
          # Name of network zone.
          # default: eu-central
          network_zone: eu-central
      network-2:
        ip_range: 10.1.0.0/16
        subnet:
          ip: 10.1.0.1/24

[!NOTE] networks.ip_range对于创建非常重要。如果您有多个主机,您可能只需定义一次。

[!NOTE] 您可以使用hcloud命令行工具列出服务器类型和可用镜像

# List server types
$ hcloud server-type list --sort name
# List images for the x86 architecture
$ hcloud image list --type system --architecture x86 --sort name

然后测试您的角色。

$ molecule test

为了便于启动时的初始调试,还可以公开以下环境变量。

$ export MOLECULE_NO_LOG=False  # not so verbose, helpful
$ export MOLECULE_DEBUG=True  # very verbose, last ditch effort

您还可以通过公开以下环境变量来定义自定义资源命名空间,例如在CI工作流程中

$ export RESOURCE_NAMESPACE=e121dc64ff615ccdfac71bb5c00296b9 # Ensure the value length is <= 32

开发

测试

运行单元测试

make test

运行集成测试

export HCLOUD_TOKEN="set_the_hcloud_token_here"
make integration

历史

该项目最初由@decentral1se维护。在寻找新维护者的长期努力后,该项目于2023年初归档。

2023年9月,代码被@jooola重写,并重新激活以继续开发。

许可证

LGPLv3许可。

项目详情


下载文件

下载您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

molecule_hetznercloud-2.3.0.tar.gz (14.6 kB 查看哈希值)

上传于 源码

构建版本

molecule_hetznercloud-2.3.0-py3-none-any.whl (15.4 kB 查看哈希值)

上传于 Python 3

由以下支持