Skip to content

Commit 4d49abb

Browse files
amiorinclaude
andcommitted
Add configuration-only existing compute provider
provider-compute: existing binds a pre-existing machine by existing-ip and its ed25519 existing-host-key fingerprint. Scope is the address. There is no lifecycle adapter: applications pass their own provider to runtime.session(provider_factory=...), and provider_class refuses it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014MEXKsS6SpeWs87maSCj3g
1 parent 9e1e31f commit 4d49abb

5 files changed

Lines changed: 97 additions & 5 deletions

File tree

‎README.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ grant access beyond the dedicated NSG; an NSG does not subtract those permission
7676

7777
## Compute provider selection
7878

79-
Set `provider-compute` to `oci` (the existing default), `digitalocean`, `gcp`, `hcloud` or `aws`.
79+
Set `provider-compute` to `oci` (the existing default), `digitalocean`, `gcp`, `hcloud`, `aws` or `existing`.
80+
`existing` describes a machine that already runs outside any provider API, such as a
81+
dedicated server: `existing-ip` (IPv4) and `existing-host-key` (its ed25519
82+
`SHA256:` fingerprint) bind the deployment scope to that address. PocketDeploy has no
83+
lifecycle adapter for it; an application passes its own provider object to
84+
`runtime.session(provider_factory=...)`, and the `pocketdeploy` CLI refuses it.
8085
Use [the provider configuration reference](skills/pocketdeploy/references/providers.md)
8186
and the corresponding `examples/colors-digitalocean.yml`, `examples/colors-gcp.yml`,
8287
`examples/colors-hcloud.yml` or `examples/colors-aws.yml`. Hetzner requires the official `hcloud` CLI

‎skills/pocketdeploy/references/providers.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Compute providers
22

3-
Select `provider-compute: oci`, `digitalocean`, `gcp`, `hcloud` or `aws`. Each deployment has one
3+
Select `provider-compute: oci`, `digitalocean`, `gcp`, `hcloud`, `aws` or `existing` (configuration only; see the README). Each deployment has one
44
provider and one server. Local state and Vault checkpoints bind provider scope;
55
changing providers requires a new deployment, separate application-data restore
66
and DNS cutover. Existing OCI scope and configuration defaults are preserved.

‎src/pocketdeploy/compute.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ def provider_class(name):
3737
if name == 'gcp':
3838
from .gcp import GCP
3939
return GCP
40+
if name == 'existing':
41+
raise DeployError('An existing machine requires an application-supplied compute provider; PocketDeploy does not manage its lifecycle.')
4042
raise DeployError('Unsupported compute provider.')

‎src/pocketdeploy/config.py‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ def manages_dns(config, app):
5151
'aws-profile', 'aws-region', 'aws-subnet-id', 'aws-instance-type', 'aws-image-id',
5252
'aws-root-volume-size-gb', 'aws-root-volume-type', 'aws-nested-virtualization',
5353
'aws-threads-per-core',
54+
# A pre-existing machine; the application supplies its provider object.
55+
'existing-ip', 'existing-host-key',
5456
}
5557

5658
PROVIDER_DEFAULTS = {
@@ -65,6 +67,7 @@ def manages_dns(config, app):
6567
'gcp-nic-type': 'VIRTIO_NET', 'gcp-local-ssd-count': 0},
6668
'aws': {'aws-instance-type': 't3.small', 'aws-root-volume-size-gb': 50,
6769
'aws-root-volume-type': 'gp3', 'aws-nested-virtualization': False},
70+
'existing': {},
6871
}
6972

7073

@@ -119,10 +122,10 @@ def normalize(raw, *, path, env=None, resolve=True, aliases=None, defaults=None,
119122
overlaid = read_pars({**DEFAULTS, **raw}, environment)
120123
provider = overlaid.get('provider-compute')
121124
if not isinstance(provider, str) or provider not in PROVIDER_DEFAULTS:
122-
raise DeployError('Supported compute providers are oci, digitalocean, gcp, hcloud and aws.')
125+
raise DeployError('Supported compute providers are oci, digitalocean, gcp, hcloud, aws and existing.')
123126
# Apply defaults only to the selected provider, including environment overrides.
124127
defaults = PROVIDER_DEFAULTS[provider]
125-
prefixes = ('oci-', 'digitalocean-', 'gcp-', 'hcloud-', 'aws-')
128+
prefixes = ('oci-', 'digitalocean-', 'gcp-', 'hcloud-', 'aws-', 'existing-')
126129
foreign = tuple(prefix for prefix in prefixes if prefix != provider + '-')
127130
if any(key.startswith(foreign) for key in raw):
128131
raise DeployError('Compute configuration contains fields for a different provider.')
@@ -155,6 +158,8 @@ def normalize(raw, *, path, env=None, resolve=True, aliases=None, defaults=None,
155158

156159
def scope(c):
157160
provider = c.get('provider-compute', 'oci')
161+
if provider == 'existing':
162+
return {'provider': provider, 'address': c['existing-ip']}
158163
if provider == 'hcloud':
159164
return {'provider': provider, 'location': c['hcloud-location'], 'network': 'none'}
160165
if provider == 'aws':
@@ -195,18 +200,29 @@ def validate_aws(c):
195200
raise DeployError('aws-threads-per-core must be 1 or 2.')
196201

197202

203+
def validate_existing(c):
204+
try:
205+
if ipaddress.IPv4Address(c['existing-ip']).compressed != c['existing-ip']:
206+
raise ValueError()
207+
except (ValueError, TypeError):
208+
raise DeployError('existing-ip must be an IPv4 address.') from None
209+
if not re.fullmatch(r'SHA256:[A-Za-z0-9+/]{43}', c['existing-host-key']):
210+
raise DeployError('existing-host-key must be an ed25519 SHA256: fingerprint.')
211+
212+
198213
def validate(c):
199214
from .kms import validate as validate_kms
200215
validate_kms(c)
201216
if c['schema-version'] != 1:
202217
raise DeployError('Only configuration schema 1 is supported.')
203218
provider = c['provider-compute']
204219
if provider not in PROVIDER_DEFAULTS:
205-
raise DeployError('Supported compute providers are oci, digitalocean, gcp, hcloud and aws.')
220+
raise DeployError('Supported compute providers are oci, digitalocean, gcp, hcloud, aws and existing.')
206221
if not re.fullmatch(r'[a-z][a-z0-9-]{0,39}', str(c.get('profile', ''))):
207222
raise DeployError('Profile must be a lowercase identifier of at most 40 characters.')
208223
required = {
209224
'hcloud': ['hcloud-server-type', 'hcloud-location', 'hcloud-image'],
225+
'existing': ['existing-ip', 'existing-host-key'],
210226
'aws': ['aws-profile', 'aws-region', 'aws-subnet-id', 'aws-instance-type', 'aws-root-volume-type'],
211227
'oci': ['oci-config-file-profile', 'oci-compartment-id', 'oci-subnet-id', 'oci-availability-domain'],
212228
'digitalocean': ['digitalocean-account-id', 'digitalocean-region',
@@ -221,6 +237,8 @@ def validate(c):
221237
raise DeployError('Invalid compute provider identifier.')
222238
if provider == 'aws':
223239
validate_aws(c)
240+
if provider == 'existing':
241+
validate_existing(c)
224242
if provider == 'hcloud' and c.get('compute-network-mode') != 'none':
225243
raise DeployError('Hetzner supports compute-network-mode none only.')
226244
if 'digitalocean-vpc-id' in c and (not isinstance(c['digitalocean-vpc-id'], str) or not re.fullmatch(r'[A-Za-z0-9-]+', c['digitalocean-vpc-id'])):

‎tests/test_existing.py‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
"""Offline contracts for the configuration-only existing-machine provider."""
2+
import json
3+
4+
import pytest
5+
6+
from pocketdeploy.common import DeployError
7+
from pocketdeploy.compute import provider_class
8+
from pocketdeploy.config import load, scope
9+
10+
KEY = 'SHA256:' + 'A' * 42 + 'c'
11+
12+
13+
def write(tmp_path, **raw):
14+
path = tmp_path / 'colors.yml'
15+
path.write_text(json.dumps({'profile': 'synthetic', **raw}))
16+
return path
17+
18+
19+
def existing(tmp_path, **extra):
20+
return write(tmp_path, **{'provider-compute': 'existing', 'existing-ip': '192.0.2.10',
21+
'existing-host-key': KEY, **extra})
22+
23+
24+
def test_existing_config_is_accepted_and_scoped_by_address(tmp_path):
25+
config = load(existing(tmp_path), env={})
26+
assert config['provider-compute'] == 'existing'
27+
assert config['existing-ip'] == '192.0.2.10'
28+
assert config['existing-host-key'] == KEY
29+
assert scope(config) == {'provider': 'existing', 'address': '192.0.2.10'}
30+
31+
32+
@pytest.mark.parametrize('ip', ['', 'example.com', '192.0.2', '2001:db8::1', '192.0.2.010', 10])
33+
def test_existing_ip_must_be_canonical_ipv4(tmp_path, ip):
34+
with pytest.raises(DeployError):
35+
load(existing(tmp_path, **{'existing-ip': ip}), env={})
36+
37+
38+
@pytest.mark.parametrize('key', ['', 'A' * 43, 'SHA256:' + 'A' * 42, 'SHA256:' + 'A' * 43 + '=',
39+
'MD5:' + 'A' * 43, 'SHA256:' + 'A' * 42 + '-'])
40+
def test_existing_host_key_must_be_sha256_fingerprint(tmp_path, key):
41+
with pytest.raises(DeployError):
42+
load(existing(tmp_path, **{'existing-host-key': key}), env={})
43+
44+
45+
def test_existing_requires_both_fields(tmp_path):
46+
with pytest.raises(DeployError):
47+
load(write(tmp_path, **{'provider-compute': 'existing', 'existing-ip': '192.0.2.10'}), env={})
48+
49+
50+
def test_existing_fields_are_foreign_to_other_providers(tmp_path):
51+
path = write(tmp_path, **{'provider-compute': 'hcloud', 'hcloud-location': 'nbg1',
52+
'existing-ip': '192.0.2.10'})
53+
with pytest.raises(DeployError, match='different provider'):
54+
load(path, env={})
55+
with pytest.raises(DeployError, match='different provider'):
56+
load(existing(tmp_path, **{'hcloud-location': 'nbg1'}), env={})
57+
58+
59+
def test_existing_rejects_ingress(tmp_path):
60+
rule = {'protocol': 'tcp', 'ports': ['443'], 'sources': ['0.0.0.0/0']}
61+
with pytest.raises(DeployError):
62+
load(existing(tmp_path, **{'compute-ingress': [rule]}), env={})
63+
64+
65+
def test_existing_has_no_builtin_provider():
66+
with pytest.raises(DeployError, match='application-supplied'):
67+
provider_class('existing')

0 commit comments

Comments
 (0)