/usr/share/doc/cloud-init/examples
NameSizeModeActions
seed/-0755rm
boothook.txt800644editdlrm
cloud-config-add-apt-repos.txt15730644editdlrm
cloud-config-ansible-controller.txt73630644editdlrm
cloud-config-ansible-managed.txt38230644editdlrm
cloud-config-ansible-pull.txt3410644editdlrm
cloud-config-apt.txt129940644editdlrm
cloud-config-archive-launch-index.txt8020644editdlrm
cloud-config-archive.txt2390644editdlrm
cloud-config-boot-cmds.txt4060644editdlrm
cloud-config-ca-certs.txt11840644editdlrm
cloud-config-chef-oneiric.txt34550644editdlrm
cloud-config-chef.txt42030644editdlrm
cloud-config-datasources.txt23220644editdlrm
cloud-config-disk-setup.txt90840644editdlrm
cloud-config-gluster.txt4560644editdlrm
cloud-config-install-packages.txt3830644editdlrm
cloud-config-launch-index.txt5700644editdlrm
cloud-config-lxd.txt18140644editdlrm
cloud-config-mount-points.txt15040644editdlrm
cloud-config-ntp.txt8350644editdlrm
cloud-config-reporting.txt3350644editdlrm
cloud-config-run-cmds.txt9630644editdlrm
cloud-config-ssh-keys.txt22890644editdlrm
cloud-config-update-apt.txt2290644editdlrm
cloud-config-update-packages.txt930644editdlrm
cloud-config-user-groups.txt68230644editdlrm
cloud-config-wireguard.txt11830644editdlrm
cloud-config-write-files.txt10780644editdlrm
cloud-config-yum-repo.txt8970644editdlrm
cloud-config.txt165590644editdlrm
include-once.txt3530644editdlrm
include.txt4340644editdlrm
kernel-command-line.txt10290644editdlrm
network-config-v1-bonded-pair.yaml4280644editdlrm
network-config-v1-bonded-vlan.yaml5080644editdlrm
network-config-v1-bridge.yaml6380644editdlrm
network-config-v1-multiple-vlan.yaml12080644editdlrm
network-config-v1-nameserver.yaml4030644editdlrm
network-config-v1-physical-3-nic.yaml4430644editdlrm
network-config-v1-physical-dhcp.yaml1000644editdlrm
network-config-v1-route.yaml3210644editdlrm
network-config-v1-subnet-dhcp.yaml1510644editdlrm
network-config-v1-subnet-multiple.yaml3640644editdlrm
network-config-v1-subnet-routes.yaml5270644editdlrm
network-config-v1-subnet-static.yaml3480644editdlrm
network-config-v1-vlan.yaml2530644editdlrm
part-handler-v2.txt15620644editdlrm
part-handler.txt20810644editdlrm
plain-ignored.txt680644editdlrm
user-script.txt1250644editdlrm
Edit: /usr/share/doc/cloud-init/examples/part-handler.txt (2081B)
#part-handler """This is a trivial example part-handler that creates a file with the path specified in the payload. It performs no input checking or error handling. To use it, first save the file you are currently viewing into your current working directory. Then run the following: ``` $ echo '/var/tmp/my_path' > part $ cloud-init devel make-mime -a part-handler.py:part-handler -a part:x-my-path --force > user-data ``` This will create a mime file with the contents of 'part' and the part-handler. You can now pass 'user-data' to your cloud of choice. When run, cloud-init will have created an empty file at /var/tmp/my_path. """ import pathlib from typing import Any from cloudinit.cloud import Cloud def list_types(): """Return a list of mime-types that are handled by this module.""" return ["text/x-my-path"] def handle_part(data: Cloud, ctype: str, filename: str, payload: Any): """Handle a part with the given mime-type. This function will get called multiple times. The first time is to allow any initial setup needed to handle parts. It will then get called once for each part matching the mime-type returned by `list_types`. Finally, it will get called one last time to allow for any final teardown. :data: A `Cloud` instance. This will be the same instance for each call to handle_part. :ctype: '__begin__', '__end__', or the mime-type (for this example 'text/x-my-path') of the part :filename: The filename for the part as defined in the MIME archive, or dynamically generated part if no filename is given :payload: The content of the part. This will be `None` when `ctype` is '__begin__' or '__end__'. """ if ctype == "__begin__": # Any custom setup needed before handling payloads return if ctype == "__end__": # Any custom teardown needed after handling payloads can happen here return # If we've made it here, we're dealing with a real payload, so handle # it appropriately pathlib.Path(payload.strip()).touch()