Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions vm-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Idempotent VM spawning config

## Idempotency:
The user defines a desired state in the form of a config in yaml, and cf-remote makes it a reality.
If run against an existing environment, it detects changes and 'repairs' the current state using the configuration.

## Example

```yml
templates:
ubuntu-vm:
provider:
name: aws
aws:
image: ubuntu-24

centos7:
provider:
name: vagrant
vagrant:
box: generic/centos7

groups:
- myhub:
role: hub
count: 1
spawn-config: ubuntu-vm
cfengine: 3.24.3
scripts: [ ./script.sh ]

- myclient:
role: client
count: 3
bootstrap: myhub
spawn-config: centos7
cfengine: 3.24.3

- other:
role: client
hosts: [ ubuntu@1.1.1.1 ]
bootstrap: myhub
cfengine: 3.24.3
```

### Spawning

```bash
cf-remote up config.yaml
```

Example output. myclient is already spawned from a previous run.
```
Checking current state...
Checking 'myhub'... Changes detected. Enabling repair
Spawning: 'ubuntu-24' on 'aws' provider... OK
Installing: 'cfengine-nova-hub_3.27.0-1.ubuntu24_amd64.deb' on 'ubuntu@34.244.25.232'... OK
Running: './script.sh' on 'ubuntu@34.244.25.232'... OK
Checking 'myclient'... No Changes detected. OK
Checking 'other'... Changes detected. Enabling repair
Hosts: adding 'ubuntu@1.1.1.1' to 'other'... OK
Installing: 'cfengine-nova-client_3.27.0-1.ubuntu24_amd64.deb' on 'ubuntu@1.1.1.1'... OK
Bootstrapping: '1.1.1.1' -> '172.31.23.220'... OK
Details about the current state can be found in /home/user/.cfengine/cf-remote/cloud_state.json
```

### Destroying

```bash
cf-remote destroy config.yaml
```

# Algorithm

1. Resolve templates in config
2. Validate resolved config using `schema` library
3. Load old state (cloud_state.json)
4. Transform validated config (new state) into same format as old state
5. Compute diffs between old state and new state. Return a list of tuple (path, before, after)
6. Map diffs to Change object containing the type of change (ex: install), the status (ex: pending) and the dependencies (vm must be already spawned)
7. schedule the list of change objects with topological sort or other algorithm and run each change using cf-remote's commands
8. save new state to cloud_state.json

# Future features

- inlining (being able to split config in smaller subtrees)