vps

VPS provisioning: cloud-init generation, Hetzner hcloud CLI wrapper, SSH deployment helpers

Cloud-init generation

vps_init() builds a cloud-init YAML string for a fresh VPS. It delegates to fastcloudinit.cloud_init_config which handles UFW (deny incoming, allow 22/80/443), user creation, and SSH key setup. Pass docker=True to install Docker via get.docker.com, and cf_token to install a Cloudflare tunnel.


source

vps_init


def vps_init(
    hostname, pub_keys, username:str='deploy', docker:bool=True, cf_token:NoneType=None, packages:NoneType=None,
    cmds:NoneType=None, kw:VAR_KEYWORD
):

Cloud-init YAML for a fresh VPS: user, UFW, optional Docker + Cloudflare tunnel

yaml = vps_init('myserver', 'ssh-rsa AAAA...', docker=True)
assert '#cloud-config' in yaml
assert 'get.docker.com' in yaml
assert 'deploy' in yaml
print('vps_init OK')
print(yaml[:400])

Hetzner (hcloud CLI)

callhcloud() and Hcloud follow the same pattern as calldocker()/Docker and callmultipass()/Multipass — subprocess wrapper plus kwargs-to-flags dispatch.


source

Hcloud


def Hcloud(
    args:VAR_POSITIONAL, kwargs:VAR_KEYWORD
):

Wrap hcloud CLI: getattr dispatches subcommands, kwargs become flags


source

callhcloud


def callhcloud(
    args:VAR_POSITIONAL
):

Run hcloud CLI command, return stdout.


source

hcloud_auth


def hcloud_auth(
    token, name:str='default'
):

Configure hcloud CLI with token. Call once before using create/servers/etc.


source

delete


def delete(
    name
):

Delete a Hetzner server by name


source

server_ip


def server_ip(
    name
)->str:

Get public IPv4 of a Hetzner server


source

servers


def servers(
    
):

List Hetzner servers as [{name, ip, status}]


source

create


def create(
    name, image:str='ubuntu-24.04', server_type:str='cx22', location:NoneType=None, cloud_init:NoneType=None,
    ssh_keys:NoneType=None
):

Create a Hetzner server. cloud_init: YAML string or file path. Returns IP.

SSH helpers

Pure subprocess-based SSH/rsync utilities — no paramiko dependency. deploy() syncs a Compose stack to a remote host and brings it up.


source

deploy


def deploy(
    compose, host, user:str='deploy', key:NoneType=None, path:str='/srv/app', pull:bool=False
):

Sync Compose stack to remote host and run docker compose up -d. Returns stdout.


source

sync


def sync(
    src, dst_path, host, user:str='deploy', key:NoneType=None, port:int=22
):

Rsync local path to remote host:dst_path


source

run_ssh


def run_ssh(
    host, cmds:VAR_POSITIONAL, user:str='deploy', key:NoneType=None, port:int=22
):

Run one or more commands on a remote host via SSH. Returns stdout.