-
Notifications
You must be signed in to change notification settings - Fork 16
Using cloud config to configure you KVM server
When using the KVM platform you can provide a custom cloud-config file to configure and provision your server automatically.
#cloud-config
bootcmd:
- echo 'Hello World!'
This cloud-config file can be passed to the API using the cloudconfig
argument:
> POST /server/create HTTP/1.1
> Host: api.glesys.com
> Authorization: Basic ...
> Accept: application/json
> Content-Type: application/json
| {
| "cloudconfig": "#cloud-config\nbootcmd:\n - echo 'Hello World!'",
| // ...
| }
This will create a server and run the command echo 'Hello World!'
on first boot.
NOTE: No users will be created for the server in the example above. You can provide users in your cloud-config or use the templating feature below.
In addition to simple cloud-config files you can use Mustache templates if you prefix your cloud-config with ## template: glesys
.
## template: glesys
#cloud-config
{{> users }}
bootcmd:
- echo 'Hello {{params.name}}!'
The cloud-config above tells the GleSYS API to run it through a Mustache template compiler which gives you access to a partial named {{> users }}
(see more below) and any parameters passed to cloudconfigparams
:
> POST /server/create HTTP/1.1
> Host: api.glesys.com
> Authorization: Basic ...
> Accept: application/json
> Content-Type: application/json
| {
| "cloudconfig": "## template: glesys\n#cloud-config\n{{> users }}\nbootcmd:\n - echo 'Hello {{params.name}}!'",
| "cloudconfigparams": {
| "name": "Martin"
| },
| "users": [
| { "username": "mbagge", "sshkeys": ["ssh-ed25519 ..."] }
| ]
| // ...
| }
This will create a server run the command echo 'Hello Martin!'
on first boot as well as create a user named mbagge
.
You can preview the compiled cloud-config file using the server/previewcloudconfig
endpoint.
A note on users
If you don't pass a custom cloud-config we will provide one for you. This cloud-config includes the {{> users }}
partial as it acts as a shortcut to create any users provided in the users
argument. You can choose to provide a password or/and any number of SSH keys for any given user.
If you don't want to use the {{> users }}
partial you can still access the provided users via the {{ users }}
variable in your template.
- cloud-init ๐ https://cloudinit.readthedocs.io/en/latest/
- cloud-config ๐ https://cloudinit.readthedocs.io/en/latest/topics/format.html#cloud-config-data
- cloud-config modules ๐ https://cloudinit.readthedocs.io/en/latest/topics/modules.html
- Mustache templating ๐ https://mustache.github.io
-
server/create
endpoint ๐ https://github.com/glesys/api-docs/wiki/API-Documentation#servercreate -
server/previewcloudconfig
endpoint ๐ https://github.com/glesys/api-docs/wiki/API-Documentation#serverpreviewcloudconfig