|
| 1 | +# Create a custom template |
| 2 | + |
| 3 | +This example demonstrates how to create a custom template with `upctl`. |
| 4 | + |
| 5 | +To keep track of resources created during this example, we will use common prefix in all resource names. |
| 6 | + |
| 7 | +```env |
| 8 | +prefix=example-upctl-custom-template- |
| 9 | +``` |
| 10 | + |
| 11 | +First, we will create server which disk will be used as a source for the custom template. |
| 12 | + |
| 13 | +```sh |
| 14 | +# Create ssh-key into current working directory |
| 15 | +ssh-keygen -t ed25519 -q -f "./id_ed25519" -N "" |
| 16 | + |
| 17 | +upctl server create \ |
| 18 | + --hostname ${prefix}source-server \ |
| 19 | + --zone pl-waw1 \ |
| 20 | + --ssh-keys ./id_ed25519.pub \ |
| 21 | + --network type=public \ |
| 22 | + --network type=utility \ |
| 23 | + --wait |
| 24 | +``` |
| 25 | + |
| 26 | +After the server has started, you can connect to it and prepare the disk to be templatized. Then, to be able to templatize the storage disk, we will stop the server. |
| 27 | + |
| 28 | +```sh |
| 29 | +upctl server stop --type hard --wait ${prefix}source-server |
| 30 | +``` |
| 31 | + |
| 32 | +The default name for the OS storage of servers created with `upctl` is `${server-title}-OS`, in this case `${prefix}source-server-OS`. We can use either that or the UUID of the storage, when creating the template. UUID of the storage can be printed, for example, by processing `json` output with jq. |
| 33 | + |
| 34 | +```sh |
| 35 | +upctl server show ${prefix}source-server -o json \ |
| 36 | + | jq -r ".storage[0].uuid" |
| 37 | +``` |
| 38 | + |
| 39 | +Now we are ready for creating the template. |
| 40 | + |
| 41 | +```sh |
| 42 | +upctl storage templatise ${prefix}source-server-OS \ |
| 43 | + --title ${prefix}template \ |
| 44 | + --wait |
| 45 | +``` |
| 46 | + |
| 47 | +Once the template is created, we can delete the source server |
| 48 | + |
| 49 | +```sh |
| 50 | +upctl server delete ${prefix}source-server --delete-storages |
| 51 | +``` |
| 52 | + |
| 53 | +To test that the template creation succeeded, create a new server from the just created template. |
| 54 | + |
| 55 | +```sh |
| 56 | +upctl server create \ |
| 57 | + --hostname ${prefix}server \ |
| 58 | + --zone pl-waw1 \ |
| 59 | + --network type=public \ |
| 60 | + --network type=utility \ |
| 61 | + --os ${prefix}template \ |
| 62 | + --wait |
| 63 | +``` |
| 64 | + |
| 65 | +Finally, we can cleanup the created resources. |
| 66 | + |
| 67 | +```sh |
| 68 | +upctl server stop --type hard --wait ${prefix}server |
| 69 | +upctl server delete ${prefix}server --delete-storages |
| 70 | +upctl storage delete ${prefix}template |
| 71 | +``` |
0 commit comments