/
usr
/
share
/
doc
/
cloud-init
/
examples
/
/usr/share/doc/cloud-init/examples
mkdir
upload
Name
Size
Mode
Actions
seed/
-
0755
rm
boothook.txt
80
0644
edit
dl
rm
cloud-config-add-apt-repos.txt
1573
0644
edit
dl
rm
cloud-config-ansible-controller.txt
7363
0644
edit
dl
rm
cloud-config-ansible-managed.txt
3823
0644
edit
dl
rm
cloud-config-ansible-pull.txt
341
0644
edit
dl
rm
cloud-config-apt.txt
12994
0644
edit
dl
rm
cloud-config-archive-launch-index.txt
802
0644
edit
dl
rm
cloud-config-archive.txt
239
0644
edit
dl
rm
cloud-config-boot-cmds.txt
406
0644
edit
dl
rm
cloud-config-ca-certs.txt
1184
0644
edit
dl
rm
cloud-config-chef-oneiric.txt
3455
0644
edit
dl
rm
cloud-config-chef.txt
4203
0644
edit
dl
rm
cloud-config-datasources.txt
2322
0644
edit
dl
rm
cloud-config-disk-setup.txt
9084
0644
edit
dl
rm
cloud-config-gluster.txt
456
0644
edit
dl
rm
cloud-config-install-packages.txt
383
0644
edit
dl
rm
cloud-config-launch-index.txt
570
0644
edit
dl
rm
cloud-config-lxd.txt
1814
0644
edit
dl
rm
cloud-config-mount-points.txt
1504
0644
edit
dl
rm
cloud-config-ntp.txt
835
0644
edit
dl
rm
cloud-config-reporting.txt
335
0644
edit
dl
rm
cloud-config-run-cmds.txt
963
0644
edit
dl
rm
cloud-config-ssh-keys.txt
2289
0644
edit
dl
rm
cloud-config-update-apt.txt
229
0644
edit
dl
rm
cloud-config-update-packages.txt
93
0644
edit
dl
rm
cloud-config-user-groups.txt
6823
0644
edit
dl
rm
cloud-config-wireguard.txt
1183
0644
edit
dl
rm
cloud-config-write-files.txt
1078
0644
edit
dl
rm
cloud-config-yum-repo.txt
897
0644
edit
dl
rm
cloud-config.txt
16559
0644
edit
dl
rm
include-once.txt
353
0644
edit
dl
rm
include.txt
434
0644
edit
dl
rm
kernel-command-line.txt
1029
0644
edit
dl
rm
network-config-v1-bonded-pair.yaml
428
0644
edit
dl
rm
network-config-v1-bonded-vlan.yaml
508
0644
edit
dl
rm
network-config-v1-bridge.yaml
638
0644
edit
dl
rm
network-config-v1-multiple-vlan.yaml
1208
0644
edit
dl
rm
network-config-v1-nameserver.yaml
403
0644
edit
dl
rm
network-config-v1-physical-3-nic.yaml
443
0644
edit
dl
rm
network-config-v1-physical-dhcp.yaml
100
0644
edit
dl
rm
network-config-v1-route.yaml
321
0644
edit
dl
rm
network-config-v1-subnet-dhcp.yaml
151
0644
edit
dl
rm
network-config-v1-subnet-multiple.yaml
364
0644
edit
dl
rm
network-config-v1-subnet-routes.yaml
527
0644
edit
dl
rm
network-config-v1-subnet-static.yaml
348
0644
edit
dl
rm
network-config-v1-vlan.yaml
253
0644
edit
dl
rm
part-handler-v2.txt
1562
0644
edit
dl
rm
part-handler.txt
2081
0644
edit
dl
rm
plain-ignored.txt
68
0644
edit
dl
rm
user-script.txt
125
0644
edit
dl
rm
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()
Save
cmd:
run